bexxcv 1.0.6 → 1.0.8
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 +39 -0
- package/dist/__main__.js +7 -0
- package/dist/data-files/data-version.json +7 -0
- package/dist/data-files/webgl_data.db +0 -0
- package/dist/doctor.d.ts +26 -0
- package/dist/doctor.js +149 -0
- package/dist/exceptions.d.ts +3 -0
- package/dist/exceptions.js +6 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/realism.d.ts +3 -0
- package/dist/realism.js +57 -0
- package/dist/schema.d.ts +1 -0
- package/dist/schema.js +171 -0
- package/dist/sync_api.js +4 -0
- package/dist/utils.js +9 -3
- package/package.json +9 -4
package/README.md
CHANGED
|
@@ -28,6 +28,7 @@ High-performance stealth Firefox automation built on top of [Camoufox](https://g
|
|
|
28
28
|
| Cloudflare UAM | Manual | `uam: true` — `page.goto()` waits until the challenge clears |
|
|
29
29
|
| Human behavior | Cursor movement only (`humanize`) | `createHuman(page)` — clicks, typing with typos, scrolling, idle drift |
|
|
30
30
|
| Launch speed | Sequential setup | Public IP lookup runs in parallel with the binary check; telemetry and update prefs off by default |
|
|
31
|
+
| Fingerprint coherence | `devicePixelRatio` picked independently of screen size | DPR is chosen so CSS size times DPR matches a real monitor resolution |
|
|
31
32
|
|
|
32
33
|
---
|
|
33
34
|
|
|
@@ -298,6 +299,43 @@ await human.idle(2000);
|
|
|
298
299
|
|
|
299
300
|
---
|
|
300
301
|
|
|
302
|
+
## Options validation
|
|
303
|
+
|
|
304
|
+
`bexxcv()` checks option types with [zod](https://zod.dev) before launching, so a wrong value fails early with a readable message.
|
|
305
|
+
|
|
306
|
+
```
|
|
307
|
+
InvalidOptions: Invalid bexxcv options:
|
|
308
|
+
turnstile: expected a boolean or { interval, retryAfter }, got the string "yes"
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
Unknown options that look like a typo of a known one only print a warning, for example `Unknown option "turnsltile", did you mean "turnstile"?`. Other unknown options are passed to Playwright untouched. Set `BEXXCV_NO_VALIDATE=1` to skip the check.
|
|
312
|
+
|
|
313
|
+
---
|
|
314
|
+
|
|
315
|
+
## Fingerprint coherence
|
|
316
|
+
|
|
317
|
+
- `devicePixelRatio` is chosen together with the screen size, so the physical resolution (CSS size times DPR) is one that real monitors have. A 1920x1080 screen can have DPR 1 or 2, but not 1.25.
|
|
318
|
+
- WebGL data keys are matched against the properties of the installed Camoufox build. If the bundled `webgl_data.db` uses different key names or keys the browser does not know, bexxcv raises a clear `UnknownProperty` error instead of silently leaking the host GPU.
|
|
319
|
+
|
|
320
|
+
---
|
|
321
|
+
|
|
322
|
+
## Data files and `doctor`
|
|
323
|
+
|
|
324
|
+
`npx bexxcv doctor` checks the bundled `webgl_data.db`: the number of usable rows per OS, the data keys, whether they match the installed browser, and how long ago the data was last stamped. A warning is also printed at launch when the data is older than 180 days. Set `BEXXCV_NO_DATA_CHECK=1` to silence it.
|
|
325
|
+
|
|
326
|
+
Refresh the data from the repository root:
|
|
327
|
+
|
|
328
|
+
```bash
|
|
329
|
+
node scripts/update-data.mjs --from /path/to/webgl_data.db
|
|
330
|
+
node scripts/update-data.mjs --npm camoufox-js
|
|
331
|
+
node scripts/update-data.mjs --stamp
|
|
332
|
+
node scripts/update-data.mjs --pin
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
`--from` and `--npm` validate the database before replacing it and refuse a database with far fewer rows unless `--force` is given. `--pin` compares `browser-pin.json` with the latest Camoufox release and only writes the change with `--write`. Test before releasing a new pin.
|
|
336
|
+
|
|
337
|
+
---
|
|
338
|
+
|
|
301
339
|
## Xvfb module
|
|
302
340
|
|
|
303
341
|
bexxcv exports all Xvfb utilities so you can manage virtual displays in your own code:
|
|
@@ -413,6 +451,7 @@ npx bexxcv version # Show installed version
|
|
|
413
451
|
npx bexxcv path # Print install directory
|
|
414
452
|
npx bexxcv test [url] # Open a test browser window
|
|
415
453
|
npx bexxcv server # Start a Playwright remote server
|
|
454
|
+
npx bexxcv doctor # Check the bundled WebGL data
|
|
416
455
|
```
|
|
417
456
|
|
|
418
457
|
---
|
package/dist/__main__.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { existsSync, rmSync } from "node:fs";
|
|
3
3
|
import { Command } from "commander";
|
|
4
4
|
import { DefaultAddons, maybeDownloadAddons } from "./addons.js";
|
|
5
|
+
import { doctor } from "./doctor.js";
|
|
5
6
|
import { ALLOW_GEOIP, downloadMMDB, removeMMDB } from "./locale.js";
|
|
6
7
|
import { CamoufoxFetcher, INSTALL_DIR, installedVerStr } from "./pkgman.js";
|
|
7
8
|
import { launchServer } from "./server.js";
|
|
@@ -126,6 +127,12 @@ program.command("version").action(async () => {
|
|
|
126
127
|
console.log("(Up to date!)");
|
|
127
128
|
}
|
|
128
129
|
});
|
|
130
|
+
program.command("doctor").action(async () => {
|
|
131
|
+
const report = await doctor();
|
|
132
|
+
for (const line of report.lines)
|
|
133
|
+
console.log(line);
|
|
134
|
+
process.exitCode = report.ok ? 0 : 1;
|
|
135
|
+
});
|
|
129
136
|
program.command("check-update").action(async () => {
|
|
130
137
|
console.log("Checking for bexxcv updates...");
|
|
131
138
|
try {
|
|
Binary file
|
package/dist/doctor.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export declare const DEFAULT_MAX_AGE_DAYS = 180;
|
|
2
|
+
export interface DataStamp {
|
|
3
|
+
updated: string;
|
|
4
|
+
rows?: number;
|
|
5
|
+
sha256?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface DataStatus {
|
|
8
|
+
exists: boolean;
|
|
9
|
+
bytes: number;
|
|
10
|
+
stamp: DataStamp | null;
|
|
11
|
+
ageDays: number | null;
|
|
12
|
+
stale: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare function readStamp(dir?: string): DataStamp | null;
|
|
15
|
+
export declare function dataStatus(options?: {
|
|
16
|
+
dir?: string;
|
|
17
|
+
maxAgeDays?: number;
|
|
18
|
+
}): DataStatus;
|
|
19
|
+
export declare function warnIfDataStale(maxAgeDays?: number): void;
|
|
20
|
+
export declare function doctor(options?: {
|
|
21
|
+
dir?: string;
|
|
22
|
+
maxAgeDays?: number;
|
|
23
|
+
}): Promise<{
|
|
24
|
+
ok: boolean;
|
|
25
|
+
lines: string[];
|
|
26
|
+
}>;
|
package/dist/doctor.js
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import * as fs from "node:fs";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { getPath } from "./pkgman.js";
|
|
6
|
+
import { reconcileWebglKeys } from "./realism.js";
|
|
7
|
+
const currentDir = import.meta.dirname ?? path.dirname(fileURLToPath(import.meta.url));
|
|
8
|
+
const DATA_DIR = path.join(currentDir, "data-files");
|
|
9
|
+
export const DEFAULT_MAX_AGE_DAYS = 180;
|
|
10
|
+
let warned = false;
|
|
11
|
+
function readProperties() {
|
|
12
|
+
try {
|
|
13
|
+
const list = JSON.parse(fs.readFileSync(getPath("properties.json"), "utf-8"));
|
|
14
|
+
return Object.fromEntries(list.map((p) => [p.property, p.type]));
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export function readStamp(dir = DATA_DIR) {
|
|
21
|
+
try {
|
|
22
|
+
const raw = JSON.parse(fs.readFileSync(path.join(dir, "data-version.json"), "utf-8"));
|
|
23
|
+
const stamp = raw?.webgl_data;
|
|
24
|
+
if (!stamp || typeof stamp.updated !== "string")
|
|
25
|
+
return null;
|
|
26
|
+
return stamp;
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export function dataStatus(options = {}) {
|
|
33
|
+
const dir = options.dir ?? DATA_DIR;
|
|
34
|
+
const maxAge = options.maxAgeDays ?? DEFAULT_MAX_AGE_DAYS;
|
|
35
|
+
const file = path.join(dir, "webgl_data.db");
|
|
36
|
+
let bytes = 0;
|
|
37
|
+
try {
|
|
38
|
+
bytes = fs.statSync(file).size;
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
bytes = 0;
|
|
42
|
+
}
|
|
43
|
+
const stamp = readStamp(dir);
|
|
44
|
+
let ageDays = null;
|
|
45
|
+
if (stamp) {
|
|
46
|
+
const time = Date.parse(stamp.updated);
|
|
47
|
+
if (!Number.isNaN(time)) {
|
|
48
|
+
ageDays = Math.floor((Date.now() - time) / 86_400_000);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
exists: bytes > 0,
|
|
53
|
+
bytes,
|
|
54
|
+
stamp,
|
|
55
|
+
ageDays,
|
|
56
|
+
stale: ageDays !== null && ageDays > maxAge,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
export function warnIfDataStale(maxAgeDays = DEFAULT_MAX_AGE_DAYS) {
|
|
60
|
+
if (warned || process.env.BEXXCV_NO_DATA_CHECK)
|
|
61
|
+
return;
|
|
62
|
+
const status = dataStatus({ maxAgeDays });
|
|
63
|
+
if (!status.stale)
|
|
64
|
+
return;
|
|
65
|
+
warned = true;
|
|
66
|
+
console.warn(`[bexxcv] WebGL data is ${status.ageDays} days old. Run "npx bexxcv doctor" to check it.`);
|
|
67
|
+
}
|
|
68
|
+
export async function doctor(options = {}) {
|
|
69
|
+
const dir = options.dir ?? DATA_DIR;
|
|
70
|
+
const status = dataStatus(options);
|
|
71
|
+
const lines = [];
|
|
72
|
+
let ok = true;
|
|
73
|
+
if (!status.exists) {
|
|
74
|
+
lines.push("webgl_data.db: missing or empty");
|
|
75
|
+
return { ok: false, lines };
|
|
76
|
+
}
|
|
77
|
+
lines.push(`webgl_data.db: ${status.bytes} bytes`);
|
|
78
|
+
try {
|
|
79
|
+
const { default: Database } = await import("better-sqlite3");
|
|
80
|
+
const db = new Database(path.join(dir, "webgl_data.db"), {
|
|
81
|
+
readonly: true,
|
|
82
|
+
fileMustExist: true,
|
|
83
|
+
});
|
|
84
|
+
try {
|
|
85
|
+
const counts = ["win", "mac", "lin"].map((os) => {
|
|
86
|
+
const row = db
|
|
87
|
+
.prepare(`SELECT COUNT(*) AS n FROM webgl_fingerprints WHERE ${os} > 0`)
|
|
88
|
+
.get();
|
|
89
|
+
return `${os}=${row.n}`;
|
|
90
|
+
});
|
|
91
|
+
lines.push(`webgl_fingerprints rows with data: ${counts.join(" ")}`);
|
|
92
|
+
if (counts.some((c) => c.endsWith("=0")))
|
|
93
|
+
ok = false;
|
|
94
|
+
const sample = db
|
|
95
|
+
.prepare("SELECT data FROM webgl_fingerprints LIMIT 1")
|
|
96
|
+
.get();
|
|
97
|
+
if (sample) {
|
|
98
|
+
const keys = Object.keys(JSON.parse(sample.data));
|
|
99
|
+
lines.push(`data keys: ${keys.join(", ")}`);
|
|
100
|
+
if (keys.length <= 3) {
|
|
101
|
+
ok = false;
|
|
102
|
+
lines.push("the database only holds vendor and renderer, other WebGL values would come from the host GPU");
|
|
103
|
+
}
|
|
104
|
+
const props = readProperties();
|
|
105
|
+
if (props) {
|
|
106
|
+
try {
|
|
107
|
+
const { webGl2Enabled: _skip, ...rest } = JSON.parse(sample.data);
|
|
108
|
+
reconcileWebglKeys(rest, props);
|
|
109
|
+
lines.push("data keys match the installed Camoufox build");
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
ok = false;
|
|
113
|
+
lines.push(error.message);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
lines.push("properties.json not found, browser not installed yet");
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
finally {
|
|
122
|
+
db.close();
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
ok = false;
|
|
127
|
+
lines.push(`webgl_fingerprints: cannot read (${error.message})`);
|
|
128
|
+
}
|
|
129
|
+
if (!status.stamp) {
|
|
130
|
+
lines.push("data-version.json: missing, run scripts/update-data.mjs --stamp");
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
const actual = createHash("sha256")
|
|
134
|
+
.update(fs.readFileSync(path.join(dir, "webgl_data.db")))
|
|
135
|
+
.digest("hex");
|
|
136
|
+
if (status.stamp.sha256 && status.stamp.sha256 !== actual) {
|
|
137
|
+
ok = false;
|
|
138
|
+
lines.push("data-version.json: sha256 does not match webgl_data.db");
|
|
139
|
+
}
|
|
140
|
+
lines.push(`last stamped: ${status.stamp.updated} (${status.ageDays} days ago)`);
|
|
141
|
+
if (status.stale) {
|
|
142
|
+
ok = false;
|
|
143
|
+
lines.push("status: stale, refresh with scripts/update-data.mjs");
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (ok)
|
|
147
|
+
lines.push("status: ok");
|
|
148
|
+
return { ok, lines };
|
|
149
|
+
}
|
package/dist/exceptions.d.ts
CHANGED
package/dist/exceptions.js
CHANGED
|
@@ -157,3 +157,9 @@ export class FileNotFoundError extends Error {
|
|
|
157
157
|
this.name = "FileNotFoundError";
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
|
+
export class InvalidOptions extends Error {
|
|
161
|
+
constructor(message) {
|
|
162
|
+
super(message ?? "One or more options are invalid.");
|
|
163
|
+
this.name = "InvalidOptions";
|
|
164
|
+
}
|
|
165
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -7,3 +7,5 @@ export { checkSelfUpdate, applySelfUpdate, type SelfUpdateInfo } from "./selfupd
|
|
|
7
7
|
export { createHuman, Human, type HumanClickOptions, type HumanOptions, type HumanPage, } from "./human.js";
|
|
8
8
|
export { attachTurnstile, watchTurnstile, type TurnstileOptions, } from "./turnstile.js";
|
|
9
9
|
export { attachUam, waitForUam, watchUam, type UamOptions, type UamResult } from "./uam.js";
|
|
10
|
+
export { dataStatus, doctor, type DataStatus } from "./doctor.js";
|
|
11
|
+
export { validateOptions } from "./schema.js";
|
package/dist/index.js
CHANGED
|
@@ -7,3 +7,5 @@ export { checkSelfUpdate, applySelfUpdate } from "./selfupdate.js";
|
|
|
7
7
|
export { createHuman, Human, } from "./human.js";
|
|
8
8
|
export { attachTurnstile, watchTurnstile, } from "./turnstile.js";
|
|
9
9
|
export { attachUam, waitForUam, watchUam } from "./uam.js";
|
|
10
|
+
export { dataStatus, doctor } from "./doctor.js";
|
|
11
|
+
export { validateOptions } from "./schema.js";
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare function isKnownPhysical(width: number, height: number): boolean;
|
|
2
|
+
export declare function coherentDprWeights(pool: [number, number][], width: number, height: number): [number[], number[]];
|
|
3
|
+
export declare function reconcileWebglKeys(data: Record<string, unknown>, known: Record<string, string>): Record<string, unknown>;
|
package/dist/realism.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { UnknownProperty } from "./exceptions.js";
|
|
2
|
+
const KNOWN_PHYSICAL = new Set([
|
|
3
|
+
"1280x720",
|
|
4
|
+
"1280x800",
|
|
5
|
+
"1366x768",
|
|
6
|
+
"1440x900",
|
|
7
|
+
"1536x864",
|
|
8
|
+
"1600x900",
|
|
9
|
+
"1680x1050",
|
|
10
|
+
"1920x1080",
|
|
11
|
+
"1920x1200",
|
|
12
|
+
"2048x1152",
|
|
13
|
+
"2256x1504",
|
|
14
|
+
"2304x1440",
|
|
15
|
+
"2560x1080",
|
|
16
|
+
"2560x1440",
|
|
17
|
+
"2560x1600",
|
|
18
|
+
"2880x1620",
|
|
19
|
+
"2880x1800",
|
|
20
|
+
"2940x1912",
|
|
21
|
+
"3000x2000",
|
|
22
|
+
"3024x1964",
|
|
23
|
+
"3440x1440",
|
|
24
|
+
"3456x2234",
|
|
25
|
+
"3840x2160",
|
|
26
|
+
"3840x2400",
|
|
27
|
+
"5120x2880",
|
|
28
|
+
]);
|
|
29
|
+
export function isKnownPhysical(width, height) {
|
|
30
|
+
return KNOWN_PHYSICAL.has(`${Math.round(width)}x${Math.round(height)}`);
|
|
31
|
+
}
|
|
32
|
+
export function coherentDprWeights(pool, width, height) {
|
|
33
|
+
const values = pool.map(([value]) => value);
|
|
34
|
+
const weights = pool.map(([value, weight]) => isKnownPhysical(width * value, height * value) ? weight : weight * 0.02);
|
|
35
|
+
return [values, weights];
|
|
36
|
+
}
|
|
37
|
+
const WEBGL_ALIASES = [
|
|
38
|
+
["webglVendor", "webGl:vendor"],
|
|
39
|
+
["webglRenderer", "webGl:renderer"],
|
|
40
|
+
];
|
|
41
|
+
export function reconcileWebglKeys(data, known) {
|
|
42
|
+
const out = {};
|
|
43
|
+
for (const [key, value] of Object.entries(data)) {
|
|
44
|
+
if (known[key]) {
|
|
45
|
+
out[key] = value;
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
const pair = WEBGL_ALIASES.find(([a, b]) => a === key || b === key);
|
|
49
|
+
const other = pair ? (pair[0] === key ? pair[1] : pair[0]) : null;
|
|
50
|
+
if (other && known[other]) {
|
|
51
|
+
out[other] = value;
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
throw new UnknownProperty(`WebGL data key "${key}" is not supported by the installed Camoufox build. The webgl_data.db in use does not match this browser version. Run "npx bexxcv doctor" for details.`);
|
|
55
|
+
}
|
|
56
|
+
return out;
|
|
57
|
+
}
|
package/dist/schema.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function validateOptions(options: Record<string, unknown> | undefined): void;
|
package/dist/schema.js
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { InvalidOptions } from "./exceptions.js";
|
|
3
|
+
const osName = z.enum(["linux", "macos", "windows"]);
|
|
4
|
+
const stringOrList = z.union([z.string(), z.array(z.string())]);
|
|
5
|
+
const positive = z.number().positive();
|
|
6
|
+
const SPEC = {
|
|
7
|
+
os: [z.union([osName, z.array(osName)]), '"linux", "macos", "windows" or an array of them'],
|
|
8
|
+
block_images: [z.boolean(), "a boolean"],
|
|
9
|
+
block_webrtc: [z.boolean(), "a boolean"],
|
|
10
|
+
block_webgl: [z.boolean(), "a boolean"],
|
|
11
|
+
disable_coop: [z.boolean(), "a boolean"],
|
|
12
|
+
geoip: [z.union([z.string().min(1), z.boolean()]), "a boolean or an IP string"],
|
|
13
|
+
humanize: [z.union([z.boolean(), positive]), "a boolean or a number of seconds"],
|
|
14
|
+
locale: [stringOrList, "a locale string or an array of locale strings"],
|
|
15
|
+
addons: [z.array(z.string()), "an array of strings"],
|
|
16
|
+
fonts: [z.array(z.string()), "an array of strings"],
|
|
17
|
+
custom_fonts_only: [z.boolean(), "a boolean"],
|
|
18
|
+
exclude_addons: [z.array(z.string()), "an array of strings"],
|
|
19
|
+
screen: [
|
|
20
|
+
z.object({
|
|
21
|
+
minWidth: z.number().optional(),
|
|
22
|
+
maxWidth: z.number().optional(),
|
|
23
|
+
minHeight: z.number().optional(),
|
|
24
|
+
maxHeight: z.number().optional(),
|
|
25
|
+
}),
|
|
26
|
+
"an object like { maxWidth, maxHeight }",
|
|
27
|
+
],
|
|
28
|
+
window: [z.tuple([positive, positive]), "a [width, height] pair"],
|
|
29
|
+
fingerprint: [
|
|
30
|
+
z.custom((v) => typeof v === "object" && v !== null && !Array.isArray(v)),
|
|
31
|
+
"a fingerprint object",
|
|
32
|
+
],
|
|
33
|
+
ff_version: [z.number().int().positive(), "a positive integer"],
|
|
34
|
+
headless: [z.union([z.boolean(), z.literal("virtual")]), 'true, false or "virtual"'],
|
|
35
|
+
main_world_eval: [z.boolean(), "a boolean"],
|
|
36
|
+
executable_path: [
|
|
37
|
+
z.union([z.string().min(1), z.instanceof(URL), z.instanceof(Uint8Array)]),
|
|
38
|
+
"a path string",
|
|
39
|
+
],
|
|
40
|
+
firefox_user_prefs: [z.record(z.string(), z.any()), "an object of Firefox prefs"],
|
|
41
|
+
proxy: [
|
|
42
|
+
z.union([
|
|
43
|
+
z.string().min(1),
|
|
44
|
+
z.object({
|
|
45
|
+
server: z.string().min(1),
|
|
46
|
+
username: z.string().optional(),
|
|
47
|
+
password: z.string().optional(),
|
|
48
|
+
bypass: z.string().optional(),
|
|
49
|
+
}),
|
|
50
|
+
]),
|
|
51
|
+
"a proxy URL string or { server, username, password, bypass }",
|
|
52
|
+
],
|
|
53
|
+
enable_cache: [z.boolean(), "a boolean"],
|
|
54
|
+
args: [z.array(z.string()), "an array of strings"],
|
|
55
|
+
env: [
|
|
56
|
+
z.record(z.string(), z.union([z.string(), z.number(), z.boolean()])),
|
|
57
|
+
"an object of environment variables",
|
|
58
|
+
],
|
|
59
|
+
debug: [z.boolean(), "a boolean"],
|
|
60
|
+
virtual_display: [z.string(), "a display string such as :99"],
|
|
61
|
+
webgl_config: [z.tuple([z.string(), z.string()]), "a [vendor, renderer] pair"],
|
|
62
|
+
i_know_what_im_doing: [z.boolean(), "a boolean"],
|
|
63
|
+
config: [
|
|
64
|
+
z.custom((v) => typeof v === "object" && v !== null && !Array.isArray(v)),
|
|
65
|
+
"an object",
|
|
66
|
+
],
|
|
67
|
+
user_data_dir: [z.string().min(1), "a directory path"],
|
|
68
|
+
auto_xvfb: [z.boolean(), "a boolean"],
|
|
69
|
+
turnstile: [
|
|
70
|
+
z.union([
|
|
71
|
+
z.boolean(),
|
|
72
|
+
z.object({ interval: positive.optional(), retryAfter: positive.optional() }),
|
|
73
|
+
]),
|
|
74
|
+
"a boolean or { interval, retryAfter }",
|
|
75
|
+
],
|
|
76
|
+
uam: [
|
|
77
|
+
z.union([
|
|
78
|
+
z.boolean(),
|
|
79
|
+
z.object({
|
|
80
|
+
timeout: positive.optional(),
|
|
81
|
+
interval: positive.optional(),
|
|
82
|
+
waitOnGoto: z.boolean().optional(),
|
|
83
|
+
}),
|
|
84
|
+
]),
|
|
85
|
+
"a boolean or { timeout, interval, waitOnGoto }",
|
|
86
|
+
],
|
|
87
|
+
};
|
|
88
|
+
const PASSTHROUGH = new Set([
|
|
89
|
+
"allow_webgl",
|
|
90
|
+
"channel",
|
|
91
|
+
"chromiumSandbox",
|
|
92
|
+
"devtools",
|
|
93
|
+
"downloadsPath",
|
|
94
|
+
"executablePath",
|
|
95
|
+
"firefoxUserPrefs",
|
|
96
|
+
"handleSIGHUP",
|
|
97
|
+
"handleSIGINT",
|
|
98
|
+
"handleSIGTERM",
|
|
99
|
+
"ignoreDefaultArgs",
|
|
100
|
+
"logger",
|
|
101
|
+
"slowMo",
|
|
102
|
+
"timeout",
|
|
103
|
+
"tracesDir",
|
|
104
|
+
]);
|
|
105
|
+
const WARNED = new Set();
|
|
106
|
+
function distance(a, b) {
|
|
107
|
+
const prev = Array.from({ length: b.length + 1 }, (_, i) => i);
|
|
108
|
+
for (let i = 1; i <= a.length; i++) {
|
|
109
|
+
let diag = prev[0];
|
|
110
|
+
prev[0] = i;
|
|
111
|
+
for (let j = 1; j <= b.length; j++) {
|
|
112
|
+
const next = prev[j];
|
|
113
|
+
prev[j] = Math.min(prev[j] + 1, prev[j - 1] + 1, diag + (a[i - 1] === b[j - 1] ? 0 : 1));
|
|
114
|
+
diag = next;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return prev[b.length];
|
|
118
|
+
}
|
|
119
|
+
function closestKey(key) {
|
|
120
|
+
if (key.length < 4)
|
|
121
|
+
return null;
|
|
122
|
+
const lower = key.toLowerCase();
|
|
123
|
+
let best = null;
|
|
124
|
+
let bestDistance = 3;
|
|
125
|
+
for (const candidate of Object.keys(SPEC)) {
|
|
126
|
+
const d = distance(lower, candidate.toLowerCase());
|
|
127
|
+
if (d < bestDistance) {
|
|
128
|
+
bestDistance = d;
|
|
129
|
+
best = candidate;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return best;
|
|
133
|
+
}
|
|
134
|
+
function describe(value) {
|
|
135
|
+
if (value === null)
|
|
136
|
+
return "null";
|
|
137
|
+
if (Array.isArray(value))
|
|
138
|
+
return "an array";
|
|
139
|
+
if (typeof value === "string") {
|
|
140
|
+
return `the string "${value.length > 24 ? `${value.slice(0, 24)}...` : value}"`;
|
|
141
|
+
}
|
|
142
|
+
if (typeof value === "object")
|
|
143
|
+
return "an object";
|
|
144
|
+
return `${typeof value} ${String(value)}`;
|
|
145
|
+
}
|
|
146
|
+
export function validateOptions(options) {
|
|
147
|
+
if (!options || process.env.BEXXCV_NO_VALIDATE)
|
|
148
|
+
return;
|
|
149
|
+
const problems = [];
|
|
150
|
+
for (const [key, value] of Object.entries(options)) {
|
|
151
|
+
if (value === undefined)
|
|
152
|
+
continue;
|
|
153
|
+
const spec = SPEC[key];
|
|
154
|
+
if (spec) {
|
|
155
|
+
if (!spec[0].safeParse(value).success) {
|
|
156
|
+
problems.push(`${key}: expected ${spec[1]}, got ${describe(value)}`);
|
|
157
|
+
}
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
if (PASSTHROUGH.has(key) || WARNED.has(key))
|
|
161
|
+
continue;
|
|
162
|
+
const hint = closestKey(key);
|
|
163
|
+
if (hint) {
|
|
164
|
+
WARNED.add(key);
|
|
165
|
+
console.warn(`[bexxcv] Unknown option "${key}", did you mean "${hint}"?`);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
if (problems.length > 0) {
|
|
169
|
+
throw new InvalidOptions(`Invalid bexxcv options:\n ${problems.join("\n ")}`);
|
|
170
|
+
}
|
|
171
|
+
}
|
package/dist/sync_api.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { firefox, } from "playwright-core";
|
|
2
2
|
import { attachNoViewportDefault, launchOptions, spoofsWindowDimensions, syncAttachVD, } from "./utils.js";
|
|
3
|
+
import { warnIfDataStale } from "./doctor.js";
|
|
4
|
+
import { validateOptions } from "./schema.js";
|
|
3
5
|
import { attachTurnstile } from "./turnstile.js";
|
|
4
6
|
import { attachUam } from "./uam.js";
|
|
5
7
|
import { VirtualDisplay } from "./virtdisplay.js";
|
|
6
8
|
import { needsXvfb } from "./xvfb.js";
|
|
7
9
|
export async function Bexxcv(launch_options = {}) {
|
|
10
|
+
validateOptions(launch_options);
|
|
11
|
+
warnIfDataStale();
|
|
8
12
|
const { headless, user_data_dir, auto_xvfb = true, turnstile = false, uam = false, ...opts } = launch_options;
|
|
9
13
|
const needsDisplay = auto_xvfb && needsXvfb();
|
|
10
14
|
const effectiveHeadless = (() => {
|
package/dist/utils.js
CHANGED
|
@@ -6,6 +6,7 @@ import { addDefaultAddons, confirmPaths, } from "./addons.js";
|
|
|
6
6
|
import { InvalidOS, InvalidPropertyType, NonFirefoxFingerprint, UnknownProperty, } from "./exceptions.js";
|
|
7
7
|
import { fromBrowserforge, generateFingerprint, SUPPORTED_OS, } from "./fingerprints.js";
|
|
8
8
|
import { publicIP, validIPv4, validIPv6 } from "./ip.js";
|
|
9
|
+
import { coherentDprWeights, reconcileWebglKeys } from "./realism.js";
|
|
9
10
|
import { geoipAllowed, getGeolocation, handleLocales } from "./locale.js";
|
|
10
11
|
import FONTS from "./mappings/fonts.config.js";
|
|
11
12
|
import { ensureCamoufoxInstalled, getPath, installedVerStr, launchPath, OS_NAME, } from "./pkgman.js";
|
|
@@ -481,9 +482,9 @@ export async function launchOptions({ config, os, block_images, block_webrtc, bl
|
|
|
481
482
|
webgl_fp = await sampleWebGL(targetOS);
|
|
482
483
|
}
|
|
483
484
|
const { webGl2Enabled, ...webGlConfig } = webgl_fp;
|
|
484
|
-
mergeInto(config, webGlConfig);
|
|
485
|
+
mergeInto(config, reconcileWebglKeys(webGlConfig, knownProperties));
|
|
485
486
|
mergeInto(firefox_user_prefs, {
|
|
486
|
-
"webgl.enable-webgl2": webGl2Enabled,
|
|
487
|
+
"webgl.enable-webgl2": webGl2Enabled ?? true,
|
|
487
488
|
"webgl.force-enabled": true,
|
|
488
489
|
});
|
|
489
490
|
}
|
|
@@ -492,7 +493,12 @@ export async function launchOptions({ config, os, block_images, block_webrtc, bl
|
|
|
492
493
|
"canvas:aaCapOffset": true,
|
|
493
494
|
});
|
|
494
495
|
const dprPool = DPR_POOLS[targetOS] ?? DPR_POOLS.lin;
|
|
495
|
-
const
|
|
496
|
+
const screenW = Number(config["screen.width"]);
|
|
497
|
+
const screenH = Number(config["screen.height"]);
|
|
498
|
+
const [dprValues, dprWeights] = screenW > 0 && screenH > 0
|
|
499
|
+
? coherentDprWeights(dprPool, screenW, screenH)
|
|
500
|
+
: [dprPool.map(([v]) => v), dprPool.map(([, w]) => w)];
|
|
501
|
+
const dpr = weightedPick(dprValues, dprWeights);
|
|
496
502
|
setInto(config, "window.devicePixelRatio", dpr);
|
|
497
503
|
if (enable_cache) {
|
|
498
504
|
mergeInto(firefox_user_prefs, CACHE_PREFS);
|
package/package.json
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bexxcv",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "rimraf dist && tsc && pnpm copy-files",
|
|
8
|
-
"
|
|
8
|
+
"gen-webgl": "node scripts/gen-webgl.cjs",
|
|
9
9
|
"copy-files": "cp -r src/data-files dist/data-files",
|
|
10
|
+
"test": "vitest",
|
|
10
11
|
"check": "biome check",
|
|
11
|
-
"fetch": "node dist/__main__.js fetch"
|
|
12
|
+
"fetch": "node dist/__main__.js fetch",
|
|
13
|
+
"prepublishOnly": "pnpm build",
|
|
14
|
+
"update-data": "node scripts/update-data.mjs",
|
|
15
|
+
"doctor": "node dist/__main__.js doctor"
|
|
12
16
|
},
|
|
13
17
|
"bin": "dist/__main__.js",
|
|
14
18
|
"files": [
|
|
@@ -49,7 +53,8 @@
|
|
|
49
53
|
"maxmind": "^5.0.0",
|
|
50
54
|
"pretty-bytes": "^7.1.0",
|
|
51
55
|
"ua-parser-js": "^2.0.10",
|
|
52
|
-
"xml2js": "^0.6.2"
|
|
56
|
+
"xml2js": "^0.6.2",
|
|
57
|
+
"zod": "^4.6.7"
|
|
53
58
|
},
|
|
54
59
|
"devDependencies": {
|
|
55
60
|
"@biomejs/biome": "2.4.10",
|