bexxcv 0.0.0-stage → 1.0.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/README.md +493 -2
- package/dist/__main__.d.ts +2 -0
- package/dist/__main__.js +156 -0
- package/dist/__version__.d.ts +5 -0
- package/dist/__version__.js +5 -0
- package/dist/addons.d.ts +7 -0
- package/dist/addons.js +56 -0
- package/dist/browser-pin.d.ts +15 -0
- package/dist/browser-pin.js +34 -0
- package/dist/data-files/browser-pin.json +7 -0
- package/dist/data-files/territoryInfo.xml +2024 -0
- package/dist/exceptions.d.ts +79 -0
- package/dist/exceptions.js +159 -0
- package/dist/fingerprints.d.ts +5 -0
- package/dist/fingerprints.js +92 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/ip.d.ts +23 -0
- package/dist/ip.js +98 -0
- package/dist/locale.d.ts +26 -0
- package/dist/locale.js +292 -0
- package/dist/mappings/browserforge.config.d.ts +44 -0
- package/dist/mappings/browserforge.config.js +43 -0
- package/dist/mappings/fonts.config.d.ts +6 -0
- package/dist/mappings/fonts.config.js +822 -0
- package/dist/mappings/warnings.config.d.ts +16 -0
- package/dist/mappings/warnings.config.js +28 -0
- package/dist/multiversion.d.ts +27 -0
- package/dist/multiversion.js +88 -0
- package/dist/pkgman.d.ts +69 -0
- package/dist/pkgman.js +529 -0
- package/dist/selfupdate.d.ts +8 -0
- package/dist/selfupdate.js +84 -0
- package/dist/server.d.ts +3 -0
- package/dist/server.js +6 -0
- package/dist/sync_api.d.ts +11 -0
- package/dist/sync_api.js +47 -0
- package/dist/utils.d.ts +45 -0
- package/dist/utils.js +514 -0
- package/dist/virtdisplay.d.ts +12 -0
- package/dist/virtdisplay.js +139 -0
- package/dist/warnings.d.ts +4 -0
- package/dist/warnings.js +33 -0
- package/dist/webgl/sample.d.ts +19 -0
- package/dist/webgl/sample.js +103 -0
- package/dist/xvfb.d.ts +6 -0
- package/dist/xvfb.js +25 -0
- package/package.json +103 -5
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
export declare function getAsBooleanFromENV(name: string, defaultValue?: boolean | undefined): boolean;
|
|
9
|
+
export declare function spoofsWindowDimensions(fromOptions: Record<string, any>): boolean;
|
|
10
|
+
export declare function attachNoViewportDefault<T>(target: T): T;
|
|
11
|
+
export declare function syncAttachVD(browser: any, virtualDisplay?: VirtualDisplay | null): any;
|
|
12
|
+
export interface LaunchOptions {
|
|
13
|
+
os?: (typeof SUPPORTED_OS)[number] | (typeof SUPPORTED_OS)[number][];
|
|
14
|
+
block_images?: boolean;
|
|
15
|
+
block_webrtc?: boolean;
|
|
16
|
+
block_webgl?: boolean;
|
|
17
|
+
disable_coop?: boolean;
|
|
18
|
+
geoip?: string | boolean;
|
|
19
|
+
humanize?: boolean | number;
|
|
20
|
+
locale?: string | string[];
|
|
21
|
+
addons?: string[];
|
|
22
|
+
fonts?: string[];
|
|
23
|
+
custom_fonts_only?: boolean;
|
|
24
|
+
exclude_addons?: (keyof typeof DefaultAddons)[];
|
|
25
|
+
screen?: Screen;
|
|
26
|
+
window?: [number, number];
|
|
27
|
+
fingerprint?: Fingerprint;
|
|
28
|
+
ff_version?: number;
|
|
29
|
+
headless?: boolean | "virtual";
|
|
30
|
+
main_world_eval?: boolean;
|
|
31
|
+
executable_path?: string | PathLike;
|
|
32
|
+
firefox_user_prefs?: Record<string, any>;
|
|
33
|
+
proxy?: string | PlaywrightLaunchOptions["proxy"];
|
|
34
|
+
enable_cache?: boolean;
|
|
35
|
+
args?: string[];
|
|
36
|
+
env?: Record<string, string | number | boolean>;
|
|
37
|
+
debug?: boolean;
|
|
38
|
+
virtual_display?: string;
|
|
39
|
+
webgl_config?: [string, string];
|
|
40
|
+
[key: string]: any;
|
|
41
|
+
}
|
|
42
|
+
export declare function launchOptions({ config, os, block_images, block_webrtc, block_webgl, disable_coop, webgl_config, geoip, humanize, locale, addons, fonts, custom_fonts_only, exclude_addons, screen, window, fingerprint, ff_version, headless, main_world_eval, executable_path, firefox_user_prefs, proxy, enable_cache, args, env, i_know_what_im_doing, debug, virtual_display, ...launch_options }: Omit<LaunchOptions, "headless"> & {
|
|
43
|
+
headless?: boolean;
|
|
44
|
+
}): Promise<Record<string, any>>;
|
|
45
|
+
export {};
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,514 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { UAParser } from "ua-parser-js";
|
|
5
|
+
import { addDefaultAddons, confirmPaths, } from "./addons.js";
|
|
6
|
+
import { InvalidOS, InvalidPropertyType, NonFirefoxFingerprint, UnknownProperty, } from "./exceptions.js";
|
|
7
|
+
import { fromBrowserforge, generateFingerprint, SUPPORTED_OS, } from "./fingerprints.js";
|
|
8
|
+
import { publicIP, validIPv4, validIPv6 } from "./ip.js";
|
|
9
|
+
import { geoipAllowed, getGeolocation, handleLocales } from "./locale.js";
|
|
10
|
+
import FONTS from "./mappings/fonts.config.js";
|
|
11
|
+
import { ensureCamoufoxInstalled, getPath, installedVerStr, launchPath, OS_NAME, } from "./pkgman.js";
|
|
12
|
+
import { LeakWarning } from "./warnings.js";
|
|
13
|
+
import { sampleWebGL } from "./webgl/sample.js";
|
|
14
|
+
function cryptoRandInt(min, max) {
|
|
15
|
+
const buf = new Uint32Array(1);
|
|
16
|
+
crypto.getRandomValues(buf);
|
|
17
|
+
return min + (buf[0] % (max - min + 1));
|
|
18
|
+
}
|
|
19
|
+
function weightedPick(items, weights) {
|
|
20
|
+
const total = weights.reduce((a, b) => a + b, 0);
|
|
21
|
+
const buf = new Uint32Array(1);
|
|
22
|
+
crypto.getRandomValues(buf);
|
|
23
|
+
let threshold = (buf[0] / 0x100000000) * total;
|
|
24
|
+
for (let i = 0; i < items.length; i++) {
|
|
25
|
+
threshold -= weights[i];
|
|
26
|
+
if (threshold <= 0)
|
|
27
|
+
return items[i];
|
|
28
|
+
}
|
|
29
|
+
return items[items.length - 1];
|
|
30
|
+
}
|
|
31
|
+
const DPR_POOLS = {
|
|
32
|
+
mac: [[2, 70], [1, 20], [1.5, 10]],
|
|
33
|
+
win: [[1, 45], [1.25, 20], [1.5, 20], [2, 15]],
|
|
34
|
+
lin: [[1, 75], [2, 15], [1.5, 10]],
|
|
35
|
+
};
|
|
36
|
+
const CACHE_PREFS = {
|
|
37
|
+
"browser.sessionhistory.max_entries": 10,
|
|
38
|
+
"browser.sessionhistory.max_total_viewers": -1,
|
|
39
|
+
"browser.cache.memory.enable": true,
|
|
40
|
+
"browser.cache.disk_cache_ssl": true,
|
|
41
|
+
"browser.cache.disk.smart_size.enabled": true,
|
|
42
|
+
};
|
|
43
|
+
function getEnvVars(configMap, userAgentOS) {
|
|
44
|
+
const envVars = {};
|
|
45
|
+
let updatedConfigData;
|
|
46
|
+
try {
|
|
47
|
+
updatedConfigData = new TextEncoder().encode(JSON.stringify(configMap));
|
|
48
|
+
}
|
|
49
|
+
catch (e) {
|
|
50
|
+
console.error(`Error updating config: ${e}`);
|
|
51
|
+
process.exit(1);
|
|
52
|
+
}
|
|
53
|
+
const chunkSize = OS_NAME === "win" ? 2047 : 32767;
|
|
54
|
+
const configStr = new TextDecoder().decode(updatedConfigData);
|
|
55
|
+
for (let i = 0; i < configStr.length; i += chunkSize) {
|
|
56
|
+
const chunk = configStr.slice(i, i + chunkSize);
|
|
57
|
+
const envName = `CAMOU_CONFIG_${Math.floor(i / chunkSize) + 1}`;
|
|
58
|
+
try {
|
|
59
|
+
envVars[envName] = chunk;
|
|
60
|
+
}
|
|
61
|
+
catch (e) {
|
|
62
|
+
console.error(`Error setting ${envName}: ${e}`);
|
|
63
|
+
process.exit(1);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (OS_NAME === "lin") {
|
|
67
|
+
const fontconfigPath = getPath(path.join("fontconfig", userAgentOS));
|
|
68
|
+
envVars.FONTCONFIG_PATH = fontconfigPath;
|
|
69
|
+
}
|
|
70
|
+
return envVars;
|
|
71
|
+
}
|
|
72
|
+
export function getAsBooleanFromENV(name, defaultValue) {
|
|
73
|
+
const value = process.env[name];
|
|
74
|
+
if (value === "false" || value === "0")
|
|
75
|
+
return false;
|
|
76
|
+
if (value)
|
|
77
|
+
return true;
|
|
78
|
+
return !!defaultValue;
|
|
79
|
+
}
|
|
80
|
+
function loadProperties(filePath) {
|
|
81
|
+
let propFile;
|
|
82
|
+
filePath = filePath?.toString();
|
|
83
|
+
if (filePath) {
|
|
84
|
+
propFile = path.join(path.dirname(filePath), "properties.json");
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
propFile = getPath("properties.json");
|
|
88
|
+
}
|
|
89
|
+
const propData = readFileSync(propFile).toString();
|
|
90
|
+
const propDict = JSON.parse(propData);
|
|
91
|
+
return propDict.reduce((acc, prop) => {
|
|
92
|
+
acc[prop.property] = prop.type;
|
|
93
|
+
return acc;
|
|
94
|
+
}, {});
|
|
95
|
+
}
|
|
96
|
+
function validateConfig(configMap, propertyTypes) {
|
|
97
|
+
for (const [key, value] of Object.entries(configMap)) {
|
|
98
|
+
const expectedType = propertyTypes[key];
|
|
99
|
+
if (!expectedType) {
|
|
100
|
+
throw new UnknownProperty(`Unknown property ${key} in config`);
|
|
101
|
+
}
|
|
102
|
+
if (!validateType(value, expectedType)) {
|
|
103
|
+
throw new InvalidPropertyType(`Invalid type for property ${key}. Expected ${expectedType}, got ${typeof value}`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function validateType(value, expectedType) {
|
|
108
|
+
switch (expectedType) {
|
|
109
|
+
case "str":
|
|
110
|
+
return typeof value === "string";
|
|
111
|
+
case "int":
|
|
112
|
+
return Number.isInteger(value);
|
|
113
|
+
case "uint":
|
|
114
|
+
return Number.isInteger(value) && value >= 0;
|
|
115
|
+
case "double":
|
|
116
|
+
return typeof value === "number";
|
|
117
|
+
case "bool":
|
|
118
|
+
return typeof value === "boolean";
|
|
119
|
+
case "array":
|
|
120
|
+
return Array.isArray(value);
|
|
121
|
+
case "dict":
|
|
122
|
+
return (typeof value === "object" && value !== null && !Array.isArray(value));
|
|
123
|
+
default:
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
function getTargetOS(config) {
|
|
128
|
+
if (config["navigator.userAgent"]) {
|
|
129
|
+
return determineUAOS(config["navigator.userAgent"]);
|
|
130
|
+
}
|
|
131
|
+
return OS_NAME;
|
|
132
|
+
}
|
|
133
|
+
function determineUAOS(userAgent) {
|
|
134
|
+
const parser = new UAParser(userAgent);
|
|
135
|
+
const parsedUA = parser.getOS().name;
|
|
136
|
+
if (!parsedUA) {
|
|
137
|
+
throw new Error("Could not determine OS from user agent");
|
|
138
|
+
}
|
|
139
|
+
if (parsedUA.startsWith("macOS")) {
|
|
140
|
+
return "mac";
|
|
141
|
+
}
|
|
142
|
+
if (parsedUA.startsWith("Windows")) {
|
|
143
|
+
return "win";
|
|
144
|
+
}
|
|
145
|
+
return "lin";
|
|
146
|
+
}
|
|
147
|
+
function getScreenCons(headless) {
|
|
148
|
+
if (headless === false)
|
|
149
|
+
return undefined;
|
|
150
|
+
if (OS_NAME === "lin") {
|
|
151
|
+
try {
|
|
152
|
+
const out = execFileSync("xrandr", ["--current"], {
|
|
153
|
+
timeout: 2_000,
|
|
154
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
155
|
+
}).toString();
|
|
156
|
+
const m = out.match(/(\d+)x(\d+)\+0\+0/);
|
|
157
|
+
if (m) {
|
|
158
|
+
return {
|
|
159
|
+
maxWidth: parseInt(m[1], 10),
|
|
160
|
+
maxHeight: parseInt(m[2], 10),
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
catch {
|
|
165
|
+
return undefined;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return undefined;
|
|
169
|
+
}
|
|
170
|
+
function updateFonts(config, targetOS) {
|
|
171
|
+
const fonts = FONTS[targetOS];
|
|
172
|
+
if (config.fonts) {
|
|
173
|
+
config.fonts = Array.from(new Set([...fonts, ...config.fonts]));
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
config.fonts = fonts;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
function checkCustomFingerprint(fingerprint) {
|
|
180
|
+
const parser = new UAParser(fingerprint.navigator.userAgent);
|
|
181
|
+
const browserName = parser.getBrowser().name || "Non-Firefox";
|
|
182
|
+
if (browserName !== "Firefox") {
|
|
183
|
+
throw new NonFirefoxFingerprint(`"${browserName}" fingerprints are not supported in Camoufox. Using fingerprints from a browser other than Firefox WILL lead to detection. If this is intentional, pass i_know_what_im_doing=True.`);
|
|
184
|
+
}
|
|
185
|
+
LeakWarning.warn("custom_fingerprint", false);
|
|
186
|
+
}
|
|
187
|
+
function validateOS(os) {
|
|
188
|
+
if (!os)
|
|
189
|
+
return undefined;
|
|
190
|
+
if (Array.isArray(os)) {
|
|
191
|
+
os.every(validateOS);
|
|
192
|
+
return [...os];
|
|
193
|
+
}
|
|
194
|
+
if (!SUPPORTED_OS.includes(os)) {
|
|
195
|
+
throw new InvalidOS(`Camoufox does not support the OS: '${os}'`);
|
|
196
|
+
}
|
|
197
|
+
return [os];
|
|
198
|
+
}
|
|
199
|
+
function _cleanLocals(data) {
|
|
200
|
+
delete data.playwright;
|
|
201
|
+
delete data.persistentContext;
|
|
202
|
+
return data;
|
|
203
|
+
}
|
|
204
|
+
function mergeInto(target, source) {
|
|
205
|
+
Object.entries(source).forEach(([key, value]) => {
|
|
206
|
+
if (!(key in target)) {
|
|
207
|
+
target[key] = value;
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
function setInto(target, key, value) {
|
|
212
|
+
if (!(key in target)) {
|
|
213
|
+
target[key] = value;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
function isDomainSet(config, ...properties) {
|
|
217
|
+
return properties.some((prop) => {
|
|
218
|
+
if (prop.endsWith(".") || prop.endsWith(":")) {
|
|
219
|
+
return Object.keys(config).some((key) => key.startsWith(prop));
|
|
220
|
+
}
|
|
221
|
+
return prop in config;
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
function warnManualConfig(config) {
|
|
225
|
+
if (isDomainSet(config, "navigator.language", "navigator.languages", "headers.Accept-Language", "locale:")) {
|
|
226
|
+
LeakWarning.warn("locale", false);
|
|
227
|
+
}
|
|
228
|
+
if (isDomainSet(config, "geolocation:", "timezone")) {
|
|
229
|
+
LeakWarning.warn("geolocation", false);
|
|
230
|
+
}
|
|
231
|
+
if (isDomainSet(config, "headers.User-Agent")) {
|
|
232
|
+
LeakWarning.warn("header-ua", false);
|
|
233
|
+
}
|
|
234
|
+
if (isDomainSet(config, "navigator.")) {
|
|
235
|
+
LeakWarning.warn("navigator", false);
|
|
236
|
+
}
|
|
237
|
+
if (isDomainSet(config, "screen.", "window.", "document.body.")) {
|
|
238
|
+
LeakWarning.warn("viewport", false);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
const WINDOW_DIM_KEYS = [
|
|
242
|
+
"window.outerWidth",
|
|
243
|
+
"window.outerHeight",
|
|
244
|
+
"window.innerWidth",
|
|
245
|
+
"window.innerHeight",
|
|
246
|
+
"document.body.clientWidth",
|
|
247
|
+
"document.body.clientHeight",
|
|
248
|
+
];
|
|
249
|
+
export function spoofsWindowDimensions(fromOptions) {
|
|
250
|
+
const env = fromOptions.env ?? {};
|
|
251
|
+
const chunks = Object.entries(env)
|
|
252
|
+
.filter(([key]) => key.startsWith("CAMOU_CONFIG_"))
|
|
253
|
+
.map(([key, value]) => [Number(key.split("_").pop()), value])
|
|
254
|
+
.sort(([a], [b]) => a - b);
|
|
255
|
+
if (chunks.length === 0) {
|
|
256
|
+
return false;
|
|
257
|
+
}
|
|
258
|
+
const blob = chunks.map(([, value]) => value).join("");
|
|
259
|
+
return WINDOW_DIM_KEYS.some((key) => blob.includes(key));
|
|
260
|
+
}
|
|
261
|
+
export function attachNoViewportDefault(target) {
|
|
262
|
+
for (const name of ["newPage", "newContext"]) {
|
|
263
|
+
const original = target[name];
|
|
264
|
+
if (typeof original !== "function") {
|
|
265
|
+
continue;
|
|
266
|
+
}
|
|
267
|
+
target[name] = (options, ...rest) => original.call(target, options && "viewport" in options
|
|
268
|
+
? options
|
|
269
|
+
: { ...options, viewport: null }, ...rest);
|
|
270
|
+
}
|
|
271
|
+
return target;
|
|
272
|
+
}
|
|
273
|
+
export function syncAttachVD(browser, virtualDisplay) {
|
|
274
|
+
if (!virtualDisplay) {
|
|
275
|
+
return browser;
|
|
276
|
+
}
|
|
277
|
+
const originalClose = browser.close.bind(browser);
|
|
278
|
+
browser.close = async (...args) => {
|
|
279
|
+
try {
|
|
280
|
+
return await originalClose(...args);
|
|
281
|
+
}
|
|
282
|
+
finally {
|
|
283
|
+
if (virtualDisplay) {
|
|
284
|
+
virtualDisplay.kill();
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
browser._virtualDisplay = virtualDisplay;
|
|
289
|
+
return browser;
|
|
290
|
+
}
|
|
291
|
+
function getProxyUrl(proxy) {
|
|
292
|
+
if (!proxy)
|
|
293
|
+
return null;
|
|
294
|
+
if (typeof proxy === "string") {
|
|
295
|
+
return new URL(proxy);
|
|
296
|
+
}
|
|
297
|
+
const { server, username, password } = proxy;
|
|
298
|
+
let url;
|
|
299
|
+
try {
|
|
300
|
+
url = new URL(server);
|
|
301
|
+
if (!url.host || !url.protocol)
|
|
302
|
+
url = new URL(`http://${server}`);
|
|
303
|
+
}
|
|
304
|
+
catch (_e) {
|
|
305
|
+
url = new URL(`http://${server}`);
|
|
306
|
+
}
|
|
307
|
+
if (username)
|
|
308
|
+
url.username = username;
|
|
309
|
+
if (password)
|
|
310
|
+
url.password = password;
|
|
311
|
+
return url;
|
|
312
|
+
}
|
|
313
|
+
export async function launchOptions({ config, os, block_images, block_webrtc, block_webgl, disable_coop, webgl_config, geoip, humanize, locale, addons, fonts, custom_fonts_only, exclude_addons, screen, window, fingerprint, ff_version, headless, main_world_eval, executable_path, firefox_user_prefs, proxy, enable_cache, args, env, i_know_what_im_doing, debug, virtual_display, ...launch_options }) {
|
|
314
|
+
if (!config) {
|
|
315
|
+
config = {};
|
|
316
|
+
}
|
|
317
|
+
const headlessBoolean = headless ?? false;
|
|
318
|
+
if (!addons) {
|
|
319
|
+
addons = [];
|
|
320
|
+
}
|
|
321
|
+
if (!args) {
|
|
322
|
+
args = [];
|
|
323
|
+
}
|
|
324
|
+
if (!firefox_user_prefs) {
|
|
325
|
+
firefox_user_prefs = {};
|
|
326
|
+
}
|
|
327
|
+
if (custom_fonts_only === undefined) {
|
|
328
|
+
custom_fonts_only = false;
|
|
329
|
+
}
|
|
330
|
+
if (i_know_what_im_doing === undefined) {
|
|
331
|
+
i_know_what_im_doing = false;
|
|
332
|
+
}
|
|
333
|
+
if (!env) {
|
|
334
|
+
env = process.env;
|
|
335
|
+
}
|
|
336
|
+
if (typeof executable_path === "string") {
|
|
337
|
+
executable_path = path.resolve(executable_path);
|
|
338
|
+
}
|
|
339
|
+
if (virtual_display) {
|
|
340
|
+
env.DISPLAY = virtual_display;
|
|
341
|
+
}
|
|
342
|
+
if (!i_know_what_im_doing) {
|
|
343
|
+
warnManualConfig(config);
|
|
344
|
+
}
|
|
345
|
+
const operatingSystems = validateOS(os);
|
|
346
|
+
if (!operatingSystems && webgl_config) {
|
|
347
|
+
throw new Error("OS must be set when using webgl_config");
|
|
348
|
+
}
|
|
349
|
+
if (!executable_path &&
|
|
350
|
+
!getAsBooleanFromENV("PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD", false)) {
|
|
351
|
+
await ensureCamoufoxInstalled();
|
|
352
|
+
}
|
|
353
|
+
await addDefaultAddons(addons, exclude_addons);
|
|
354
|
+
if (addons.length > 0) {
|
|
355
|
+
confirmPaths(addons);
|
|
356
|
+
config.addons = addons;
|
|
357
|
+
}
|
|
358
|
+
let ff_version_str;
|
|
359
|
+
if (ff_version) {
|
|
360
|
+
ff_version_str = ff_version.toString();
|
|
361
|
+
LeakWarning.warn("ff_version", i_know_what_im_doing);
|
|
362
|
+
}
|
|
363
|
+
else {
|
|
364
|
+
ff_version_str = installedVerStr().split(".", 1)[0];
|
|
365
|
+
}
|
|
366
|
+
if (!fingerprint) {
|
|
367
|
+
fingerprint = generateFingerprint(window, {
|
|
368
|
+
screen: screen || getScreenCons(headlessBoolean || "DISPLAY" in env),
|
|
369
|
+
operatingSystems,
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
else {
|
|
373
|
+
if (!i_know_what_im_doing) {
|
|
374
|
+
checkCustomFingerprint(fingerprint);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
mergeInto(config, fromBrowserforge(fingerprint, ff_version_str));
|
|
378
|
+
const randint = (min, max) => {
|
|
379
|
+
const buf = new Uint32Array(1);
|
|
380
|
+
crypto.getRandomValues(buf);
|
|
381
|
+
return min + (buf[0] % (max - min + 1));
|
|
382
|
+
};
|
|
383
|
+
const knownProperties = loadProperties(executable_path);
|
|
384
|
+
for (const seed of ["fonts:spacing_seed", "audio:seed", "canvas:seed"]) {
|
|
385
|
+
if (seed in knownProperties) {
|
|
386
|
+
setInto(config, seed, randint(1, 4_294_967_295));
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
const targetOS = getTargetOS(config);
|
|
390
|
+
setInto(config, "window.history.length", weightedPick([1, 2, 3, 4, 5, 6], [40, 25, 15, 10, 6, 4]));
|
|
391
|
+
if (fonts) {
|
|
392
|
+
config.fonts = fonts;
|
|
393
|
+
}
|
|
394
|
+
if (custom_fonts_only) {
|
|
395
|
+
firefox_user_prefs["gfx.bundled-fonts.activate"] = 0;
|
|
396
|
+
if (fonts) {
|
|
397
|
+
LeakWarning.warn("custom_fonts_only");
|
|
398
|
+
}
|
|
399
|
+
else {
|
|
400
|
+
throw new Error("No custom fonts were passed, but `custom_fonts_only` is enabled.");
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
else {
|
|
404
|
+
updateFonts(config, targetOS);
|
|
405
|
+
}
|
|
406
|
+
const proxyUrl = getProxyUrl(proxy);
|
|
407
|
+
if (geoip) {
|
|
408
|
+
geoipAllowed();
|
|
409
|
+
if (typeof geoip !== "string") {
|
|
410
|
+
geoip = await publicIP(proxyUrl?.href);
|
|
411
|
+
}
|
|
412
|
+
if (!block_webrtc) {
|
|
413
|
+
if (validIPv4(geoip)) {
|
|
414
|
+
setInto(config, "webrtc:ipv4", geoip);
|
|
415
|
+
firefox_user_prefs["network.dns.disableIPv6"] = true;
|
|
416
|
+
}
|
|
417
|
+
else if (validIPv6(geoip)) {
|
|
418
|
+
setInto(config, "webrtc:ipv6", geoip);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
const geolocation = await getGeolocation(geoip);
|
|
422
|
+
config = { ...config, ...geolocation.asConfig() };
|
|
423
|
+
}
|
|
424
|
+
if (proxyUrl &&
|
|
425
|
+
!proxyUrl.hostname.includes("localhost") &&
|
|
426
|
+
!isDomainSet(config, "geolocation:")) {
|
|
427
|
+
LeakWarning.warn("proxy_without_geoip");
|
|
428
|
+
}
|
|
429
|
+
if (locale) {
|
|
430
|
+
handleLocales(locale, config);
|
|
431
|
+
}
|
|
432
|
+
if (humanize) {
|
|
433
|
+
setInto(config, "humanize", true);
|
|
434
|
+
if (typeof humanize === "number") {
|
|
435
|
+
setInto(config, "humanize:maxTime", humanize);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
if (main_world_eval) {
|
|
439
|
+
setInto(config, "allowMainWorld", true);
|
|
440
|
+
}
|
|
441
|
+
if (block_images) {
|
|
442
|
+
LeakWarning.warn("block_images", i_know_what_im_doing);
|
|
443
|
+
firefox_user_prefs["permissions.default.image"] = 2;
|
|
444
|
+
}
|
|
445
|
+
if (block_webrtc) {
|
|
446
|
+
firefox_user_prefs["media.peerconnection.enabled"] = false;
|
|
447
|
+
}
|
|
448
|
+
if (disable_coop) {
|
|
449
|
+
LeakWarning.warn("disable_coop", i_know_what_im_doing);
|
|
450
|
+
firefox_user_prefs["browser.tabs.remote.useCrossOriginOpenerPolicy"] =
|
|
451
|
+
false;
|
|
452
|
+
}
|
|
453
|
+
if (block_webgl || launch_options.allow_webgl === false) {
|
|
454
|
+
firefox_user_prefs["webgl.disabled"] = true;
|
|
455
|
+
LeakWarning.warn("block_webgl", i_know_what_im_doing);
|
|
456
|
+
}
|
|
457
|
+
else {
|
|
458
|
+
let webgl_fp;
|
|
459
|
+
if (webgl_config) {
|
|
460
|
+
webgl_fp = await sampleWebGL(targetOS, ...webgl_config);
|
|
461
|
+
}
|
|
462
|
+
else {
|
|
463
|
+
webgl_fp = await sampleWebGL(targetOS);
|
|
464
|
+
}
|
|
465
|
+
const { webGl2Enabled, ...webGlConfig } = webgl_fp;
|
|
466
|
+
mergeInto(config, webGlConfig);
|
|
467
|
+
mergeInto(firefox_user_prefs, {
|
|
468
|
+
"webgl.enable-webgl2": webGl2Enabled,
|
|
469
|
+
"webgl.force-enabled": true,
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
mergeInto(config, {
|
|
473
|
+
"canvas:aaOffset": cryptoRandInt(0, 100) - 50,
|
|
474
|
+
"canvas:aaCapOffset": true,
|
|
475
|
+
});
|
|
476
|
+
const dprPool = DPR_POOLS[targetOS] ?? DPR_POOLS.lin;
|
|
477
|
+
const dpr = weightedPick(dprPool.map(([v]) => v), dprPool.map(([, w]) => w));
|
|
478
|
+
setInto(config, "window.devicePixelRatio", dpr);
|
|
479
|
+
if (enable_cache) {
|
|
480
|
+
mergeInto(firefox_user_prefs, CACHE_PREFS);
|
|
481
|
+
}
|
|
482
|
+
if (debug) {
|
|
483
|
+
console.debug("[DEBUG] Config:");
|
|
484
|
+
console.debug(config);
|
|
485
|
+
}
|
|
486
|
+
validateConfig(config, knownProperties);
|
|
487
|
+
const env_vars = {
|
|
488
|
+
...getEnvVars(config, targetOS),
|
|
489
|
+
...env,
|
|
490
|
+
};
|
|
491
|
+
if (executable_path) {
|
|
492
|
+
executable_path = executable_path.toString();
|
|
493
|
+
}
|
|
494
|
+
else {
|
|
495
|
+
executable_path = launchPath();
|
|
496
|
+
}
|
|
497
|
+
const out = {
|
|
498
|
+
executablePath: executable_path,
|
|
499
|
+
args: args,
|
|
500
|
+
env: env_vars,
|
|
501
|
+
firefoxUserPrefs: firefox_user_prefs,
|
|
502
|
+
proxy: proxyUrl
|
|
503
|
+
? {
|
|
504
|
+
server: proxyUrl.origin,
|
|
505
|
+
username: proxyUrl.username,
|
|
506
|
+
password: proxyUrl.password,
|
|
507
|
+
bypass: typeof proxy === "string" ? undefined : proxy?.bypass,
|
|
508
|
+
}
|
|
509
|
+
: undefined,
|
|
510
|
+
headless: headlessBoolean,
|
|
511
|
+
...launch_options,
|
|
512
|
+
};
|
|
513
|
+
return out;
|
|
514
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare class VirtualDisplay {
|
|
2
|
+
private debug;
|
|
3
|
+
private proc;
|
|
4
|
+
private _display;
|
|
5
|
+
constructor(debug?: boolean);
|
|
6
|
+
private get xvfb_args();
|
|
7
|
+
private get xvfb_path();
|
|
8
|
+
private spawnXvfb;
|
|
9
|
+
get(): Promise<string>;
|
|
10
|
+
kill(): void;
|
|
11
|
+
private static assert_linux;
|
|
12
|
+
}
|