bexxcv 1.0.7 → 1.0.9
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 +81 -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 +4 -0
- package/dist/index.js +4 -0
- package/dist/pagehooks.d.ts +6 -0
- package/dist/pagehooks.js +19 -0
- package/dist/plugins/brake.d.ts +8 -0
- package/dist/plugins/brake.js +74 -0
- package/dist/plugins/cocoon.d.ts +5 -0
- package/dist/plugins/cocoon.js +17 -0
- package/dist/plugins/dodge.d.ts +21 -0
- package/dist/plugins/dodge.js +102 -0
- package/dist/plugins/gauntlet.d.ts +20 -0
- package/dist/plugins/gauntlet.js +119 -0
- package/dist/plugins/index.d.ts +27 -0
- package/dist/plugins/index.js +55 -0
- package/dist/plugins/lens.d.ts +20 -0
- package/dist/plugins/lens.js +89 -0
- package/dist/plugins/stash.d.ts +8 -0
- package/dist/plugins/stash.js +108 -0
- package/dist/plugins/types.d.ts +13 -0
- package/dist/plugins/types.js +49 -0
- package/dist/plugins/veneer.d.ts +5 -0
- package/dist/plugins/veneer.js +37 -0
- package/dist/plugins/wiretap.d.ts +26 -0
- package/dist/plugins/wiretap.js +123 -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 +256 -0
- package/dist/sync_api.d.ts +3 -1
- package/dist/sync_api.js +13 -1
- package/dist/turnstile.d.ts +12 -0
- package/dist/turnstile.js +70 -13
- package/dist/uam.d.ts +4 -0
- package/dist/uam.js +32 -6
- package/dist/utils.js +9 -3
- package/package.json +13 -10
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
const SENSITIVE = new Set([
|
|
4
|
+
"cookie",
|
|
5
|
+
"set-cookie",
|
|
6
|
+
"authorization",
|
|
7
|
+
"proxy-authorization",
|
|
8
|
+
"x-api-key",
|
|
9
|
+
]);
|
|
10
|
+
const STORES = new WeakMap();
|
|
11
|
+
export function wiretapEntries(context) {
|
|
12
|
+
return STORES.get(context) ?? [];
|
|
13
|
+
}
|
|
14
|
+
function scrub(headers, redact) {
|
|
15
|
+
if (!redact)
|
|
16
|
+
return { ...headers };
|
|
17
|
+
const out = {};
|
|
18
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
19
|
+
out[key] = SENSITIVE.has(key.toLowerCase()) ? "[redacted]" : value;
|
|
20
|
+
}
|
|
21
|
+
return out;
|
|
22
|
+
}
|
|
23
|
+
function matcher(patterns) {
|
|
24
|
+
if (!patterns || patterns.length === 0)
|
|
25
|
+
return () => true;
|
|
26
|
+
const tests = patterns.map((pattern) => {
|
|
27
|
+
if (pattern.startsWith("re:")) {
|
|
28
|
+
const re = new RegExp(pattern.slice(3));
|
|
29
|
+
return (url) => re.test(url);
|
|
30
|
+
}
|
|
31
|
+
return (url) => url.includes(pattern);
|
|
32
|
+
});
|
|
33
|
+
return (url) => tests.some((test) => test(url));
|
|
34
|
+
}
|
|
35
|
+
function withTimeout(promise, ms) {
|
|
36
|
+
return new Promise((resolve, reject) => {
|
|
37
|
+
const timer = setTimeout(() => reject(new Error("timeout")), ms);
|
|
38
|
+
promise.then((value) => {
|
|
39
|
+
clearTimeout(timer);
|
|
40
|
+
resolve(value);
|
|
41
|
+
}, (error) => {
|
|
42
|
+
clearTimeout(timer);
|
|
43
|
+
reject(error);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
export function wiretap(options = {}) {
|
|
48
|
+
const match = matcher(options.match);
|
|
49
|
+
const methods = new Set((options.methods ?? []).map((m) => m.toUpperCase()));
|
|
50
|
+
const redact = options.redact ?? true;
|
|
51
|
+
const bodies = options.bodies ?? true;
|
|
52
|
+
const maxBytes = options.maxBodyBytes ?? 1_000_000;
|
|
53
|
+
const streamTimeout = options.streamTimeout ?? 60_000;
|
|
54
|
+
const pending = new Set();
|
|
55
|
+
const capture = async (response, list) => {
|
|
56
|
+
const request = response.request();
|
|
57
|
+
if (methods.size > 0 && !methods.has(request.method()))
|
|
58
|
+
return;
|
|
59
|
+
const url = response.url();
|
|
60
|
+
if (!match(url))
|
|
61
|
+
return;
|
|
62
|
+
const responseHeaders = response.headers();
|
|
63
|
+
const contentType = responseHeaders["content-type"] ?? "";
|
|
64
|
+
const entry = {
|
|
65
|
+
time: new Date().toISOString(),
|
|
66
|
+
method: request.method(),
|
|
67
|
+
url,
|
|
68
|
+
status: response.status(),
|
|
69
|
+
requestHeaders: scrub(request.headers(), redact),
|
|
70
|
+
postData: request.postData(),
|
|
71
|
+
responseHeaders: scrub(responseHeaders, redact),
|
|
72
|
+
contentType,
|
|
73
|
+
body: null,
|
|
74
|
+
};
|
|
75
|
+
if (bodies) {
|
|
76
|
+
const stream = /event-stream/i.test(contentType);
|
|
77
|
+
try {
|
|
78
|
+
const text = await withTimeout(response.text(), stream ? streamTimeout : 10_000);
|
|
79
|
+
if (Buffer.byteLength(text) > maxBytes) {
|
|
80
|
+
entry.body = text.slice(0, maxBytes);
|
|
81
|
+
entry.bodyNote = "truncated";
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
entry.body = text;
|
|
85
|
+
}
|
|
86
|
+
if (stream) {
|
|
87
|
+
entry.events = text
|
|
88
|
+
.split(/\r?\n\r?\n/)
|
|
89
|
+
.map((chunk) => chunk.trim())
|
|
90
|
+
.filter(Boolean);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
entry.bodyNote = error.message;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
list.push(entry);
|
|
98
|
+
};
|
|
99
|
+
const save = async (contexts) => {
|
|
100
|
+
if (!options.out)
|
|
101
|
+
return;
|
|
102
|
+
await Promise.allSettled([...pending]);
|
|
103
|
+
const entries = contexts.flatMap((context) => wiretapEntries(context));
|
|
104
|
+
entries.sort((a, b) => a.time.localeCompare(b.time));
|
|
105
|
+
fs.mkdirSync(path.dirname(path.resolve(options.out)), { recursive: true });
|
|
106
|
+
fs.writeFileSync(options.out, `${JSON.stringify({ captured: entries.length, entries }, null, 2)}\n`, { mode: 0o600 });
|
|
107
|
+
};
|
|
108
|
+
return {
|
|
109
|
+
name: "wiretap",
|
|
110
|
+
order: 30,
|
|
111
|
+
onContext(context) {
|
|
112
|
+
const list = [];
|
|
113
|
+
STORES.set(context, list);
|
|
114
|
+
context.on("response", (response) => {
|
|
115
|
+
const task = capture(response, list)
|
|
116
|
+
.catch(() => undefined)
|
|
117
|
+
.finally(() => pending.delete(task));
|
|
118
|
+
pending.add(task);
|
|
119
|
+
});
|
|
120
|
+
},
|
|
121
|
+
beforeClose: save,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
@@ -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,256 @@
|
|
|
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
|
+
gauntlet: [
|
|
77
|
+
z.union([
|
|
78
|
+
z.boolean(),
|
|
79
|
+
z.object({
|
|
80
|
+
solve: z.array(z.enum(["uam", "turnstile"])).optional(),
|
|
81
|
+
maxTries: z.number().int().positive().optional(),
|
|
82
|
+
timeout: positive.optional(),
|
|
83
|
+
sustain: z.number().nonnegative().optional(),
|
|
84
|
+
}),
|
|
85
|
+
]),
|
|
86
|
+
'a boolean or { solve: ["uam", "turnstile"], maxTries, timeout, sustain }',
|
|
87
|
+
],
|
|
88
|
+
wiretap: [
|
|
89
|
+
z.union([
|
|
90
|
+
z.boolean(),
|
|
91
|
+
z.object({
|
|
92
|
+
match: z.array(z.string()).optional(),
|
|
93
|
+
methods: z.array(z.string()).optional(),
|
|
94
|
+
out: z.string().min(1).optional(),
|
|
95
|
+
bodies: z.boolean().optional(),
|
|
96
|
+
maxBodyBytes: positive.optional(),
|
|
97
|
+
streamTimeout: positive.optional(),
|
|
98
|
+
redact: z.boolean().optional(),
|
|
99
|
+
}),
|
|
100
|
+
]),
|
|
101
|
+
"a boolean or { match, methods, out, bodies, maxBodyBytes, streamTimeout, redact }",
|
|
102
|
+
],
|
|
103
|
+
stash: [
|
|
104
|
+
z.union([
|
|
105
|
+
z.string().min(1),
|
|
106
|
+
z.object({
|
|
107
|
+
file: z.string().min(1),
|
|
108
|
+
names: z.array(z.string()).optional(),
|
|
109
|
+
domains: z.array(z.string()).optional(),
|
|
110
|
+
saveEvery: positive.optional(),
|
|
111
|
+
}),
|
|
112
|
+
]),
|
|
113
|
+
"a file path or { file, names, domains, saveEvery }",
|
|
114
|
+
],
|
|
115
|
+
veneer: [
|
|
116
|
+
z.union([z.boolean(), z.object({ strict: z.boolean().optional() })]),
|
|
117
|
+
"a boolean or { strict }",
|
|
118
|
+
],
|
|
119
|
+
brake: [
|
|
120
|
+
z.union([
|
|
121
|
+
z.boolean(),
|
|
122
|
+
z.object({
|
|
123
|
+
maxRps: positive.optional(),
|
|
124
|
+
respectRetryAfter: z.boolean().optional(),
|
|
125
|
+
perHost: z.boolean().optional(),
|
|
126
|
+
maxBackoff: positive.optional(),
|
|
127
|
+
}),
|
|
128
|
+
]),
|
|
129
|
+
"a boolean or { maxRps, respectRetryAfter, perHost, maxBackoff }",
|
|
130
|
+
],
|
|
131
|
+
dodge: [
|
|
132
|
+
z.object({
|
|
133
|
+
pool: z.array(z.string().min(1)).min(1),
|
|
134
|
+
rotateOn: z.array(z.number().int()).optional(),
|
|
135
|
+
healthCheck: z.boolean().optional(),
|
|
136
|
+
healthTimeout: positive.optional(),
|
|
137
|
+
cooldown: positive.optional(),
|
|
138
|
+
onBlocked: z
|
|
139
|
+
.custom((v) => typeof v === "function")
|
|
140
|
+
.optional(),
|
|
141
|
+
}),
|
|
142
|
+
"{ pool: [proxy urls], rotateOn, healthCheck, healthTimeout, cooldown, onBlocked }",
|
|
143
|
+
],
|
|
144
|
+
cocoon: [z.string().min(1), "a folder path"],
|
|
145
|
+
lens: [
|
|
146
|
+
z.union([
|
|
147
|
+
z.boolean(),
|
|
148
|
+
z.object({
|
|
149
|
+
audit: z.boolean().optional(),
|
|
150
|
+
target: z.literal("local").optional(),
|
|
151
|
+
quiet: z.boolean().optional(),
|
|
152
|
+
out: z.string().min(1).optional(),
|
|
153
|
+
}),
|
|
154
|
+
]),
|
|
155
|
+
'a boolean or { audit, target: "local", quiet, out }',
|
|
156
|
+
],
|
|
157
|
+
plugins: [
|
|
158
|
+
z.array(z.custom((v) => typeof v === "object" && v !== null && typeof v.name === "string")),
|
|
159
|
+
"an array of plugin objects with a name",
|
|
160
|
+
],
|
|
161
|
+
uam: [
|
|
162
|
+
z.union([
|
|
163
|
+
z.boolean(),
|
|
164
|
+
z.object({
|
|
165
|
+
timeout: positive.optional(),
|
|
166
|
+
interval: positive.optional(),
|
|
167
|
+
waitOnGoto: z.boolean().optional(),
|
|
168
|
+
}),
|
|
169
|
+
]),
|
|
170
|
+
"a boolean or { timeout, interval, waitOnGoto }",
|
|
171
|
+
],
|
|
172
|
+
};
|
|
173
|
+
const PASSTHROUGH = new Set([
|
|
174
|
+
"allow_webgl",
|
|
175
|
+
"channel",
|
|
176
|
+
"chromiumSandbox",
|
|
177
|
+
"devtools",
|
|
178
|
+
"downloadsPath",
|
|
179
|
+
"executablePath",
|
|
180
|
+
"firefoxUserPrefs",
|
|
181
|
+
"handleSIGHUP",
|
|
182
|
+
"handleSIGINT",
|
|
183
|
+
"handleSIGTERM",
|
|
184
|
+
"ignoreDefaultArgs",
|
|
185
|
+
"logger",
|
|
186
|
+
"slowMo",
|
|
187
|
+
"timeout",
|
|
188
|
+
"tracesDir",
|
|
189
|
+
]);
|
|
190
|
+
const WARNED = new Set();
|
|
191
|
+
function distance(a, b) {
|
|
192
|
+
const prev = Array.from({ length: b.length + 1 }, (_, i) => i);
|
|
193
|
+
for (let i = 1; i <= a.length; i++) {
|
|
194
|
+
let diag = prev[0];
|
|
195
|
+
prev[0] = i;
|
|
196
|
+
for (let j = 1; j <= b.length; j++) {
|
|
197
|
+
const next = prev[j];
|
|
198
|
+
prev[j] = Math.min(prev[j] + 1, prev[j - 1] + 1, diag + (a[i - 1] === b[j - 1] ? 0 : 1));
|
|
199
|
+
diag = next;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return prev[b.length];
|
|
203
|
+
}
|
|
204
|
+
function closestKey(key) {
|
|
205
|
+
if (key.length < 4)
|
|
206
|
+
return null;
|
|
207
|
+
const lower = key.toLowerCase();
|
|
208
|
+
let best = null;
|
|
209
|
+
let bestDistance = 3;
|
|
210
|
+
for (const candidate of Object.keys(SPEC)) {
|
|
211
|
+
const d = distance(lower, candidate.toLowerCase());
|
|
212
|
+
if (d < bestDistance) {
|
|
213
|
+
bestDistance = d;
|
|
214
|
+
best = candidate;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return best;
|
|
218
|
+
}
|
|
219
|
+
function describe(value) {
|
|
220
|
+
if (value === null)
|
|
221
|
+
return "null";
|
|
222
|
+
if (Array.isArray(value))
|
|
223
|
+
return "an array";
|
|
224
|
+
if (typeof value === "string") {
|
|
225
|
+
return `the string "${value.length > 24 ? `${value.slice(0, 24)}...` : value}"`;
|
|
226
|
+
}
|
|
227
|
+
if (typeof value === "object")
|
|
228
|
+
return "an object";
|
|
229
|
+
return `${typeof value} ${String(value)}`;
|
|
230
|
+
}
|
|
231
|
+
export function validateOptions(options) {
|
|
232
|
+
if (!options || process.env.BEXXCV_NO_VALIDATE)
|
|
233
|
+
return;
|
|
234
|
+
const problems = [];
|
|
235
|
+
for (const [key, value] of Object.entries(options)) {
|
|
236
|
+
if (value === undefined)
|
|
237
|
+
continue;
|
|
238
|
+
const spec = SPEC[key];
|
|
239
|
+
if (spec) {
|
|
240
|
+
if (!spec[0].safeParse(value).success) {
|
|
241
|
+
problems.push(`${key}: expected ${spec[1]}, got ${describe(value)}`);
|
|
242
|
+
}
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
if (PASSTHROUGH.has(key) || WARNED.has(key))
|
|
246
|
+
continue;
|
|
247
|
+
const hint = closestKey(key);
|
|
248
|
+
if (hint) {
|
|
249
|
+
WARNED.add(key);
|
|
250
|
+
console.warn(`[bexxcv] Unknown option "${key}", did you mean "${hint}"?`);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
if (problems.length > 0) {
|
|
254
|
+
throw new InvalidOptions(`Invalid bexxcv options:\n ${problems.join("\n ")}`);
|
|
255
|
+
}
|
|
256
|
+
}
|
package/dist/sync_api.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type Browser, type BrowserContext, type BrowserType } from "playwright-core";
|
|
2
2
|
import { type LaunchOptions } from "./utils.js";
|
|
3
3
|
import { type TurnstileOptions } from "./turnstile.js";
|
|
4
|
+
import { type PluginOptions } from "./plugins/index.js";
|
|
4
5
|
import { type UamOptions } from "./uam.js";
|
|
5
6
|
export interface BexxcvOptions extends LaunchOptions {
|
|
6
7
|
user_data_dir?: string;
|
|
@@ -8,7 +9,8 @@ export interface BexxcvOptions extends LaunchOptions {
|
|
|
8
9
|
turnstile?: boolean | TurnstileOptions;
|
|
9
10
|
uam?: boolean | UamOptions;
|
|
10
11
|
}
|
|
11
|
-
export
|
|
12
|
+
export type BexxcvLaunchOptions = BexxcvOptions & PluginOptions;
|
|
13
|
+
export declare function Bexxcv<UserDataDir extends string | undefined = undefined, ReturnType = UserDataDir extends string ? BrowserContext : Browser>(launch_options?: BexxcvOptions & PluginOptions & {
|
|
12
14
|
user_data_dir?: UserDataDir;
|
|
13
15
|
}): Promise<ReturnType>;
|
|
14
16
|
export declare const Camoufox: typeof Bexxcv;
|
package/dist/sync_api.js
CHANGED
|
@@ -1,11 +1,20 @@
|
|
|
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";
|
|
6
|
+
import { applyPlugins, buildPlugins, runBeforeLaunch, stripPluginOptions, } from "./plugins/index.js";
|
|
4
7
|
import { attachUam } from "./uam.js";
|
|
5
8
|
import { VirtualDisplay } from "./virtdisplay.js";
|
|
6
9
|
import { needsXvfb } from "./xvfb.js";
|
|
7
10
|
export async function Bexxcv(launch_options = {}) {
|
|
8
|
-
|
|
11
|
+
validateOptions(launch_options);
|
|
12
|
+
warnIfDataStale();
|
|
13
|
+
const pluginList = buildPlugins(launch_options);
|
|
14
|
+
launch_options = { ...launch_options };
|
|
15
|
+
await runBeforeLaunch(pluginList, launch_options);
|
|
16
|
+
const { headless, user_data_dir, auto_xvfb = true, turnstile = false, uam = false, ...restOptions } = launch_options;
|
|
17
|
+
const opts = stripPluginOptions(restOptions);
|
|
9
18
|
const needsDisplay = auto_xvfb && needsXvfb();
|
|
10
19
|
const effectiveHeadless = (() => {
|
|
11
20
|
if (headless === "virtual")
|
|
@@ -23,6 +32,9 @@ export async function Bexxcv(launch_options = {}) {
|
|
|
23
32
|
if (uam) {
|
|
24
33
|
attachUam(launched, uam === true ? {} : uam);
|
|
25
34
|
}
|
|
35
|
+
if (pluginList.length > 0) {
|
|
36
|
+
await applyPlugins(launched, pluginList);
|
|
37
|
+
}
|
|
26
38
|
return launched;
|
|
27
39
|
}
|
|
28
40
|
export const Camoufox = Bexxcv;
|
package/dist/turnstile.d.ts
CHANGED
|
@@ -3,5 +3,17 @@ export interface TurnstileOptions {
|
|
|
3
3
|
interval?: number;
|
|
4
4
|
retryAfter?: number;
|
|
5
5
|
}
|
|
6
|
+
export interface Widget {
|
|
7
|
+
x: number;
|
|
8
|
+
y: number;
|
|
9
|
+
w: number;
|
|
10
|
+
h: number;
|
|
11
|
+
solved: boolean;
|
|
12
|
+
key: string;
|
|
13
|
+
}
|
|
14
|
+
export declare function findWidgets(page: Page): Promise<Widget[]>;
|
|
15
|
+
export declare function readTurnstileToken(page: Page): Promise<string | null>;
|
|
16
|
+
export declare function createClicker(retryAfter?: number): (page: Page) => Promise<boolean>;
|
|
17
|
+
export declare function solveTurnstile(page: Page, timeout?: number, idleChecks?: number, retryAfter?: number): Promise<string | null>;
|
|
6
18
|
export declare function watchTurnstile(page: Page, options?: TurnstileOptions): void;
|
|
7
19
|
export declare function attachTurnstile<T extends Browser | BrowserContext>(target: T, options?: TurnstileOptions): T;
|
package/dist/turnstile.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { onEachPage } from "./pagehooks.js";
|
|
2
2
|
import { between, sleep } from "./random.js";
|
|
3
3
|
const WATCHED = new WeakSet();
|
|
4
|
-
async function findWidgets(page) {
|
|
4
|
+
export async function findWidgets(page) {
|
|
5
5
|
return page.evaluate(() => {
|
|
6
6
|
const out = [];
|
|
7
7
|
const seen = new Set();
|
|
@@ -45,6 +45,29 @@ async function findWidgets(page) {
|
|
|
45
45
|
return out;
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
|
+
export async function readTurnstileToken(page) {
|
|
49
|
+
try {
|
|
50
|
+
return await page.evaluate(() => {
|
|
51
|
+
for (const el of Array.from(document.querySelectorAll('[name="cf-turnstile-response"]'))) {
|
|
52
|
+
if (el.value && el.value.length > 20)
|
|
53
|
+
return el.value;
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
const w = window;
|
|
57
|
+
const value = w.turnstile?.getResponse?.();
|
|
58
|
+
if (value && value.length > 20)
|
|
59
|
+
return value;
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
return null;
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
48
71
|
async function clickAt(page, x, y) {
|
|
49
72
|
await page.mouse.move(x + between(-60, 60), y + between(-40, 40), { steps: 4 });
|
|
50
73
|
await sleep(between(60, 160));
|
|
@@ -54,6 +77,51 @@ async function clickAt(page, x, y) {
|
|
|
54
77
|
await sleep(between(60, 120));
|
|
55
78
|
await page.mouse.up();
|
|
56
79
|
}
|
|
80
|
+
async function clickPending(page, clicked, retryAfter) {
|
|
81
|
+
const widgets = await findWidgets(page);
|
|
82
|
+
let clicks = 0;
|
|
83
|
+
for (const widget of widgets) {
|
|
84
|
+
if (widget.solved)
|
|
85
|
+
continue;
|
|
86
|
+
const last = clicked.get(widget.key) ?? 0;
|
|
87
|
+
if (Date.now() - last < retryAfter)
|
|
88
|
+
continue;
|
|
89
|
+
clicked.set(widget.key, Date.now());
|
|
90
|
+
const x = widget.x + Math.min(30, widget.w / 2) + between(-4, 4);
|
|
91
|
+
const y = widget.y + widget.h / 2 + between(-4, 4);
|
|
92
|
+
await clickAt(page, x, y);
|
|
93
|
+
clicks++;
|
|
94
|
+
}
|
|
95
|
+
return { widgets, clicks };
|
|
96
|
+
}
|
|
97
|
+
export function createClicker(retryAfter = 8000) {
|
|
98
|
+
const clicked = new Map();
|
|
99
|
+
return async (page) => {
|
|
100
|
+
const result = await clickPending(page, clicked, retryAfter);
|
|
101
|
+
return result.clicks > 0;
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
export async function solveTurnstile(page, timeout = 30000, idleChecks = 4, retryAfter = 8000) {
|
|
105
|
+
const end = Date.now() + timeout;
|
|
106
|
+
const clicked = new Map();
|
|
107
|
+
let idle = 0;
|
|
108
|
+
while (Date.now() < end && !page.isClosed()) {
|
|
109
|
+
const token = await readTurnstileToken(page);
|
|
110
|
+
if (token)
|
|
111
|
+
return token;
|
|
112
|
+
try {
|
|
113
|
+
const result = await clickPending(page, clicked, retryAfter);
|
|
114
|
+
idle = result.widgets.length === 0 ? idle + 1 : 0;
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
idle++;
|
|
118
|
+
}
|
|
119
|
+
if (idle >= idleChecks)
|
|
120
|
+
return null;
|
|
121
|
+
await sleep(1000);
|
|
122
|
+
}
|
|
123
|
+
return readTurnstileToken(page);
|
|
124
|
+
}
|
|
57
125
|
export function watchTurnstile(page, options = {}) {
|
|
58
126
|
if (WATCHED.has(page))
|
|
59
127
|
return;
|
|
@@ -68,18 +136,7 @@ export function watchTurnstile(page, options = {}) {
|
|
|
68
136
|
const loop = async () => {
|
|
69
137
|
while (active && !page.isClosed()) {
|
|
70
138
|
try {
|
|
71
|
-
|
|
72
|
-
for (const widget of widgets) {
|
|
73
|
-
if (widget.solved)
|
|
74
|
-
continue;
|
|
75
|
-
const last = clicked.get(widget.key) ?? 0;
|
|
76
|
-
if (Date.now() - last < retryAfter)
|
|
77
|
-
continue;
|
|
78
|
-
clicked.set(widget.key, Date.now());
|
|
79
|
-
const x = widget.x + Math.min(30, widget.w / 2) + between(-4, 4);
|
|
80
|
-
const y = widget.y + widget.h / 2 + between(-4, 4);
|
|
81
|
-
await clickAt(page, x, y);
|
|
82
|
-
}
|
|
139
|
+
await clickPending(page, clicked, retryAfter);
|
|
83
140
|
}
|
|
84
141
|
catch {
|
|
85
142
|
await sleep(500);
|
package/dist/uam.d.ts
CHANGED
|
@@ -3,12 +3,16 @@ export interface UamOptions {
|
|
|
3
3
|
timeout?: number;
|
|
4
4
|
interval?: number;
|
|
5
5
|
waitOnGoto?: boolean;
|
|
6
|
+
assist?: (page: Page) => Promise<boolean>;
|
|
6
7
|
}
|
|
7
8
|
export interface UamResult {
|
|
8
9
|
challenged: boolean;
|
|
9
10
|
bypassed: boolean;
|
|
10
11
|
cookie: string | null;
|
|
11
12
|
}
|
|
13
|
+
export declare function trackMitigation(page: Page): void;
|
|
14
|
+
export declare function isChallenge(page: Page): Promise<boolean>;
|
|
15
|
+
export declare function humanActivity(page: Page, scale?: number): Promise<void>;
|
|
12
16
|
export declare function waitForUam(page: Page, options?: UamOptions): Promise<UamResult>;
|
|
13
17
|
export declare function watchUam(page: Page, options?: UamOptions): void;
|
|
14
18
|
export declare function attachUam<T extends Browser | BrowserContext>(target: T, options?: UamOptions): T;
|