camoufox-js 0.3.1 → 0.3.3

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.
@@ -1,3 +1,4 @@
1
1
  import { Fingerprint, FingerprintGeneratorOptions } from 'fingerprint-generator';
2
+ export declare const SUPPORTED_OS: readonly ["linux", "macos", "windows"];
2
3
  export declare function fromBrowserforge(fingerprint: Fingerprint, ffVersion?: string): Record<string, any>;
3
- export declare function generateFingerprint(window?: [number, number], config?: FingerprintGeneratorOptions | {}): Fingerprint;
4
+ export declare function generateFingerprint(window?: [number, number], config?: Partial<FingerprintGeneratorOptions>): Fingerprint;
@@ -1,10 +1,11 @@
1
1
  import { join } from 'node:path';
2
2
  import { loadYaml } from './pkgman.js';
3
3
  import { FingerprintGenerator } from 'fingerprint-generator';
4
+ export const SUPPORTED_OS = ['linux', 'macos', 'windows'];
4
5
  const BROWSERFORGE_DATA = loadYaml(join(import.meta.dirname, 'data-files', 'browserforge.yml'));
5
6
  const FP_GENERATOR = new FingerprintGenerator({
6
7
  browsers: ['firefox'],
7
- operatingSystems: ['linux', 'macos', 'windows'],
8
+ operatingSystems: SUPPORTED_OS,
8
9
  });
9
10
  function randrange(min, max) {
10
11
  return Math.floor(Math.random() * (max - min + 1)) + min;
@@ -73,7 +74,7 @@ function handleWindowSize(fp, outerWidth, outerHeight) {
73
74
  sc.outerHeight = outerHeight;
74
75
  fp.screen = sc;
75
76
  }
76
- export function generateFingerprint(window, config = {}) {
77
+ export function generateFingerprint(window, config) {
77
78
  if (window) {
78
79
  const { fingerprint } = FP_GENERATOR.getFingerprint(config);
79
80
  handleWindowSize(fingerprint, window[0], window[1]);
package/dist/locale.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  export declare const ALLOW_GEOIP = true;
2
2
  declare class Locale {
3
3
  language: string;
4
- region?: string;
5
- script?: string;
6
- constructor(language: string, region?: string, script?: string);
4
+ region?: string | undefined;
5
+ script?: string | undefined;
6
+ constructor(language: string, region?: string | undefined, script?: string | undefined);
7
7
  asString(): string;
8
8
  asConfig(): Record<string, string>;
9
9
  }
@@ -12,8 +12,8 @@ declare class Geolocation {
12
12
  longitude: number;
13
13
  latitude: number;
14
14
  timezone: string;
15
- accuracy?: number;
16
- constructor(locale: Locale, longitude: number, latitude: number, timezone: string, accuracy?: number);
15
+ accuracy?: number | undefined;
16
+ constructor(locale: Locale, longitude: number, latitude: number, timezone: string, accuracy?: number | undefined);
17
17
  asConfig(): Record<string, any>;
18
18
  }
19
19
  export declare function normalizeLocale(locale: string): Locale;
package/dist/locale.js CHANGED
@@ -76,8 +76,7 @@ export function normalizeLocale(locale) {
76
76
  if (!parser.region) {
77
77
  throw InvalidLocale.invalidInput(locale);
78
78
  }
79
- const record = parser.language()?.data['record'];
80
- return new Locale(record['Subtag'], parser.region()?.data['record']['Subtag'], record['Suppress-Script']);
79
+ return new Locale(parser.language()?.format() ?? 'en', parser.region()?.format(), parser.language()?.script()?.format());
81
80
  }
82
81
  export function handleLocale(locale, ignoreRegion = false) {
83
82
  if (locale.length > 3) {
package/dist/pkgman.js CHANGED
@@ -162,7 +162,7 @@ export class CamoufoxFetcher extends GitHubDownloader {
162
162
  return Buffer.from(await response.arrayBuffer());
163
163
  }
164
164
  async extractZip(zipFile) {
165
- const zip = AdmZip(zipFile);
165
+ const zip = new AdmZip(zipFile);
166
166
  zip.extractAllTo(INSTALL_DIR.toString(), true);
167
167
  }
168
168
  static cleanup() {
@@ -292,7 +292,7 @@ export async function webdl(url, desc = '', bar = true, buffer = null) {
292
292
  return fileBuffer;
293
293
  }
294
294
  export async function unzip(zipFile, extractPath, desc, bar = true) {
295
- const zip = AdmZip(zipFile);
295
+ const zip = new AdmZip(zipFile);
296
296
  const zipEntries = zip.getEntries();
297
297
  if (bar) {
298
298
  console.log(desc || 'Extracting files...');
@@ -1,4 +1,4 @@
1
- import { Browser, BrowserContext, BrowserType } from 'playwright';
1
+ import { Browser, BrowserContext, BrowserType } from 'playwright-core';
2
2
  import { LaunchOptions } from './utils.js';
3
3
  export declare function Camoufox(launch_options: LaunchOptions): Promise<BrowserContext | Browser>;
4
4
  export declare function NewBrowser(playwright: BrowserType<Browser>, headless?: boolean | 'virtual', fromOptions?: Record<string, any>, persistentContext?: boolean, debug?: boolean, launch_options?: LaunchOptions): Promise<Browser | BrowserContext>;
package/dist/sync_api.js CHANGED
@@ -1,4 +1,4 @@
1
- import { firefox } from 'playwright';
1
+ import { firefox } from 'playwright-core';
2
2
  import { launchOptions, syncAttachVD } from './utils.js';
3
3
  import { VirtualDisplay } from './virtdisplay.js';
4
4
  export async function Camoufox(launch_options) {
package/dist/utils.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import { DefaultAddons } from './addons.js';
2
+ import { SUPPORTED_OS } from './fingerprints.js';
2
3
  import { VirtualDisplay } from './virtdisplay.js';
3
4
  import { PathLike } from 'fs';
4
5
  import { Fingerprint, FingerprintGeneratorOptions } from 'fingerprint-generator';
5
- import { LaunchOptions as PlaywrightLaunchOptions } from 'playwright';
6
+ import { LaunchOptions as PlaywrightLaunchOptions } from 'playwright-core';
6
7
  type Screen = FingerprintGeneratorOptions['screen'];
7
8
  export declare function getAsBooleanFromENV(name: string, defaultValue?: boolean | undefined): boolean;
8
9
  export declare function syncAttachVD(browser: any, virtualDisplay?: VirtualDisplay | null): any;
@@ -11,7 +12,7 @@ export interface LaunchOptions {
11
12
  * Can be "windows", "macos", "linux", or a list to randomly choose from.
12
13
  * Default: ["windows", "macos", "linux"]
13
14
  */
14
- os?: string | string[];
15
+ os?: typeof SUPPORTED_OS[number] | (typeof SUPPORTED_OS[number])[];
15
16
  /** Whether to block all images. */
16
17
  block_images?: boolean;
17
18
  /** Whether to block WebRTC entirely. */
package/dist/utils.js CHANGED
@@ -4,7 +4,7 @@
4
4
  import path from 'path';
5
5
  import { addDefaultAddons, confirmPaths } from './addons.js';
6
6
  import { InvalidOS, InvalidPropertyType, NonFirefoxFingerprint, UnknownProperty } from './exceptions.js';
7
- import { fromBrowserforge, generateFingerprint } from './fingerprints.js';
7
+ import { fromBrowserforge, generateFingerprint, SUPPORTED_OS } from './fingerprints.js';
8
8
  import { publicIP, validIPv4, validIPv6 } from './ip.js';
9
9
  import { geoipAllowed, getGeolocation, handleLocales } from './locale.js';
10
10
  import { OS_NAME, getPath, installedVerStr, launchPath } from './pkgman.js';
@@ -128,20 +128,20 @@ function determineUAOS(userAgent) {
128
128
  }
129
129
  function getScreenCons(headless) {
130
130
  if (headless === false) {
131
- return null;
131
+ return undefined;
132
132
  }
133
133
  // TODO - Implement getMonitors
134
134
  // try {
135
135
  // const monitors = getMonitors();
136
136
  // if (!monitors.length) {
137
- // return null;
137
+ // return undefined;
138
138
  // }
139
139
  // const monitor = monitors.reduce((prev, curr) => (prev.width * prev.height > curr.width * curr.height ? prev : curr));
140
140
  // return { maxWidth: monitor.width, maxHeight: monitor.height };
141
141
  // } catch {
142
- // return null;
142
+ // return undefined;
143
143
  // }
144
- return null;
144
+ return undefined;
145
145
  }
146
146
  function updateFonts(config, targetOS) {
147
147
  const fontsPath = join(import.meta.dirname, 'data-files', 'fonts.json');
@@ -161,17 +161,17 @@ function checkCustomFingerprint(fingerprint) {
161
161
  }
162
162
  LeakWarning.warn('custom_fingerprint', false);
163
163
  }
164
- function checkValidOS(os) {
164
+ function validateOS(os) {
165
+ if (!os)
166
+ return undefined;
165
167
  if (Array.isArray(os)) {
166
- os.forEach(checkValidOS);
167
- return;
168
- }
169
- if (!os.toLowerCase()) {
170
- throw new InvalidOS(`OS values must be lowercase: '${os}'`);
168
+ os.every(validateOS);
169
+ return [...os];
171
170
  }
172
- if (!['windows', 'macos', 'linux'].includes(os)) {
171
+ if (!SUPPORTED_OS.includes(os)) {
173
172
  throw new InvalidOS(`Camoufox does not support the OS: '${os}'`);
174
173
  }
174
+ return [os];
175
175
  }
176
176
  function cleanLocals(data) {
177
177
  delete data.playwright;
@@ -253,6 +253,8 @@ export function syncAttachVD(browser, virtualDisplay) {
253
253
  * Implementation from https://github.com/microsoft/playwright/blob/3873b72ac1441ca691f7594f0ed705bd84518f93/packages/playwright-core/src/server/browserContext.ts#L737-L747
254
254
  */
255
255
  function getProxyUrl(proxy) {
256
+ if (!proxy)
257
+ return null;
256
258
  if (typeof proxy === 'string') {
257
259
  return new URL(proxy);
258
260
  }
@@ -314,12 +316,9 @@ export async function launchOptions({ config, os, block_images, block_webrtc, bl
314
316
  if (!i_know_what_im_doing) {
315
317
  warnManualConfig(config);
316
318
  }
317
- // Assert the target OS is valid
318
- if (os) {
319
- checkValidOS(os);
320
- }
319
+ const operatingSystems = validateOS(os);
321
320
  // webgl_config requires OS to be set
322
- else if (webgl_config) {
321
+ if (!operatingSystems && webgl_config) {
323
322
  throw new Error('OS must be set when using webgl_config');
324
323
  }
325
324
  // Add the default addons
@@ -342,7 +341,7 @@ export async function launchOptions({ config, os, block_images, block_webrtc, bl
342
341
  if (!fingerprint) {
343
342
  fingerprint = generateFingerprint(window, {
344
343
  screen: screen || getScreenCons(headless || 'DISPLAY' in env),
345
- os,
344
+ operatingSystems,
346
345
  });
347
346
  }
348
347
  else {
@@ -377,7 +376,7 @@ export async function launchOptions({ config, os, block_images, block_webrtc, bl
377
376
  // Set a fixed font spacing seed
378
377
  setInto(config, 'fonts:spacing_seed', Math.floor(Math.random() * 1_073_741_824));
379
378
  // Handle proxy
380
- const proxyUrl = proxy ? getProxyUrl(proxy) : undefined;
379
+ const proxyUrl = getProxyUrl(proxy);
381
380
  // Set geolocation
382
381
  if (geoip) {
383
382
  geoipAllowed();
@@ -439,17 +438,17 @@ export async function launchOptions({ config, os, block_images, block_webrtc, bl
439
438
  // If the user has provided a specific WebGL vendor/renderer pair, use it
440
439
  let webgl_fp;
441
440
  if (webgl_config) {
442
- webgl_fp = sampleWebGL(targetOS, ...webgl_config);
441
+ webgl_fp = await sampleWebGL(targetOS, ...webgl_config);
443
442
  }
444
443
  else {
445
- webgl_fp = sampleWebGL(targetOS);
444
+ webgl_fp = await sampleWebGL(targetOS);
446
445
  }
447
- const enable_webgl2 = webgl_fp.webGl2Enabled ?? false;
446
+ const { webGl2Enabled, ...webGlConfig } = webgl_fp;
448
447
  // Merge the WebGL fingerprint into the config
449
- mergeInto(config, webgl_fp);
448
+ mergeInto(config, webGlConfig);
450
449
  // Set the WebGL preferences
451
450
  mergeInto(firefox_user_prefs, {
452
- 'webgl.enable-webgl2': enable_webgl2,
451
+ 'webgl.enable-webgl2': webGl2Enabled,
453
452
  'webgl.force-enabled': true,
454
453
  });
455
454
  }
@@ -490,7 +489,7 @@ export async function launchOptions({ config, os, block_images, block_webrtc, bl
490
489
  server: proxyUrl.origin,
491
490
  username: proxyUrl.username,
492
491
  password: proxyUrl.password,
493
- bypass: typeof proxy === 'string' ? undefined : proxy.bypass,
492
+ bypass: typeof proxy === 'string' ? undefined : proxy?.bypass,
494
493
  } : undefined,
495
494
  "headless": headless,
496
495
  ...launch_options,
@@ -1,9 +1,13 @@
1
1
  interface WebGLData {
2
2
  vendor: string;
3
3
  renderer: string;
4
- data: any;
4
+ data: string;
5
+ win: number;
6
+ mac: number;
7
+ lin: number;
8
+ webGl2Enabled: boolean;
5
9
  }
6
- export declare function sampleWebGL(os: string, vendor?: string, renderer?: string): Promise<WebGLData>;
10
+ export declare function sampleWebGL(os: 'win' | 'mac' | 'lin', vendor?: string, renderer?: string): Promise<WebGLData>;
7
11
  interface PossiblePairs {
8
12
  [key: string]: Array<{
9
13
  vendor: string;
@@ -30,7 +30,7 @@ export async function sampleWebGL(os, vendor, renderer) {
30
30
  }
31
31
  if (vendor && renderer) {
32
32
  const result = rows[0];
33
- if (result[3] <= 0) {
33
+ if (result[os] <= 0) {
34
34
  db.all(`SELECT DISTINCT vendor, renderer FROM webgl_fingerprints WHERE ${os} > 0`, [], (err, pairs) => {
35
35
  if (err) {
36
36
  reject(err);
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "camoufox-js",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {
7
7
  "build": "rimraf dist && tsc && npm run copy-files",
8
- "test": "echo \"Error: no test specified\" && exit 1",
8
+ "test": "vitest",
9
9
  "copy-files": "cp -r src/data-files dist/data-files"
10
10
  },
11
11
  "bin": "dist/__main__.js",
@@ -26,14 +26,21 @@
26
26
  "js-yaml": "^4.1.0",
27
27
  "language-tags": "^2.0.1",
28
28
  "maxmind": "^4.3.24",
29
- "playwright": "^1.50.1",
29
+ "playwright-core": "^1.52.0",
30
30
  "progress": "^2.0.3",
31
31
  "sqlite3": "^5.1.7",
32
32
  "ua-parser-js": "^2.0.2",
33
33
  "xml2js": "^0.6.2"
34
34
  },
35
35
  "devDependencies": {
36
+ "@types/adm-zip": "^0.5.7",
37
+ "@types/js-yaml": "^4.0.9",
38
+ "@types/language-tags": "^1.0.4",
36
39
  "@types/node": "^22.13.2",
37
- "rimraf": "^6.0.1"
40
+ "@types/progress": "^2.0.7",
41
+ "@types/xml2js": "^0.4.14",
42
+ "rimraf": "^6.0.1",
43
+ "typescript": "^5.8.3",
44
+ "vitest": "^3.1.1"
38
45
  }
39
46
  }