camoucore 0.3.0 → 0.6.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.
- package/LICENSE +4 -3
- package/dist/camoufox/__main__.d.ts +10 -0
- package/dist/camoufox/__main__.js +1175 -0
- package/dist/camoufox/__version__.d.ts +31 -0
- package/dist/camoufox/__version__.js +32 -0
- package/dist/camoufox/_humanize_playwright.d.ts +54 -0
- package/dist/camoufox/_humanize_playwright.js +429 -0
- package/dist/camoufox/addons.d.ts +21 -0
- package/dist/camoufox/addons.js +56 -0
- package/dist/camoufox/async_api.d.ts +9 -0
- package/dist/camoufox/async_api.js +9 -0
- package/dist/camoufox/browser-pin.d.ts +46 -0
- package/dist/camoufox/browser-pin.js +96 -0
- package/dist/camoufox/cli.d.ts +7 -0
- package/dist/camoufox/cli.js +20 -0
- package/dist/camoufox/coherence.d.ts +141 -0
- package/dist/camoufox/coherence.js +708 -0
- package/dist/camoufox/data-files/audio-output-latency.json +15 -0
- package/dist/camoufox/data-files/browser-pin.json +7 -0
- package/dist/camoufox/data-files/display-profiles.json +6 -0
- package/dist/camoufox/data-files/essential-fonts.json +5 -0
- package/dist/camoufox/data-files/fingerprint-presets-v150.json +14544 -0
- package/dist/camoufox/data-files/fingerprint-presets.json +5192 -0
- package/dist/camoufox/data-files/font-bases.json +1888 -0
- package/dist/camoufox/data-files/font-groups.json +716 -0
- package/dist/camoufox/data-files/font-prefs.json +1046 -0
- package/dist/camoufox/data-files/fonts.json +240 -0
- package/dist/camoufox/data-files/fpgen.yml +44 -0
- package/dist/camoufox/data-files/launcher-constants.json +136 -0
- package/dist/camoufox/data-files/media-devices.json +180 -0
- package/dist/camoufox/data-files/repos.yml +40 -0
- package/dist/camoufox/data-files/voice-manifests.json +1864 -0
- package/dist/camoufox/data-files/voice-uris.json +188 -0
- package/dist/camoufox/data-files/warnings.yml +146 -0
- package/dist/camoufox/display_profile.d.ts +21 -0
- package/dist/camoufox/display_profile.js +129 -0
- package/dist/camoufox/driver_defaults.d.ts +27 -0
- package/dist/camoufox/driver_defaults.js +119 -0
- package/dist/camoufox/exceptions.d.ts +68 -0
- package/dist/camoufox/exceptions.js +122 -0
- package/dist/camoufox/fingerprints.d.ts +434 -0
- package/dist/camoufox/fingerprints.js +1936 -0
- package/dist/camoufox/gpudisplay.d.ts +158 -0
- package/dist/camoufox/gpudisplay.js +695 -0
- package/dist/camoufox/host_rendering.d.ts +38 -0
- package/dist/camoufox/host_rendering.js +180 -0
- package/dist/camoufox/humanize.d.ts +89 -0
- package/dist/camoufox/humanize.js +143 -0
- package/dist/camoufox/index.d.ts +21 -0
- package/dist/camoufox/index.js +21 -0
- package/dist/camoufox/ip.d.ts +45 -0
- package/dist/camoufox/ip.js +114 -0
- package/dist/camoufox/multiversion.d.ts +131 -0
- package/dist/camoufox/multiversion.js +490 -0
- package/dist/camoufox/node-floor.d.ts +5 -0
- package/dist/camoufox/node-floor.js +17 -0
- package/dist/camoufox/paths.d.ts +45 -0
- package/dist/camoufox/paths.js +62 -0
- package/dist/camoufox/pkgman.d.ts +361 -0
- package/dist/camoufox/pkgman.js +1066 -0
- package/dist/camoufox/product.d.ts +8 -0
- package/dist/camoufox/product.js +8 -0
- package/dist/camoufox/pycompat.d.ts +97 -0
- package/dist/camoufox/pycompat.js +458 -0
- package/dist/camoufox/server.d.ts +36 -0
- package/dist/camoufox/server.js +82 -0
- package/dist/camoufox/sync_api.d.ts +77 -0
- package/dist/camoufox/sync_api.js +207 -0
- package/dist/camoufox/utils.d.ts +638 -0
- package/dist/camoufox/utils.js +2507 -0
- package/dist/camoufox/warnings.d.ts +16 -0
- package/dist/camoufox/warnings.js +65 -0
- package/dist/camoufox/webgl.d.ts +52 -0
- package/dist/camoufox/webgl.js +264 -0
- package/dist/camouwolf/__main__.d.ts +10 -0
- package/dist/camouwolf/__main__.js +1180 -0
- package/dist/camouwolf/__version__.d.ts +31 -0
- package/dist/camouwolf/__version__.js +32 -0
- package/dist/camouwolf/_humanize_playwright.d.ts +53 -0
- package/dist/camouwolf/_humanize_playwright.js +427 -0
- package/dist/camouwolf/addons.d.ts +42 -0
- package/dist/camouwolf/addons.js +113 -0
- package/dist/camouwolf/async_api.d.ts +9 -0
- package/dist/camouwolf/async_api.js +9 -0
- package/dist/camouwolf/browser-pin.d.ts +46 -0
- package/dist/camouwolf/browser-pin.js +96 -0
- package/dist/camouwolf/cli.d.ts +7 -0
- package/dist/camouwolf/cli.js +20 -0
- package/dist/camouwolf/clienthints.d.ts +61 -0
- package/dist/camouwolf/clienthints.js +176 -0
- package/dist/camouwolf/coherence.d.ts +152 -0
- package/dist/camouwolf/coherence.js +554 -0
- package/dist/camouwolf/data-files/browser-pin.json +7 -0
- package/dist/camouwolf/data-files/camouwolf.defaults.json +118 -0
- package/dist/camouwolf/data-files/data/bundle-fonts.json +1983 -0
- package/dist/camouwolf/data-files/data/chrome-languages.json +517 -0
- package/dist/camouwolf/data-files/data/properties.json +321 -0
- package/dist/camouwolf/data-files/data/system-colors.json +35 -0
- package/dist/camouwolf/data-files/data/ubo.json +6 -0
- package/dist/camouwolf/data-files/fpgen.yml +41 -0
- package/dist/camouwolf/data-files/launcher-constants.json +26 -0
- package/dist/camouwolf/data-files/repos.yml +23 -0
- package/dist/camouwolf/data-files/warnings.yml +96 -0
- package/dist/camouwolf/driver_defaults.d.ts +25 -0
- package/dist/camouwolf/driver_defaults.js +114 -0
- package/dist/camouwolf/exceptions.d.ts +95 -0
- package/dist/camouwolf/exceptions.js +150 -0
- package/dist/camouwolf/fingerprints.d.ts +227 -0
- package/dist/camouwolf/fingerprints.js +753 -0
- package/dist/camouwolf/gpudisplay.d.ts +171 -0
- package/dist/camouwolf/gpudisplay.js +711 -0
- package/dist/camouwolf/host_rendering.d.ts +18 -0
- package/dist/camouwolf/host_rendering.js +114 -0
- package/dist/camouwolf/humanize.d.ts +84 -0
- package/dist/camouwolf/humanize.js +128 -0
- package/dist/camouwolf/index.d.ts +22 -0
- package/dist/camouwolf/index.js +21 -0
- package/dist/camouwolf/multiversion.d.ts +131 -0
- package/dist/camouwolf/multiversion.js +491 -0
- package/dist/camouwolf/node-floor.d.ts +5 -0
- package/dist/camouwolf/node-floor.js +17 -0
- package/dist/camouwolf/paths.d.ts +34 -0
- package/dist/camouwolf/paths.js +58 -0
- package/dist/camouwolf/pkgman.d.ts +331 -0
- package/dist/camouwolf/pkgman.js +972 -0
- package/dist/camouwolf/product.d.ts +3 -0
- package/dist/camouwolf/product.js +3 -0
- package/dist/camouwolf/pycompat.d.ts +92 -0
- package/dist/camouwolf/pycompat.js +461 -0
- package/dist/camouwolf/server.d.ts +36 -0
- package/dist/camouwolf/server.js +81 -0
- package/dist/camouwolf/switches.d.ts +77 -0
- package/dist/camouwolf/switches.js +222 -0
- package/dist/camouwolf/sync_api.d.ts +84 -0
- package/dist/camouwolf/sync_api.js +173 -0
- package/dist/camouwolf/utils.d.ts +644 -0
- package/dist/camouwolf/utils.js +2057 -0
- package/dist/camouwolf/warnings.d.ts +14 -0
- package/dist/camouwolf/warnings.js +59 -0
- package/dist/camouwolf/webgl.d.ts +41 -0
- package/dist/camouwolf/webgl.js +198 -0
- package/dist/data.d.ts +1 -1
- package/dist/data.js +3 -3
- package/dist/download.js +1 -1
- package/dist/exceptions.d.ts +1 -1
- package/dist/exceptions.js +1 -1
- package/dist/geolocation.js +1 -1
- package/dist/host.js +1 -1
- package/dist/ip.js +1 -1
- package/dist/locales.js +1 -1
- package/dist/mcp/cli.d.ts +15 -0
- package/dist/mcp/cli.js +108 -0
- package/dist/mcp/index.d.ts +8 -0
- package/dist/mcp/index.js +8 -0
- package/dist/mcp/main.d.ts +2 -0
- package/dist/mcp/main.js +8 -0
- package/dist/mcp/secrets.d.ts +50 -0
- package/dist/mcp/secrets.js +193 -0
- package/dist/mcp/server.d.ts +48 -0
- package/dist/mcp/server.js +653 -0
- package/dist/mcp/tree.d.ts +10 -0
- package/dist/mcp/tree.js +36 -0
- package/dist/passthrough.d.ts +1 -1
- package/dist/product.js +1 -1
- package/dist/settings.js +1 -1
- package/dist/telemetry.d.ts +0 -1
- package/dist/telemetry.js +5 -4
- package/dist/virtdisplay.d.ts +1 -1
- package/dist/virtdisplay.js +1 -1
- package/dist/warnings.js +1 -1
- package/package.json +57 -13
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export declare const BASELINE_OVERRIDES_PREF = "privacy.baselineFingerprintingProtection.overrides";
|
|
2
|
+
export declare const CANVAS_PLACEHOLDER_TARGETS: readonly ["+CanvasImageExtractionPrompt", "+CanvasExtractionBeforeUserInputIsBlocked", "+CanvasExtractionFromThirdPartiesIsBlocked"];
|
|
3
|
+
export declare const WEBGPU_BLOCKLIST_PREF = "gfx.blacklist.webgpu";
|
|
4
|
+
export declare const FEATURE_STATUS_OK = 1;
|
|
5
|
+
export declare const FEATURE_BLOCKED_DEVICE = 4;
|
|
6
|
+
/** A GPU as WEBGL_debug_renderer_info reports it: [vendor, renderer]. */
|
|
7
|
+
export type Gpu = [string, string];
|
|
8
|
+
/** Turn on the canvas placeholder, keeping any baseline overrides already set. */
|
|
9
|
+
export declare function addCanvasPlaceholder(prefs: Record<string, any>): void;
|
|
10
|
+
export declare function hasCanvasPlaceholder(prefs: Record<string, any>): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Expose navigator.gpu where Firefox on the claimed device has it, with the
|
|
13
|
+
* host's adapter only when `gpu` is the host's hardware GPU.
|
|
14
|
+
*
|
|
15
|
+
* Firefox enables WebGPU on Windows and on Apple Silicon Macs only
|
|
16
|
+
* (dom.webgpu.enabled in StaticPrefList.yaml). Any other adapter would
|
|
17
|
+
* contradict the claimed GPU, so requestAdapter() returns null, as Windows
|
|
18
|
+
* Firefox does on the Microsoft Basic Render Driver. The status is written
|
|
19
|
+
* either way, because a persistent profile saves it and the next startup
|
|
20
|
+
* reads it. Prefs the caller set are kept.
|
|
21
|
+
*/
|
|
22
|
+
export declare function setWebgpu(prefs: Record<string, any>, targetOs: string, gpu: [string | undefined, string | undefined], host: Gpu | null): void;
|
|
23
|
+
/** A browser that cannot answer a WebGL probe must not hold the launch forever. */
|
|
24
|
+
export declare const HOST_GPU_PROBE_TIMEOUT_MS = 30000;
|
|
25
|
+
/**
|
|
26
|
+
* The [vendor, renderer] this machine's Firefox reports, or null without WebGL.
|
|
27
|
+
*
|
|
28
|
+
* Read from the binary about to launch, with no identity applied, under the
|
|
29
|
+
* same display and the same rendering prefs: headless, Xvfb, a GPU display and
|
|
30
|
+
* a real display can each render on a different device. The strings are the
|
|
31
|
+
* ones Firefox sanitizes itself.
|
|
32
|
+
*/
|
|
33
|
+
export declare function hostGpu(executablePath: string, headless: boolean, env: Record<string, string | number | boolean>, prefs: Record<string, any>): Promise<Gpu | null>;
|
|
34
|
+
/**
|
|
35
|
+
* Whether the host's canvas and WebGL come from a GPU, not a software
|
|
36
|
+
* rasterizer.
|
|
37
|
+
*/
|
|
38
|
+
export declare function rendersOnHardware(gpu: Gpu | null): gpu is Gpu;
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What this machine renders, and covering it when the identity claims another
|
|
3
|
+
* machine. The twin of host_rendering.py.
|
|
4
|
+
*
|
|
5
|
+
* A page can draw a canvas or a WebGL scene and read the pixels back, and those
|
|
6
|
+
* pixels come from the real OS, driver and GPU whatever the identity claims. On
|
|
7
|
+
* the host's own OS the identity claims the GPU the host renders with, so the
|
|
8
|
+
* pixels agree with it. An identity on another OS, or naming another GPU,
|
|
9
|
+
* cannot agree, so its canvas readback is replaced with random data, as
|
|
10
|
+
* privacy.resistFingerprinting does in LibreWolf, Tor Browser and Mullvad
|
|
11
|
+
* Browser. Stock Firefox does not do that.
|
|
12
|
+
* WebGPU hands the page the host's adapter, so the identity gets it only when it
|
|
13
|
+
* claims the host's GPU.
|
|
14
|
+
*/
|
|
15
|
+
import { firefox } from "playwright-core";
|
|
16
|
+
import { isSoftwareRenderer } from "./fingerprints.js";
|
|
17
|
+
import { GPU_PREFS } from "./gpudisplay.js";
|
|
18
|
+
export const BASELINE_OVERRIDES_PREF = "privacy.baselineFingerprintingProtection.overrides";
|
|
19
|
+
// The canvas targets privacy.resistFingerprinting turns on, and only those:
|
|
20
|
+
// readback without the site's permission returns random data.
|
|
21
|
+
export const CANVAS_PLACEHOLDER_TARGETS = [
|
|
22
|
+
"+CanvasImageExtractionPrompt",
|
|
23
|
+
"+CanvasExtractionBeforeUserInputIsBlocked",
|
|
24
|
+
"+CanvasExtractionFromThirdPartiesIsBlocked",
|
|
25
|
+
];
|
|
26
|
+
// The downloadable blocklist's pref for WebGPU and its nsIGfxInfo statuses
|
|
27
|
+
// (widget/GfxInfoFeatureStatusDefs.inc). A blocked device resolves
|
|
28
|
+
// requestAdapter() to null, as on a machine whose GPU Firefox blocks.
|
|
29
|
+
export const WEBGPU_BLOCKLIST_PREF = "gfx.blacklist.webgpu";
|
|
30
|
+
export const FEATURE_STATUS_OK = 1;
|
|
31
|
+
export const FEATURE_BLOCKED_DEVICE = 4;
|
|
32
|
+
// What the launcher itself adds to the browser's environment; none of it
|
|
33
|
+
// changes which device Firefox renders on.
|
|
34
|
+
const LAUNCHER_ENV = ["CAMOU_", "FONTCONFIG_FILE"];
|
|
35
|
+
/** Turn on the canvas placeholder, keeping any baseline overrides already set. */
|
|
36
|
+
export function addCanvasPlaceholder(prefs) {
|
|
37
|
+
const overrides = String(prefs[BASELINE_OVERRIDES_PREF] || "")
|
|
38
|
+
.split(",")
|
|
39
|
+
.filter(Boolean);
|
|
40
|
+
prefs[BASELINE_OVERRIDES_PREF] = [
|
|
41
|
+
...overrides,
|
|
42
|
+
...CANVAS_PLACEHOLDER_TARGETS,
|
|
43
|
+
].join(",");
|
|
44
|
+
}
|
|
45
|
+
export function hasCanvasPlaceholder(prefs) {
|
|
46
|
+
return String(prefs[BASELINE_OVERRIDES_PREF] || "").includes(CANVAS_PLACEHOLDER_TARGETS[0]);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Expose navigator.gpu where Firefox on the claimed device has it, with the
|
|
50
|
+
* host's adapter only when `gpu` is the host's hardware GPU.
|
|
51
|
+
*
|
|
52
|
+
* Firefox enables WebGPU on Windows and on Apple Silicon Macs only
|
|
53
|
+
* (dom.webgpu.enabled in StaticPrefList.yaml). Any other adapter would
|
|
54
|
+
* contradict the claimed GPU, so requestAdapter() returns null, as Windows
|
|
55
|
+
* Firefox does on the Microsoft Basic Render Driver. The status is written
|
|
56
|
+
* either way, because a persistent profile saves it and the next startup
|
|
57
|
+
* reads it. Prefs the caller set are kept.
|
|
58
|
+
*/
|
|
59
|
+
export function setWebgpu(prefs, targetOs, gpu, host) {
|
|
60
|
+
// A key the caller set is kept even when its value is null, as Python's
|
|
61
|
+
// setdefault keeps it.
|
|
62
|
+
if (!("dom.webgpu.enabled" in prefs)) {
|
|
63
|
+
prefs["dom.webgpu.enabled"] =
|
|
64
|
+
targetOs === "win" || (targetOs === "mac" && gpu[0] === "Apple");
|
|
65
|
+
}
|
|
66
|
+
if (prefs["dom.webgpu.enabled"] && !(WEBGPU_BLOCKLIST_PREF in prefs)) {
|
|
67
|
+
const ownAdapter = rendersOnHardware(host) && gpu[0] === host[0] && gpu[1] === host[1];
|
|
68
|
+
prefs[WEBGPU_BLOCKLIST_PREF] = ownAdapter
|
|
69
|
+
? FEATURE_STATUS_OK
|
|
70
|
+
: FEATURE_BLOCKED_DEVICE;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const probes = new Map();
|
|
74
|
+
/** A browser that cannot answer a WebGL probe must not hold the launch forever. */
|
|
75
|
+
export const HOST_GPU_PROBE_TIMEOUT_MS = 30_000;
|
|
76
|
+
function within(promise, timeoutMs, message) {
|
|
77
|
+
return new Promise((resolve, reject) => {
|
|
78
|
+
const timer = setTimeout(() => reject(new Error(message)), timeoutMs);
|
|
79
|
+
timer.unref();
|
|
80
|
+
promise.then((value) => {
|
|
81
|
+
clearTimeout(timer);
|
|
82
|
+
resolve(value);
|
|
83
|
+
}, (error) => {
|
|
84
|
+
clearTimeout(timer);
|
|
85
|
+
reject(error);
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* The [vendor, renderer] this machine's Firefox reports, or null without WebGL.
|
|
91
|
+
*
|
|
92
|
+
* Read from the binary about to launch, with no identity applied, under the
|
|
93
|
+
* same display and the same rendering prefs: headless, Xvfb, a GPU display and
|
|
94
|
+
* a real display can each render on a different device. The strings are the
|
|
95
|
+
* ones Firefox sanitizes itself.
|
|
96
|
+
*/
|
|
97
|
+
export function hostGpu(executablePath, headless, env, prefs) {
|
|
98
|
+
const hostEnv = Object.entries(env)
|
|
99
|
+
.filter(([key]) => !LAUNCHER_ENV.some((prefix) => key.startsWith(prefix)))
|
|
100
|
+
.map(([key, value]) => [key, String(value)])
|
|
101
|
+
.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));
|
|
102
|
+
const hostPrefs = Object.keys(GPU_PREFS)
|
|
103
|
+
.filter((key) => key in prefs)
|
|
104
|
+
.map((key) => [key, prefs[key]]);
|
|
105
|
+
const key = JSON.stringify([executablePath, headless, hostEnv, hostPrefs]);
|
|
106
|
+
let gpu = probes.get(key);
|
|
107
|
+
if (!gpu) {
|
|
108
|
+
gpu = readGpu(executablePath, headless, Object.fromEntries(hostEnv), Object.fromEntries(hostPrefs));
|
|
109
|
+
// Remember a reading, not a failure: the next launch tries again.
|
|
110
|
+
gpu.catch(() => probes.delete(key));
|
|
111
|
+
probes.set(key, gpu);
|
|
112
|
+
}
|
|
113
|
+
return gpu;
|
|
114
|
+
}
|
|
115
|
+
async function readGpu(executablePath, headless, env, prefs) {
|
|
116
|
+
// A display that accepts connections but never answers the X handshake
|
|
117
|
+
// leaves Firefox inside getContext() forever. The launch, the read and the
|
|
118
|
+
// cleanup share one deadline, and a timeout says what it was waiting on.
|
|
119
|
+
const deadline = Date.now() + HOST_GPU_PROBE_TIMEOUT_MS;
|
|
120
|
+
const display = env.DISPLAY ? ` (DISPLAY=${env.DISPLAY})` : "";
|
|
121
|
+
const timeoutMessage = `Host GPU probe timed out after ${HOST_GPU_PROBE_TIMEOUT_MS} ms ` +
|
|
122
|
+
`while launching ${executablePath}${display}. The browser did not answer ` +
|
|
123
|
+
"the WebGL probe; check that the display accepts X connections.";
|
|
124
|
+
const remaining = () => Math.max(1, deadline - Date.now());
|
|
125
|
+
let browser;
|
|
126
|
+
let result = null;
|
|
127
|
+
let failed = false;
|
|
128
|
+
let failure;
|
|
129
|
+
let closeFailure;
|
|
130
|
+
try {
|
|
131
|
+
browser = await within(firefox.launch({
|
|
132
|
+
executablePath,
|
|
133
|
+
headless,
|
|
134
|
+
env,
|
|
135
|
+
timeout: remaining(),
|
|
136
|
+
// The launch forces WebGL on, which can choose another device.
|
|
137
|
+
firefoxUserPrefs: { ...prefs, "webgl.force-enabled": true },
|
|
138
|
+
}), remaining(), timeoutMessage);
|
|
139
|
+
const page = await within(browser.newPage(), remaining(), timeoutMessage);
|
|
140
|
+
result = await within(page.evaluate(() => {
|
|
141
|
+
const gl = globalThis.document
|
|
142
|
+
.createElement("canvas")
|
|
143
|
+
.getContext("webgl");
|
|
144
|
+
const info = gl?.getExtension("WEBGL_debug_renderer_info");
|
|
145
|
+
return info
|
|
146
|
+
? [
|
|
147
|
+
gl.getParameter(info.UNMASKED_VENDOR_WEBGL),
|
|
148
|
+
gl.getParameter(info.UNMASKED_RENDERER_WEBGL),
|
|
149
|
+
]
|
|
150
|
+
: null;
|
|
151
|
+
}), remaining(), timeoutMessage);
|
|
152
|
+
}
|
|
153
|
+
catch (error) {
|
|
154
|
+
failed = true;
|
|
155
|
+
failure = error;
|
|
156
|
+
}
|
|
157
|
+
finally {
|
|
158
|
+
if (browser) {
|
|
159
|
+
try {
|
|
160
|
+
await within(browser.close(), remaining(), timeoutMessage);
|
|
161
|
+
}
|
|
162
|
+
catch (error) {
|
|
163
|
+
closeFailure = error;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
// The read failure is the one to report; a close failure only on its own.
|
|
168
|
+
if (failed)
|
|
169
|
+
throw failure;
|
|
170
|
+
if (closeFailure !== undefined)
|
|
171
|
+
throw closeFailure;
|
|
172
|
+
return result;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Whether the host's canvas and WebGL come from a GPU, not a software
|
|
176
|
+
* rasterizer.
|
|
177
|
+
*/
|
|
178
|
+
export function rendersOnHardware(gpu) {
|
|
179
|
+
return gpu !== null && !isSoftwareRenderer(gpu[1]);
|
|
180
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-channel humanized input, run by the driver, never by the browser.
|
|
3
|
+
* The TypeScript twin of python/camoucore/src/camoucore/camoufox/humanize.py.
|
|
4
|
+
*
|
|
5
|
+
* import { Camoufox, myuri, raw } from "camoufox";
|
|
6
|
+
*
|
|
7
|
+
* await Camoufox({ humanize: true }); // myuri on every channel
|
|
8
|
+
* await Camoufox({
|
|
9
|
+
* humanize: {
|
|
10
|
+
* mouse: myuri({ move: myMove }),
|
|
11
|
+
* scroll: raw(),
|
|
12
|
+
* settings: { typing: { wpm: 70 } },
|
|
13
|
+
* seed: 1234,
|
|
14
|
+
* },
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* The browser has no humanization of its own: each Playwright input call
|
|
18
|
+
* reaches the page as the one native-looking event it asks for, when it is
|
|
19
|
+
* sent (docs/input-dispatch.md). A channel (mouse, keyboard, scroll) is one of
|
|
20
|
+
*
|
|
21
|
+
* myuri() myuri's smart actions (https://github.com/JWriter20/Myuri):
|
|
22
|
+
* paths, clicks, typing and wheel turns as the people it was
|
|
23
|
+
* fitted to make them on the identity's OS, and the decisions
|
|
24
|
+
* around a click (scroll into view, the point, whether it lands)
|
|
25
|
+
* raw() Playwright's own calls, unchanged
|
|
26
|
+
*
|
|
27
|
+
* cursory() is another name for myuri(), which runs cursory's paths.
|
|
28
|
+
*
|
|
29
|
+
* `myuri(parts)` replaces any of myuri's parts on its channel with a function
|
|
30
|
+
* of yours; the rest stay myuri's (_humanize_playwright.ts). `humanize` may be
|
|
31
|
+
* null / false (every channel raw), true (every channel myuri), or an object
|
|
32
|
+
* per channel plus an optional `seed` and `settings`; an omitted channel is
|
|
33
|
+
* myuri. `settings` are myuri's (its README lists each one), and the seed draws
|
|
34
|
+
* one person around them. Nothing about it reaches the browser's config.
|
|
35
|
+
*/
|
|
36
|
+
import { type BoundingBox, type DeepPartial, type MyuriSettings, type PartContext, type Vector } from "@jwriter20/myuri";
|
|
37
|
+
export declare const CHANNELS: readonly ["mouse", "keyboard", "scroll"];
|
|
38
|
+
export type Channel = (typeof CHANNELS)[number];
|
|
39
|
+
/** The myuri parts each channel's myuri() may replace (myuri's PARTS). */
|
|
40
|
+
export declare const CHANNEL_PARTS: Record<Channel, readonly string[]>;
|
|
41
|
+
/**
|
|
42
|
+
* What myuri() takes: functions that replace myuri's parts, each called with
|
|
43
|
+
* the page, the part's arguments and `{ default, rng, play }`.
|
|
44
|
+
*/
|
|
45
|
+
export interface MyuriOptions {
|
|
46
|
+
move?: (page: any, x: number, y: number, ctx: PartContext<void>) => unknown;
|
|
47
|
+
press?: (page: any, button: "left" | "right" | "middle", clickCount: number, ctx: PartContext<void>) => unknown;
|
|
48
|
+
point?: (page: any, box: BoundingBox, attempt: number, ctx: PartContext<Vector>) => Vector | Promise<Vector>;
|
|
49
|
+
reaches?: (page: any, locator: any, x: number, y: number, pressing: boolean, ctx: PartContext<string | null>) => string | null | Promise<string | null>;
|
|
50
|
+
intoView?: (page: any, locator: any, ctx: PartContext<void>) => unknown;
|
|
51
|
+
wheel?: (page: any, dx: number, dy: number, ctx: PartContext<void>) => unknown;
|
|
52
|
+
type?: (page: any, text: string, ctx: PartContext<void>) => unknown;
|
|
53
|
+
key?: (page: any, key: string, ctx: PartContext<void>) => unknown;
|
|
54
|
+
}
|
|
55
|
+
export interface Engine {
|
|
56
|
+
engine: "raw" | "myuri";
|
|
57
|
+
options: MyuriOptions;
|
|
58
|
+
}
|
|
59
|
+
export type HumanizeSetting = boolean | Record<string, unknown> | null | undefined;
|
|
60
|
+
/** Playwright's own dispatch, byte for byte. */
|
|
61
|
+
export declare function raw(): Engine;
|
|
62
|
+
/**
|
|
63
|
+
* myuri's smart actions on the channel. Each key names a part to replace with
|
|
64
|
+
* your function, called as `fn(page, ...args, { default, rng, play })`:
|
|
65
|
+
*
|
|
66
|
+
* mouse move(x, y) press(button, clickCount) point(box, attempt)
|
|
67
|
+
* reaches(locator, x, y, pressing)
|
|
68
|
+
* keyboard type(text) key(key)
|
|
69
|
+
* scroll intoView(locator) wheel(dx, dy)
|
|
70
|
+
*
|
|
71
|
+
* `default(...args)` runs myuri's part (with the same arguments when given
|
|
72
|
+
* none), `rng()` draws from the humanize seed's stream, and `play(steps)`
|
|
73
|
+
* plays a timeline of input. Speeds and the like are `humanize.settings`.
|
|
74
|
+
*/
|
|
75
|
+
export declare function myuri(options?: MyuriOptions): Engine;
|
|
76
|
+
export declare const cursory: typeof myuri;
|
|
77
|
+
/** A checked `humanize` setting. */
|
|
78
|
+
export interface Humanize {
|
|
79
|
+
engines: Record<Channel, Engine>;
|
|
80
|
+
seed?: number;
|
|
81
|
+
settings: DeepPartial<MyuriSettings>;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* The engine per channel of a `humanize` setting, the seed if given, and
|
|
85
|
+
* myuri's settings ({} when not given).
|
|
86
|
+
*/
|
|
87
|
+
export declare function normalize(humanize: unknown): Humanize;
|
|
88
|
+
/** The channels of a `humanize` setting that an engine in this process drives. */
|
|
89
|
+
export declare function drivenChannels(humanize: unknown): Channel[];
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-channel humanized input, run by the driver, never by the browser.
|
|
3
|
+
* The TypeScript twin of python/camoucore/src/camoucore/camoufox/humanize.py.
|
|
4
|
+
*
|
|
5
|
+
* import { Camoufox, myuri, raw } from "camoufox";
|
|
6
|
+
*
|
|
7
|
+
* await Camoufox({ humanize: true }); // myuri on every channel
|
|
8
|
+
* await Camoufox({
|
|
9
|
+
* humanize: {
|
|
10
|
+
* mouse: myuri({ move: myMove }),
|
|
11
|
+
* scroll: raw(),
|
|
12
|
+
* settings: { typing: { wpm: 70 } },
|
|
13
|
+
* seed: 1234,
|
|
14
|
+
* },
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* The browser has no humanization of its own: each Playwright input call
|
|
18
|
+
* reaches the page as the one native-looking event it asks for, when it is
|
|
19
|
+
* sent (docs/input-dispatch.md). A channel (mouse, keyboard, scroll) is one of
|
|
20
|
+
*
|
|
21
|
+
* myuri() myuri's smart actions (https://github.com/JWriter20/Myuri):
|
|
22
|
+
* paths, clicks, typing and wheel turns as the people it was
|
|
23
|
+
* fitted to make them on the identity's OS, and the decisions
|
|
24
|
+
* around a click (scroll into view, the point, whether it lands)
|
|
25
|
+
* raw() Playwright's own calls, unchanged
|
|
26
|
+
*
|
|
27
|
+
* cursory() is another name for myuri(), which runs cursory's paths.
|
|
28
|
+
*
|
|
29
|
+
* `myuri(parts)` replaces any of myuri's parts on its channel with a function
|
|
30
|
+
* of yours; the rest stay myuri's (_humanize_playwright.ts). `humanize` may be
|
|
31
|
+
* null / false (every channel raw), true (every channel myuri), or an object
|
|
32
|
+
* per channel plus an optional `seed` and `settings`; an omitted channel is
|
|
33
|
+
* myuri. `settings` are myuri's (its README lists each one), and the seed draws
|
|
34
|
+
* one person around them. Nothing about it reaches the browser's config.
|
|
35
|
+
*/
|
|
36
|
+
import { resolveSettings, } from "@jwriter20/myuri";
|
|
37
|
+
import { pyRepr, ValueError } from "./pycompat.js";
|
|
38
|
+
export const CHANNELS = ["mouse", "keyboard", "scroll"];
|
|
39
|
+
/** The myuri parts each channel's myuri() may replace (myuri's PARTS). */
|
|
40
|
+
export const CHANNEL_PARTS = {
|
|
41
|
+
mouse: ["move", "press", "point", "reaches"],
|
|
42
|
+
keyboard: ["type", "key"],
|
|
43
|
+
scroll: ["intoView", "wheel"],
|
|
44
|
+
};
|
|
45
|
+
/** Playwright's own dispatch, byte for byte. */
|
|
46
|
+
export function raw() {
|
|
47
|
+
return { engine: "raw", options: {} };
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* myuri's smart actions on the channel. Each key names a part to replace with
|
|
51
|
+
* your function, called as `fn(page, ...args, { default, rng, play })`:
|
|
52
|
+
*
|
|
53
|
+
* mouse move(x, y) press(button, clickCount) point(box, attempt)
|
|
54
|
+
* reaches(locator, x, y, pressing)
|
|
55
|
+
* keyboard type(text) key(key)
|
|
56
|
+
* scroll intoView(locator) wheel(dx, dy)
|
|
57
|
+
*
|
|
58
|
+
* `default(...args)` runs myuri's part (with the same arguments when given
|
|
59
|
+
* none), `rng()` draws from the humanize seed's stream, and `play(steps)`
|
|
60
|
+
* plays a timeline of input. Speeds and the like are `humanize.settings`.
|
|
61
|
+
*/
|
|
62
|
+
export function myuri(options = {}) {
|
|
63
|
+
const parts = Object.values(CHANNEL_PARTS).flat();
|
|
64
|
+
const unknown = Object.keys(options)
|
|
65
|
+
.filter((key) => !parts.includes(key))
|
|
66
|
+
.sort();
|
|
67
|
+
if (unknown.length)
|
|
68
|
+
throw new ValueError(`myuri() has no part '${unknown[0]}'; the parts are ${JSON.stringify(CHANNEL_PARTS)} ` +
|
|
69
|
+
"(speeds and the like are humanize.settings)");
|
|
70
|
+
for (const [name, fn] of Object.entries(options))
|
|
71
|
+
if (typeof fn !== "function")
|
|
72
|
+
throw new ValueError(`myuri({ ${name} }) takes the function that replaces the part, got ${pyRepr(fn)}`);
|
|
73
|
+
return { engine: "myuri", options: { ...options } };
|
|
74
|
+
}
|
|
75
|
+
export const cursory = myuri;
|
|
76
|
+
const IN_BROWSER = "the browser does not humanize input: each Playwright call is one event. " +
|
|
77
|
+
"Pass True, or myuri() or raw() per channel (camoufox.humanize)";
|
|
78
|
+
function asEngine(channel, value) {
|
|
79
|
+
const entry = value;
|
|
80
|
+
if (typeof entry !== "object" ||
|
|
81
|
+
!["myuri", "cursory", "raw"].includes(entry?.engine))
|
|
82
|
+
throw new ValueError(`humanize["${channel}"]=${pyRepr(value)} is not an engine; ${IN_BROWSER}`);
|
|
83
|
+
const options = entry?.options ?? {};
|
|
84
|
+
if (entry?.engine === "raw") {
|
|
85
|
+
if (Object.keys(options).length)
|
|
86
|
+
throw new ValueError(`humanize["${channel}"]: raw() takes no options`);
|
|
87
|
+
return raw();
|
|
88
|
+
}
|
|
89
|
+
const engine = myuri(options);
|
|
90
|
+
const allowed = CHANNEL_PARTS[channel];
|
|
91
|
+
const misplaced = Object.keys(options)
|
|
92
|
+
.filter((key) => !allowed.includes(key))
|
|
93
|
+
.sort();
|
|
94
|
+
if (misplaced.length)
|
|
95
|
+
throw new ValueError(`humanize["${channel}"]: myuri({ ${misplaced[0]} }) is not a ${channel} part; ` +
|
|
96
|
+
`the ${channel} parts are ${allowed.join(", ")}`);
|
|
97
|
+
return engine;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* The engine per channel of a `humanize` setting, the seed if given, and
|
|
101
|
+
* myuri's settings ({} when not given).
|
|
102
|
+
*/
|
|
103
|
+
export function normalize(humanize) {
|
|
104
|
+
const every = (engine) => ({
|
|
105
|
+
engines: Object.fromEntries(CHANNELS.map((c) => [c, engine()])),
|
|
106
|
+
settings: {},
|
|
107
|
+
});
|
|
108
|
+
if (humanize === null || humanize === undefined || humanize === false)
|
|
109
|
+
return every(raw);
|
|
110
|
+
if (humanize === true)
|
|
111
|
+
return every(myuri);
|
|
112
|
+
if (typeof humanize !== "object" || Array.isArray(humanize))
|
|
113
|
+
throw new ValueError(`humanize=${pyRepr(humanize)}: ${IN_BROWSER}`);
|
|
114
|
+
const setting = humanize;
|
|
115
|
+
const unknown = Object.keys(setting).filter((key) => !CHANNELS.includes(key) &&
|
|
116
|
+
key !== "seed" &&
|
|
117
|
+
key !== "settings");
|
|
118
|
+
if (unknown.length)
|
|
119
|
+
throw new ValueError(`humanize has no channel ${JSON.stringify(unknown)}; the channels are ${CHANNELS.join(", ")}, and "seed" and "settings"`);
|
|
120
|
+
const seed = (setting.seed ?? undefined);
|
|
121
|
+
if (seed !== undefined &&
|
|
122
|
+
(!Number.isInteger(seed) || seed < 0 || seed >= 2 ** 32))
|
|
123
|
+
throw new ValueError(`humanize.seed must be an integer in [0, 2**32), got ${String(seed)}`);
|
|
124
|
+
const settings = (setting.settings ?? {});
|
|
125
|
+
if (typeof settings !== "object" || Array.isArray(settings))
|
|
126
|
+
throw new ValueError(`humanize.settings must be an object of myuri settings, got ${pyRepr(settings)}`);
|
|
127
|
+
try {
|
|
128
|
+
resolveSettings(settings);
|
|
129
|
+
}
|
|
130
|
+
catch (e) {
|
|
131
|
+
throw new ValueError(`humanize.settings: ${e.message}`);
|
|
132
|
+
}
|
|
133
|
+
const engines = Object.fromEntries(CHANNELS.map((c) => [
|
|
134
|
+
c,
|
|
135
|
+
asEngine(c, setting[c] === undefined ? myuri() : setting[c]),
|
|
136
|
+
]));
|
|
137
|
+
return { engines, seed, settings };
|
|
138
|
+
}
|
|
139
|
+
/** The channels of a `humanize` setting that an engine in this process drives. */
|
|
140
|
+
export function drivenChannels(humanize) {
|
|
141
|
+
const { engines } = normalize(humanize);
|
|
142
|
+
return CHANNELS.filter((c) => engines[c].engine !== "raw");
|
|
143
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public API. Mirrors python/camoucore/src/camoucore/camoufox/__init__.py (Camoufox, NewBrowser,
|
|
3
|
+
* NewContext, their Async* twins, DefaultAddons, launch_options), plus the
|
|
4
|
+
* package-management and server helpers the TS port has always exported.
|
|
5
|
+
*/
|
|
6
|
+
import "./node-floor.js";
|
|
7
|
+
export { VirtualDisplay } from "../virtdisplay.js";
|
|
8
|
+
export { attach } from "./_humanize_playwright.js";
|
|
9
|
+
export type { DefaultAddon } from "./addons.js";
|
|
10
|
+
export { DefaultAddons } from "./addons.js";
|
|
11
|
+
export { AsyncCamoufox, AsyncNewBrowser, AsyncNewContext, } from "./async_api.js";
|
|
12
|
+
export { generateContextFingerprint, getRandomPreset, loadPresets, Screen, } from "./fingerprints.js";
|
|
13
|
+
export { cursory, type HumanizeSetting, type MyuriOptions, myuri, raw, } from "./humanize.js";
|
|
14
|
+
export { findInstalledVersion, listInstalled, printTree, } from "./multiversion.js";
|
|
15
|
+
export { INSTALL_DIR, OS_NAME } from "./paths.js";
|
|
16
|
+
export { CamoufoxFetcher, installedVerStr, RepoConfig } from "./pkgman.js";
|
|
17
|
+
export { PRODUCT } from "./product.js";
|
|
18
|
+
export { type LaunchServerOptions, launchServer } from "./server.js";
|
|
19
|
+
export { Camoufox, type Headless, NewBrowser, type NewBrowserOptions, NewContext, type NewContextOptions, } from "./sync_api.js";
|
|
20
|
+
export { type LaunchOptions, launchOptions, launchOptions as launch_options, } from "./utils.js";
|
|
21
|
+
export { FallbackWarning, LeakWarning } from "./warnings.js";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public API. Mirrors python/camoucore/src/camoucore/camoufox/__init__.py (Camoufox, NewBrowser,
|
|
3
|
+
* NewContext, their Async* twins, DefaultAddons, launch_options), plus the
|
|
4
|
+
* package-management and server helpers the TS port has always exported.
|
|
5
|
+
*/
|
|
6
|
+
// First: fail with the Node.js floor before any module needs it.
|
|
7
|
+
import "./node-floor.js";
|
|
8
|
+
export { VirtualDisplay } from "../virtdisplay.js";
|
|
9
|
+
export { attach } from "./_humanize_playwright.js";
|
|
10
|
+
export { DefaultAddons } from "./addons.js";
|
|
11
|
+
export { AsyncCamoufox, AsyncNewBrowser, AsyncNewContext, } from "./async_api.js";
|
|
12
|
+
export { generateContextFingerprint, getRandomPreset, loadPresets, Screen, } from "./fingerprints.js";
|
|
13
|
+
export { cursory, myuri, raw, } from "./humanize.js";
|
|
14
|
+
export { findInstalledVersion, listInstalled, printTree, } from "./multiversion.js";
|
|
15
|
+
export { INSTALL_DIR, OS_NAME } from "./paths.js";
|
|
16
|
+
export { CamoufoxFetcher, installedVerStr, RepoConfig } from "./pkgman.js";
|
|
17
|
+
export { PRODUCT } from "./product.js";
|
|
18
|
+
export { launchServer } from "./server.js";
|
|
19
|
+
export { Camoufox, NewBrowser, NewContext, } from "./sync_api.js";
|
|
20
|
+
export { launchOptions, launchOptions as launch_options, } from "./utils.js";
|
|
21
|
+
export { FallbackWarning, LeakWarning } from "./warnings.js";
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Proxy credentials for Juggler: the SOCKS5 username and password Playwright
|
|
3
|
+
* refuses to pass, and the public IPv6 behind a proxy. The other proxy and
|
|
4
|
+
* public-IP lookups are camoucore's (camoucore/ip.js).
|
|
5
|
+
*
|
|
6
|
+
* TypeScript twin of python/camoucore/src/camoucore/camoufox/ip.py.
|
|
7
|
+
*/
|
|
8
|
+
import { type ProxyConfig } from "../ip.js";
|
|
9
|
+
export interface ProxyAuth {
|
|
10
|
+
host: string;
|
|
11
|
+
port: number | null;
|
|
12
|
+
username: string;
|
|
13
|
+
password: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Splits a SOCKS5 proxy's username and password from what Playwright is given.
|
|
17
|
+
*
|
|
18
|
+
* Playwright refuses a `socks5://` proxy that has a username ("Browser does
|
|
19
|
+
* not support socks5 proxy authentication"), but Juggler can send them
|
|
20
|
+
* (RFC 1929). Returns the proxy without its credentials, and the credentials
|
|
21
|
+
* with the proxy's host and port, for Juggler; or the proxy unchanged and
|
|
22
|
+
* null when it is not SOCKS5 or has no credentials.
|
|
23
|
+
*/
|
|
24
|
+
export declare function socks5Auth<T extends ProxyConfig | undefined | null>(proxy: T): [T, ProxyAuth | null];
|
|
25
|
+
/**
|
|
26
|
+
* The environment variable that carries a launch-level SOCKS5 proxy's
|
|
27
|
+
* credentials to Juggler (TargetRegistry.js), which clears it once read.
|
|
28
|
+
*/
|
|
29
|
+
export declare const PROXY_AUTH_ENV = "CAMOU_PROXY_AUTH";
|
|
30
|
+
/** The environment that hands a launch-level proxy's credentials to Juggler. */
|
|
31
|
+
export declare function proxyAuthEnv(auth: ProxyAuth): Record<string, string>;
|
|
32
|
+
/**
|
|
33
|
+
* The init script that hands a context's SOCKS5 credentials to Juggler.
|
|
34
|
+
*
|
|
35
|
+
* Juggler takes it out of the context's init scripts (TargetRegistry.js), so
|
|
36
|
+
* it never reaches a page or a content process. It is valid JavaScript that
|
|
37
|
+
* does nothing, should a browser without that support run it.
|
|
38
|
+
*/
|
|
39
|
+
export declare function proxyAuthInitScript(auth: ProxyAuth): string;
|
|
40
|
+
/**
|
|
41
|
+
* This host's public IPv6 address, or the exit's behind `proxy`; null when it
|
|
42
|
+
* has none it can reach the internet from. The hosts have AAAA records only,
|
|
43
|
+
* so an answer proves the route.
|
|
44
|
+
*/
|
|
45
|
+
export declare function publicIPv6(proxy?: string): Promise<string | null>;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Proxy credentials for Juggler: the SOCKS5 username and password Playwright
|
|
3
|
+
* refuses to pass, and the public IPv6 behind a proxy. The other proxy and
|
|
4
|
+
* public-IP lookups are camoucore's (camoucore/ip.js).
|
|
5
|
+
*
|
|
6
|
+
* TypeScript twin of python/camoucore/src/camoucore/camoufox/ip.py.
|
|
7
|
+
*/
|
|
8
|
+
import { Impit } from "impit";
|
|
9
|
+
import { publicIPv6 as corePublicIPv6, DIRECT_IP_TIMEOUT_MS, PROXIED_IP_TIMEOUT_MS, validIPv6, } from "../ip.js";
|
|
10
|
+
import { InvalidProxy } from "./exceptions.js";
|
|
11
|
+
/**
|
|
12
|
+
* Splits a SOCKS5 proxy's username and password from what Playwright is given.
|
|
13
|
+
*
|
|
14
|
+
* Playwright refuses a `socks5://` proxy that has a username ("Browser does
|
|
15
|
+
* not support socks5 proxy authentication"), but Juggler can send them
|
|
16
|
+
* (RFC 1929). Returns the proxy without its credentials, and the credentials
|
|
17
|
+
* with the proxy's host and port, for Juggler; or the proxy unchanged and
|
|
18
|
+
* null when it is not SOCKS5 or has no credentials.
|
|
19
|
+
*/
|
|
20
|
+
export function socks5Auth(proxy) {
|
|
21
|
+
if (!proxy || !(proxy.username || proxy.password))
|
|
22
|
+
return [proxy, null];
|
|
23
|
+
const server = String(proxy.server ?? "");
|
|
24
|
+
// As Playwright reads the server: without a scheme, it is an HTTP proxy.
|
|
25
|
+
let url;
|
|
26
|
+
try {
|
|
27
|
+
url = new URL(server.includes("://") ? server : `http://${server}`);
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
throw new InvalidProxy(`Invalid proxy server: ${server}`, { cause: error });
|
|
31
|
+
}
|
|
32
|
+
if (url.protocol.toLowerCase() !== "socks5:" || !url.hostname)
|
|
33
|
+
return [proxy, null];
|
|
34
|
+
const { username, password, ...bare } = proxy;
|
|
35
|
+
return [
|
|
36
|
+
bare,
|
|
37
|
+
{
|
|
38
|
+
host: url.hostname.replace(/^\[(.*)\]$/, "$1"),
|
|
39
|
+
port: url.port ? Number(url.port) : null,
|
|
40
|
+
username: username || "",
|
|
41
|
+
password: password || "",
|
|
42
|
+
},
|
|
43
|
+
];
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The environment variable that carries a launch-level SOCKS5 proxy's
|
|
47
|
+
* credentials to Juggler (TargetRegistry.js), which clears it once read.
|
|
48
|
+
*/
|
|
49
|
+
export const PROXY_AUTH_ENV = "CAMOU_PROXY_AUTH";
|
|
50
|
+
/** The environment that hands a launch-level proxy's credentials to Juggler. */
|
|
51
|
+
export function proxyAuthEnv(auth) {
|
|
52
|
+
return { [PROXY_AUTH_ENV]: JSON.stringify(auth) };
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The init script that hands a context's SOCKS5 credentials to Juggler.
|
|
56
|
+
*
|
|
57
|
+
* Juggler takes it out of the context's init scripts (TargetRegistry.js), so
|
|
58
|
+
* it never reaches a page or a content process. It is valid JavaScript that
|
|
59
|
+
* does nothing, should a browser without that support run it.
|
|
60
|
+
*/
|
|
61
|
+
export function proxyAuthInitScript(auth) {
|
|
62
|
+
return `camoufoxProxyAuth: (${JSON.stringify(auth)});`;
|
|
63
|
+
}
|
|
64
|
+
// camoucore's publicIPv6() takes no proxy; this stays until it does. Impit has
|
|
65
|
+
// no close/dispose API and V8 rarely collects its tiny wrappers, so one
|
|
66
|
+
// instance per proxy is kept.
|
|
67
|
+
const impitCache = new Map();
|
|
68
|
+
const publicIPv6Cache = new Map();
|
|
69
|
+
function getImpit(proxy) {
|
|
70
|
+
const key = proxy ?? "";
|
|
71
|
+
let impit = impitCache.get(key);
|
|
72
|
+
if (!impit) {
|
|
73
|
+
// Certificates are verified: what this answers decides the identity.
|
|
74
|
+
impit = new Impit({
|
|
75
|
+
proxyUrl: proxy,
|
|
76
|
+
timeout: proxy ? PROXIED_IP_TIMEOUT_MS : DIRECT_IP_TIMEOUT_MS,
|
|
77
|
+
ignoreTlsErrors: false,
|
|
78
|
+
});
|
|
79
|
+
impitCache.set(key, impit);
|
|
80
|
+
}
|
|
81
|
+
return impit;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* This host's public IPv6 address, or the exit's behind `proxy`; null when it
|
|
85
|
+
* has none it can reach the internet from. The hosts have AAAA records only,
|
|
86
|
+
* so an answer proves the route.
|
|
87
|
+
*/
|
|
88
|
+
export function publicIPv6(proxy) {
|
|
89
|
+
if (!proxy)
|
|
90
|
+
return corePublicIPv6();
|
|
91
|
+
let pending = publicIPv6Cache.get(proxy);
|
|
92
|
+
if (!pending) {
|
|
93
|
+
pending = resolvePublicIPv6(proxy);
|
|
94
|
+
publicIPv6Cache.set(proxy, pending);
|
|
95
|
+
}
|
|
96
|
+
return pending;
|
|
97
|
+
}
|
|
98
|
+
async function resolvePublicIPv6(proxy) {
|
|
99
|
+
for (const url of ["https://api6.ipify.org", "https://v6.ident.me"]) {
|
|
100
|
+
let ip;
|
|
101
|
+
try {
|
|
102
|
+
const response = await getImpit(proxy).fetch(url);
|
|
103
|
+
if (!response.ok)
|
|
104
|
+
continue;
|
|
105
|
+
ip = (await response.text()).trim();
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
if (validIPv6(ip))
|
|
111
|
+
return ip;
|
|
112
|
+
}
|
|
113
|
+
return null;
|
|
114
|
+
}
|