camoufox-js 0.11.3 → 0.11.5
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.
- package/dist/sync_api.js +8 -1
- package/dist/utils.d.ts +19 -0
- package/dist/utils.js +60 -7
- package/package.json +3 -3
package/dist/sync_api.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { firefox, } from "playwright-core";
|
|
2
|
-
import { launchOptions, syncAttachVD } from "./utils.js";
|
|
2
|
+
import { attachNoViewportDefault, launchOptions, spoofsWindowDimensions, syncAttachVD, } from "./utils.js";
|
|
3
3
|
import { VirtualDisplay } from "./virtdisplay.js";
|
|
4
4
|
export async function Camoufox(launch_options = {}) {
|
|
5
5
|
const { headless, user_data_dir, ...launchOptions } = launch_options;
|
|
@@ -20,10 +20,17 @@ export async function NewBrowser(playwright, headless = false, fromOptions = {},
|
|
|
20
20
|
headless: normalizedHeadless,
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
|
+
const noViewportDefault = spoofsWindowDimensions(fromOptions);
|
|
23
24
|
if (typeof userDataDir === "string") {
|
|
25
|
+
if (noViewportDefault && !("viewport" in fromOptions)) {
|
|
26
|
+
fromOptions = { ...fromOptions, viewport: null };
|
|
27
|
+
}
|
|
24
28
|
const context = await playwright.launchPersistentContext(userDataDir, fromOptions);
|
|
25
29
|
return syncAttachVD(context, virtualDisplay);
|
|
26
30
|
}
|
|
27
31
|
const browser = await playwright.launch(fromOptions);
|
|
32
|
+
if (noViewportDefault) {
|
|
33
|
+
attachNoViewportDefault(browser);
|
|
34
|
+
}
|
|
28
35
|
return syncAttachVD(browser, virtualDisplay);
|
|
29
36
|
}
|
package/dist/utils.d.ts
CHANGED
|
@@ -6,6 +6,25 @@ import { SUPPORTED_OS } from "./fingerprints.js";
|
|
|
6
6
|
import type { VirtualDisplay } from "./virtdisplay.js";
|
|
7
7
|
type Screen = FingerprintGeneratorOptions["screen"];
|
|
8
8
|
export declare function getAsBooleanFromENV(name: string, defaultValue?: boolean | undefined): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Whether the CAMOU_CONFIG in a set of launch options spoofs any window
|
|
11
|
+
* dimension. The config is chunked across CAMOU_CONFIG_<n> env vars, so
|
|
12
|
+
* reassemble it in index order before looking.
|
|
13
|
+
*/
|
|
14
|
+
export declare function spoofsWindowDimensions(fromOptions: Record<string, any>): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Defaults newPage()/newContext() to `viewport: null`.
|
|
17
|
+
*
|
|
18
|
+
* Playwright applies a 1280x720 viewport by default, which makes Juggler ask
|
|
19
|
+
* the content window to become 1280x720. When Camoufox is pinning the window to
|
|
20
|
+
* a spoofed size, that request can never be satisfied, so the page reports the
|
|
21
|
+
* Playwright viewport instead of the spoofed dimensions (and a second
|
|
22
|
+
* newPage() can hang - daijro/camoufox#666).
|
|
23
|
+
*
|
|
24
|
+
* Without a viewport, Juggler measures the window instead of resizing it.
|
|
25
|
+
* An explicit viewport from the caller always wins.
|
|
26
|
+
*/
|
|
27
|
+
export declare function attachNoViewportDefault<T>(target: T): T;
|
|
9
28
|
export declare function syncAttachVD(browser: any, virtualDisplay?: VirtualDisplay | null): any;
|
|
10
29
|
export interface LaunchOptions {
|
|
11
30
|
/** Operating system to use for the fingerprint generation.
|
package/dist/utils.js
CHANGED
|
@@ -74,8 +74,7 @@ function loadProperties(filePath) {
|
|
|
74
74
|
return acc;
|
|
75
75
|
}, {});
|
|
76
76
|
}
|
|
77
|
-
function validateConfig(configMap,
|
|
78
|
-
const propertyTypes = loadProperties(path);
|
|
77
|
+
function validateConfig(configMap, propertyTypes) {
|
|
79
78
|
for (const [key, value] of Object.entries(configMap)) {
|
|
80
79
|
const expectedType = propertyTypes[key];
|
|
81
80
|
if (!expectedType) {
|
|
@@ -214,6 +213,55 @@ function warnManualConfig(config) {
|
|
|
214
213
|
LeakWarning.warn("viewport", false);
|
|
215
214
|
}
|
|
216
215
|
}
|
|
216
|
+
const WINDOW_DIM_KEYS = [
|
|
217
|
+
"window.outerWidth",
|
|
218
|
+
"window.outerHeight",
|
|
219
|
+
"window.innerWidth",
|
|
220
|
+
"window.innerHeight",
|
|
221
|
+
"document.body.clientWidth",
|
|
222
|
+
"document.body.clientHeight",
|
|
223
|
+
];
|
|
224
|
+
/**
|
|
225
|
+
* Whether the CAMOU_CONFIG in a set of launch options spoofs any window
|
|
226
|
+
* dimension. The config is chunked across CAMOU_CONFIG_<n> env vars, so
|
|
227
|
+
* reassemble it in index order before looking.
|
|
228
|
+
*/
|
|
229
|
+
export function spoofsWindowDimensions(fromOptions) {
|
|
230
|
+
const env = fromOptions.env ?? {};
|
|
231
|
+
const chunks = Object.entries(env)
|
|
232
|
+
.filter(([key]) => key.startsWith("CAMOU_CONFIG_"))
|
|
233
|
+
.map(([key, value]) => [Number(key.split("_").pop()), value])
|
|
234
|
+
.sort(([a], [b]) => a - b);
|
|
235
|
+
if (chunks.length === 0) {
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
238
|
+
const blob = chunks.map(([, value]) => value).join("");
|
|
239
|
+
return WINDOW_DIM_KEYS.some((key) => blob.includes(key));
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Defaults newPage()/newContext() to `viewport: null`.
|
|
243
|
+
*
|
|
244
|
+
* Playwright applies a 1280x720 viewport by default, which makes Juggler ask
|
|
245
|
+
* the content window to become 1280x720. When Camoufox is pinning the window to
|
|
246
|
+
* a spoofed size, that request can never be satisfied, so the page reports the
|
|
247
|
+
* Playwright viewport instead of the spoofed dimensions (and a second
|
|
248
|
+
* newPage() can hang - daijro/camoufox#666).
|
|
249
|
+
*
|
|
250
|
+
* Without a viewport, Juggler measures the window instead of resizing it.
|
|
251
|
+
* An explicit viewport from the caller always wins.
|
|
252
|
+
*/
|
|
253
|
+
export function attachNoViewportDefault(target) {
|
|
254
|
+
for (const name of ["newPage", "newContext"]) {
|
|
255
|
+
const original = target[name];
|
|
256
|
+
if (typeof original !== "function") {
|
|
257
|
+
continue;
|
|
258
|
+
}
|
|
259
|
+
target[name] = (options, ...rest) => original.call(target, options && "viewport" in options
|
|
260
|
+
? options
|
|
261
|
+
: { ...options, viewport: null }, ...rest);
|
|
262
|
+
}
|
|
263
|
+
return target;
|
|
264
|
+
}
|
|
217
265
|
async function _asyncAttachVD(browser, virtualDisplay) {
|
|
218
266
|
if (!virtualDisplay) {
|
|
219
267
|
return browser;
|
|
@@ -370,11 +418,16 @@ export async function launchOptions({ config, os, block_images, block_webrtc, bl
|
|
|
370
418
|
// a per-launch audio:seed the AudioFingerprintManager defaults to 0, so every
|
|
371
419
|
// spoofed context returns identical audio samples — a "same machine behind
|
|
372
420
|
// many identities" tell on CreepJS. setInto is "set only if unset", so a
|
|
373
|
-
// caller-supplied seed wins (the JS equivalent of setdefault).
|
|
421
|
+
// caller-supplied seed wins (the JS equivalent of setdefault). audio:seed and
|
|
422
|
+
// canvas:seed only exist since Camoufox 2.0, and the library supports older
|
|
423
|
+
// builds, so seed only what the installed browser's schema knows.
|
|
374
424
|
const randint = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min;
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
425
|
+
const knownProperties = loadProperties(executable_path);
|
|
426
|
+
for (const seed of ["fonts:spacing_seed", "audio:seed", "canvas:seed"]) {
|
|
427
|
+
if (seed in knownProperties) {
|
|
428
|
+
setInto(config, seed, randint(1, 4_294_967_295));
|
|
429
|
+
}
|
|
430
|
+
}
|
|
378
431
|
const targetOS = getTargetOS(config);
|
|
379
432
|
// Set a random window.history.length
|
|
380
433
|
setInto(config, "window.history.length", Math.floor(Math.random() * 5) + 1);
|
|
@@ -489,7 +542,7 @@ export async function launchOptions({ config, os, block_images, block_webrtc, bl
|
|
|
489
542
|
console.debug(config);
|
|
490
543
|
}
|
|
491
544
|
// Validate the config
|
|
492
|
-
validateConfig(config,
|
|
545
|
+
validateConfig(config, knownProperties);
|
|
493
546
|
//Prepare environment variables to pass to Camoufox
|
|
494
547
|
const env_vars = {
|
|
495
548
|
...getEnvVars(config, targetOS),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "camoufox-js",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.5",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"bin": "dist/__main__.js",
|
|
@@ -23,11 +23,11 @@
|
|
|
23
23
|
"license": "MPL-2.0",
|
|
24
24
|
"description": "Experimental JS port of Camoufox for Python.",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"adm-zip": "^0.
|
|
26
|
+
"adm-zip": "^0.6.0",
|
|
27
27
|
"better-sqlite3": "^13.0.1",
|
|
28
28
|
"cli-progress": "^3.12.0",
|
|
29
29
|
"commander": "^14.0.0",
|
|
30
|
-
"fingerprint-generator": "^2.1.
|
|
30
|
+
"fingerprint-generator": "^2.1.86",
|
|
31
31
|
"glob": "^13.0.0",
|
|
32
32
|
"impit": "^0.14.1",
|
|
33
33
|
"language-tags": "^2.0.1",
|