camoufox-js 0.6.2 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,16 @@
1
+ declare const _default: {
2
+ navigator: string;
3
+ locale: string;
4
+ geolocation: string;
5
+ "header-ua": string;
6
+ viewport: string;
7
+ custom_fingerprint: string;
8
+ proxy_without_geoip: string;
9
+ ff_version: string;
10
+ no_region: string;
11
+ block_webgl: string;
12
+ block_images: string;
13
+ custom_fonts_only: string;
14
+ disable_coop: string;
15
+ };
16
+ export default _default;
@@ -0,0 +1,28 @@
1
+ export default {
2
+ navigator: "Manually setting navigator properties is not recommended." +
3
+ " Device information is automatically generated within Camoufox" +
4
+ " based on the provided `os`.",
5
+ locale: "Use the `locale` parameter in Camoufox instead of setting the config manually.",
6
+ geolocation: "Please use the `geoip` parameter in Camoufox instead of setting your geolocation manually." +
7
+ " This can lead to detection if your target geolocation does not match your IP." +
8
+ " Pass `geoip=True` or a target IP (ex: geoip='123.45.67.89') to let Camoufox populate this data for you.",
9
+ "header-ua": "Do not set the header.User-Agent manually. Camoufox will generate a User-Agent for you.",
10
+ viewport: "Manually setting screen & window properties is not recommended." +
11
+ " Screen dimensions are randomly generated within Camoufox" +
12
+ " based on the provided screen constraints. See here:" +
13
+ " https://github.com/daijro/camoufox/tree/main/pythonlib#browserforge-integration.",
14
+ custom_fingerprint: "Passing your own fingerprint is not recommended." +
15
+ " BrowserForge fingerprints are automatically generated within Camoufox" +
16
+ " based on the provided `os` and `screen` constraints.",
17
+ proxy_without_geoip: "When using a proxy, it is heavily recommended that you pass `geoip=True`.",
18
+ ff_version: "Spoofing the Firefox version will likely lead to detection." +
19
+ " If rotating the Firefox version is absolutely necessary, it would be more advisable to" +
20
+ " rotate between older versions of Camoufox instead.",
21
+ no_region: "Because you did not pass in a locale region, Camoufox will generate one for you." +
22
+ " This can cause suspicion if your IP does not match your locale region.",
23
+ block_webgl: "Disabling WebGL is not recommended. Many WAFs will check if WebGL is enabled.",
24
+ block_images: "Blocking image requests has been reported to cause detection issues on major WAFs.",
25
+ custom_fonts_only: "Disabling OS-specific fonts while spoofing your OS will make your browser fingerprint inconsistent." +
26
+ " WAFs can detect this mismatch between your claimed OS and available system fonts.",
27
+ disable_coop: "Disabling Cross-Origin-Opener-Policy (COOP) handling can potentially be detected by sophisticated WAFs.",
28
+ };
package/dist/pkgman.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { PathLike } from 'fs';
2
- import { Writable } from 'stream';
3
- export declare const OS_NAME: 'mac' | 'win' | 'lin';
1
+ import type { PathLike } from "node:fs";
2
+ import type { Writable } from "node:stream";
3
+ export declare const OS_NAME: "mac" | "win" | "lin";
4
4
  export declare const INSTALL_DIR: PathLike;
5
5
  export declare const LOCAL_DATA: PathLike;
6
6
  export declare const OS_ARCH_MATRIX: {
@@ -59,7 +59,4 @@ export declare function webdl(url: string, desc?: string, bar?: boolean, buffer?
59
59
  retries: number;
60
60
  }): Promise<Buffer>;
61
61
  export declare function unzip(zipFile: Buffer, extractPath: string, desc?: string, bar?: boolean): Promise<void>;
62
- export declare function loadYaml(file: string): {
63
- [key: string]: any;
64
- };
65
62
  export {};
package/dist/pkgman.js CHANGED
@@ -1,39 +1,38 @@
1
- import { CONSTRAINTS } from './__version__.js';
2
- import * as os from 'os';
3
- import * as path from 'path';
4
- import * as fs from 'fs';
5
- import { execSync } from 'child_process';
6
- import { CamoufoxNotInstalled, FileNotFoundError, MissingRelease, UnsupportedArchitecture, UnsupportedOS, UnsupportedVersion, } from './exceptions.js';
7
- import AdmZip from 'adm-zip';
8
- import * as yaml from 'js-yaml';
9
- import ProgressBar from 'progress';
10
- import { setTimeout } from 'timers/promises';
1
+ import { execSync } from "node:child_process";
2
+ import * as fs from "node:fs";
3
+ import * as os from "node:os";
4
+ import * as path from "node:path";
5
+ import { setTimeout } from "node:timers/promises";
6
+ import AdmZip from "adm-zip";
7
+ import ProgressBar from "progress";
8
+ import { CONSTRAINTS } from "./__version__.js";
9
+ import { CamoufoxNotInstalled, FileNotFoundError, MissingRelease, UnsupportedArchitecture, UnsupportedOS, UnsupportedVersion, } from "./exceptions.js";
11
10
  const ARCH_MAP = {
12
- 'x64': 'x86_64',
13
- 'ia32': 'i686',
14
- 'arm64': 'arm64',
15
- 'arm': 'arm64',
11
+ x64: "x86_64",
12
+ ia32: "i686",
13
+ arm64: "arm64",
14
+ arm: "arm64",
16
15
  };
17
16
  const OS_MAP = {
18
- 'darwin': 'mac',
19
- 'linux': 'lin',
20
- 'win32': 'win',
17
+ darwin: "mac",
18
+ linux: "lin",
19
+ win32: "win",
21
20
  };
22
21
  if (!(process.platform in OS_MAP)) {
23
22
  throw new UnsupportedOS(`OS ${process.platform} is not supported`);
24
23
  }
25
24
  export const OS_NAME = OS_MAP[process.platform];
26
- export const INSTALL_DIR = userCacheDir('camoufox');
27
- export const LOCAL_DATA = path.join(import.meta.dirname, 'data-files');
25
+ export const INSTALL_DIR = userCacheDir("camoufox");
26
+ export const LOCAL_DATA = path.join(import.meta.dirname, "data-files");
28
27
  export const OS_ARCH_MATRIX = {
29
- 'win': ['x86_64', 'i686'],
30
- 'mac': ['x86_64', 'arm64'],
31
- 'lin': ['x86_64', 'arm64', 'i686'],
28
+ win: ["x86_64", "i686"],
29
+ mac: ["x86_64", "arm64"],
30
+ lin: ["x86_64", "arm64", "i686"],
32
31
  };
33
32
  const LAUNCH_FILE = {
34
- 'win': 'camoufox.exe',
35
- 'mac': '../MacOS/camoufox',
36
- 'lin': 'camoufox-bin',
33
+ win: "camoufox.exe",
34
+ mac: "../MacOS/camoufox",
35
+ lin: "camoufox-bin",
37
36
  };
38
37
  class Version {
39
38
  release;
@@ -45,7 +44,9 @@ class Version {
45
44
  this.sorted_rel = this.buildSortedRel();
46
45
  }
47
46
  buildSortedRel() {
48
- const parts = this.release.split('.').map(x => (isNaN(Number(x)) ? x.charCodeAt(0) - 1024 : Number(x)));
47
+ const parts = this.release
48
+ .split(".")
49
+ .map((x) => Number.isNaN(Number(x)) ? x.charCodeAt(0) - 1024 : Number(x));
49
50
  while (parts.length < 5) {
50
51
  parts.push(0);
51
52
  }
@@ -55,7 +56,7 @@ class Version {
55
56
  return `${this.version}-${this.release}`;
56
57
  }
57
58
  equals(other) {
58
- return this.sorted_rel.join('.') === other.sorted_rel.join('.');
59
+ return this.sorted_rel.join(".") === other.sorted_rel.join(".");
59
60
  }
60
61
  lessThan(other) {
61
62
  for (let i = 0; i < this.sorted_rel.length; i++) {
@@ -70,18 +71,21 @@ class Version {
70
71
  return VERSION_MIN.lessThan(this) && this.lessThan(VERSION_MAX);
71
72
  }
72
73
  static fromPath(filePath = INSTALL_DIR) {
73
- const versionPath = path.join(filePath.toString(), 'version.json');
74
+ const versionPath = path.join(filePath.toString(), "version.json");
74
75
  if (!fs.existsSync(versionPath)) {
75
76
  throw new FileNotFoundError(`Version information not found at ${versionPath}. Please run \`camoufox fetch\` to install.`);
76
77
  }
77
- const versionData = JSON.parse(fs.readFileSync(versionPath, 'utf-8'));
78
+ const versionData = JSON.parse(fs.readFileSync(versionPath, "utf-8"));
78
79
  return new Version(versionData.release, versionData.version);
79
80
  }
80
81
  static isSupportedPath(path) {
81
82
  return Version.fromPath(path).isSupported();
82
83
  }
83
84
  static buildMinMax() {
84
- return [new Version(CONSTRAINTS.MIN_VERSION), new Version(CONSTRAINTS.MAX_VERSION)];
85
+ return [
86
+ new Version(CONSTRAINTS.MIN_VERSION),
87
+ new Version(CONSTRAINTS.MAX_VERSION),
88
+ ];
85
89
  }
86
90
  }
87
91
  const [VERSION_MIN, VERSION_MAX] = Version.buildMinMax();
@@ -187,24 +191,24 @@ export class CamoufoxFetcher extends GitHubDownloader {
187
191
  return false;
188
192
  }
189
193
  setVersion() {
190
- fs.writeFileSync(path.join(INSTALL_DIR.toString(), 'version.json'), JSON.stringify({ version: this.version, release: this.release }));
194
+ fs.writeFileSync(path.join(INSTALL_DIR.toString(), "version.json"), JSON.stringify({ version: this.version, release: this.release }));
191
195
  }
192
196
  async install() {
193
197
  await this.init();
194
198
  await CamoufoxFetcher.cleanup();
195
199
  try {
196
200
  fs.mkdirSync(INSTALL_DIR, { recursive: true });
197
- const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'camoufox-'));
198
- const tempFilePath = path.join(tempDir, 'camoufox.zip');
201
+ const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "camoufox-"));
202
+ const tempFilePath = path.join(tempDir, "camoufox.zip");
199
203
  const tempFileStream = fs.createWriteStream(tempFilePath);
200
- await webdl(this.url, 'Downloading Camoufox...', true, tempFileStream);
201
- await new Promise(r => tempFileStream.close(r));
204
+ await webdl(this.url, "Downloading Camoufox...", true, tempFileStream);
205
+ await new Promise((r) => tempFileStream.close(r));
202
206
  await this.extractZip(tempFilePath);
203
207
  this.setVersion();
204
- if (OS_NAME !== 'win') {
208
+ if (OS_NAME !== "win") {
205
209
  execSync(`chmod -R 755 ${INSTALL_DIR}`);
206
210
  }
207
- console.log('Camoufox successfully installed.');
211
+ console.log("Camoufox successfully installed.");
208
212
  }
209
213
  catch (e) {
210
214
  console.error(`Error installing Camoufox: ${e}`);
@@ -238,14 +242,14 @@ export class CamoufoxFetcher extends GitHubDownloader {
238
242
  }
239
243
  }
240
244
  function userCacheDir(appName) {
241
- if (OS_NAME === 'win') {
242
- return path.join(os.homedir(), 'AppData', 'Local', appName, appName, 'Cache');
245
+ if (OS_NAME === "win") {
246
+ return path.join(os.homedir(), "AppData", "Local", appName, appName, "Cache");
243
247
  }
244
- else if (OS_NAME === 'mac') {
245
- return path.join(os.homedir(), 'Library', 'Caches', appName);
248
+ else if (OS_NAME === "mac") {
249
+ return path.join(os.homedir(), "Library", "Caches", appName);
246
250
  }
247
251
  else {
248
- return path.join(os.homedir(), '.cache', appName);
252
+ return path.join(os.homedir(), ".cache", appName);
249
253
  }
250
254
  }
251
255
  export function installedVerStr() {
@@ -258,7 +262,8 @@ export function camoufoxPath(downloadIfMissing = true) {
258
262
  throw new Error(`Camoufox executable not found at ${INSTALL_DIR}`);
259
263
  }
260
264
  }
261
- else if (fs.existsSync(INSTALL_DIR) && Version.isSupportedPath(INSTALL_DIR)) {
265
+ else if (fs.existsSync(INSTALL_DIR) &&
266
+ Version.isSupportedPath(INSTALL_DIR)) {
262
267
  return INSTALL_DIR;
263
268
  }
264
269
  else {
@@ -272,8 +277,8 @@ export function camoufoxPath(downloadIfMissing = true) {
272
277
  return INSTALL_DIR;
273
278
  }
274
279
  export function getPath(file) {
275
- if (OS_NAME === 'mac') {
276
- return path.resolve(camoufoxPath().toString(), 'Camoufox.app', 'Contents', 'Resources', file);
280
+ if (OS_NAME === "mac") {
281
+ return path.resolve(camoufoxPath().toString(), "Camoufox.app", "Contents", "Resources", file);
277
282
  }
278
283
  return path.join(camoufoxPath().toString(), file);
279
284
  }
@@ -284,7 +289,7 @@ export function launchPath() {
284
289
  }
285
290
  return launchPath;
286
291
  }
287
- export async function webdl(url, desc = '', bar = true, buffer = null, { retries } = { retries: 5 }) {
292
+ export async function webdl(url, desc = "", bar = true, buffer = null, { retries } = { retries: 5 }) {
288
293
  let attempts = 0;
289
294
  let response;
290
295
  while (attempts < retries) {
@@ -302,11 +307,13 @@ export async function webdl(url, desc = '', bar = true, buffer = null, { retries
302
307
  if (!response || !response.ok) {
303
308
  throw new Error(`Failed to download from ${url} after ${retries} attempts`);
304
309
  }
305
- const totalSize = parseInt(response.headers.get('content-length') || '0', 10);
306
- const progressBar = bar ? new ProgressBar(`${desc} [:bar] :percent :etas`, {
307
- total: totalSize,
308
- width: 40,
309
- }) : null;
310
+ const totalSize = parseInt(response.headers.get("content-length") || "0", 10);
311
+ const progressBar = bar
312
+ ? new ProgressBar(`${desc} [:bar] :percent :etas`, {
313
+ total: totalSize,
314
+ width: 40,
315
+ })
316
+ : null;
310
317
  const chunks = [];
311
318
  for await (const chunk of response.body) {
312
319
  if (buffer) {
@@ -326,7 +333,7 @@ export async function unzip(zipFile, extractPath, desc, bar = true) {
326
333
  const zip = new AdmZip(zipFile);
327
334
  const zipEntries = zip.getEntries();
328
335
  if (bar) {
329
- console.log(desc || 'Extracting files...');
336
+ console.log(desc || "Extracting files...");
330
337
  }
331
338
  for (const entry of zipEntries) {
332
339
  if (bar) {
@@ -335,14 +342,6 @@ export async function unzip(zipFile, extractPath, desc, bar = true) {
335
342
  zip.extractEntryTo(entry, extractPath, false, true);
336
343
  }
337
344
  if (bar) {
338
- console.log('Extraction complete.');
345
+ console.log("Extraction complete.");
339
346
  }
340
347
  }
341
- export function loadYaml(file) {
342
- let filePath = file;
343
- if (!path.isAbsolute(file)) {
344
- filePath = path.join(LOCAL_DATA.toString(), file);
345
- }
346
- const fileContents = fs.readFileSync(filePath, 'utf8');
347
- return yaml.load(fileContents);
348
- }
package/dist/server.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { BrowserServer } from 'playwright-core';
2
- import { LaunchOptions } from './utils.js';
1
+ import { type BrowserServer } from "playwright-core";
2
+ import { type LaunchOptions } from "./utils.js";
3
3
  export declare function launchServer({ port, ws_path, ...options }: LaunchOptions | {
4
4
  port?: number;
5
5
  ws_path?: string;
package/dist/server.js CHANGED
@@ -1,8 +1,8 @@
1
- import { firefox } from 'playwright-core';
2
- import { launchOptions } from './utils.js';
1
+ import { firefox } from "playwright-core";
2
+ import { launchOptions } from "./utils.js";
3
3
  export async function launchServer({ port, ws_path, ...options }) {
4
4
  return firefox.launchServer({
5
- ...await launchOptions(options),
5
+ ...(await launchOptions(options)),
6
6
  port,
7
7
  wsPath: ws_path,
8
8
  });
@@ -1,7 +1,7 @@
1
- import { Browser, BrowserContext, BrowserType } from 'playwright-core';
2
- import { LaunchOptions } from './utils.js';
1
+ import { type Browser, type BrowserContext, type BrowserType } from "playwright-core";
2
+ import { type LaunchOptions } from "./utils.js";
3
3
  export declare function Camoufox<UserDataDir extends string | undefined = undefined, ReturnType = UserDataDir extends string ? BrowserContext : Browser>(launch_options?: LaunchOptions | {
4
- headless?: boolean | 'virtual';
4
+ headless?: boolean | "virtual";
5
5
  user_data_dir: UserDataDir;
6
6
  }): Promise<ReturnType>;
7
- export declare function NewBrowser<UserDataDir extends string | false = false, ReturnType = UserDataDir extends string ? BrowserContext : Browser>(playwright: BrowserType<Browser>, headless?: boolean | 'virtual', fromOptions?: Record<string, any>, userDataDir?: UserDataDir, debug?: boolean, launch_options?: LaunchOptions): Promise<ReturnType>;
7
+ export declare function NewBrowser<UserDataDir extends string | false = false, ReturnType = UserDataDir extends string ? BrowserContext : Browser>(playwright: BrowserType<Browser>, headless?: boolean | "virtual", fromOptions?: Record<string, any>, userDataDir?: UserDataDir, debug?: boolean, launch_options?: LaunchOptions): Promise<ReturnType>;
package/dist/sync_api.js CHANGED
@@ -1,15 +1,15 @@
1
- import { firefox } from 'playwright-core';
2
- import { launchOptions, syncAttachVD } from './utils.js';
3
- import { VirtualDisplay } from './virtdisplay.js';
1
+ import { firefox, } from "playwright-core";
2
+ import { launchOptions, syncAttachVD } from "./utils.js";
3
+ import { VirtualDisplay } from "./virtdisplay.js";
4
4
  export async function Camoufox(launch_options = {}) {
5
5
  const { headless, user_data_dir, ...launchOptions } = launch_options;
6
6
  return NewBrowser(firefox, headless, {}, user_data_dir ?? false, false, launchOptions);
7
7
  }
8
8
  export async function NewBrowser(playwright, headless = false, fromOptions = {}, userDataDir = false, debug = false, launch_options = {}) {
9
9
  let virtualDisplay = null;
10
- if (headless === 'virtual') {
10
+ if (headless === "virtual") {
11
11
  virtualDisplay = new VirtualDisplay(debug);
12
- launch_options['virtual_display'] = virtualDisplay.get();
12
+ launch_options.virtual_display = virtualDisplay.get();
13
13
  launch_options.headless = false;
14
14
  }
15
15
  else {
@@ -18,7 +18,7 @@ export async function NewBrowser(playwright, headless = false, fromOptions = {},
18
18
  if (!fromOptions || Object.keys(fromOptions).length === 0) {
19
19
  fromOptions = await launchOptions({ debug, ...launch_options });
20
20
  }
21
- if (typeof userDataDir === 'string') {
21
+ if (typeof userDataDir === "string") {
22
22
  const context = await playwright.launchPersistentContext(userDataDir, fromOptions);
23
23
  return syncAttachVD(context, virtualDisplay);
24
24
  }
package/dist/utils.d.ts CHANGED
@@ -1,10 +1,10 @@
1
- import { DefaultAddons } from './addons.js';
2
- import { SUPPORTED_OS } from './fingerprints.js';
3
- import { VirtualDisplay } from './virtdisplay.js';
4
- import { PathLike } from 'fs';
5
- import { Fingerprint, FingerprintGeneratorOptions } from 'fingerprint-generator';
6
- import { LaunchOptions as PlaywrightLaunchOptions } from 'playwright-core';
7
- type Screen = FingerprintGeneratorOptions['screen'];
1
+ import { type PathLike } from "node:fs";
2
+ import type { Fingerprint, FingerprintGeneratorOptions } from "fingerprint-generator";
3
+ import type { LaunchOptions as PlaywrightLaunchOptions } from "playwright-core";
4
+ import { type DefaultAddons } from "./addons.js";
5
+ import { SUPPORTED_OS } from "./fingerprints.js";
6
+ import type { VirtualDisplay } from "./virtdisplay.js";
7
+ type Screen = FingerprintGeneratorOptions["screen"];
8
8
  export declare function getAsBooleanFromENV(name: string, defaultValue?: boolean | undefined): boolean;
9
9
  export declare function syncAttachVD(browser: any, virtualDisplay?: VirtualDisplay | null): any;
10
10
  export interface LaunchOptions {
@@ -12,7 +12,7 @@ export interface LaunchOptions {
12
12
  * Can be "windows", "macos", "linux", or a list to randomly choose from.
13
13
  * Default: ["windows", "macos", "linux"]
14
14
  */
15
- os?: typeof SUPPORTED_OS[number] | (typeof SUPPORTED_OS[number])[];
15
+ os?: (typeof SUPPORTED_OS)[number] | (typeof SUPPORTED_OS)[number][];
16
16
  /** Whether to block all images. */
17
17
  block_images?: boolean;
18
18
  /** Whether to block WebRTC entirely. */
@@ -68,7 +68,7 @@ export interface LaunchOptions {
68
68
  /** Proxy to use for the browser.
69
69
  * Note: If `geoip` is `true`, a request will be sent through this proxy to find the target IP.
70
70
  */
71
- proxy?: string | PlaywrightLaunchOptions['proxy'];
71
+ proxy?: string | PlaywrightLaunchOptions["proxy"];
72
72
  /** Cache previous pages, requests, etc. (uses more memory). */
73
73
  enable_cache?: boolean;
74
74
  /** Arguments to pass to the browser. */