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.
Files changed (44) hide show
  1. package/README.md +81 -0
  2. package/dist/__main__.js +7 -0
  3. package/dist/data-files/data-version.json +7 -0
  4. package/dist/data-files/webgl_data.db +0 -0
  5. package/dist/doctor.d.ts +26 -0
  6. package/dist/doctor.js +149 -0
  7. package/dist/exceptions.d.ts +3 -0
  8. package/dist/exceptions.js +6 -0
  9. package/dist/index.d.ts +4 -0
  10. package/dist/index.js +4 -0
  11. package/dist/pagehooks.d.ts +6 -0
  12. package/dist/pagehooks.js +19 -0
  13. package/dist/plugins/brake.d.ts +8 -0
  14. package/dist/plugins/brake.js +74 -0
  15. package/dist/plugins/cocoon.d.ts +5 -0
  16. package/dist/plugins/cocoon.js +17 -0
  17. package/dist/plugins/dodge.d.ts +21 -0
  18. package/dist/plugins/dodge.js +102 -0
  19. package/dist/plugins/gauntlet.d.ts +20 -0
  20. package/dist/plugins/gauntlet.js +119 -0
  21. package/dist/plugins/index.d.ts +27 -0
  22. package/dist/plugins/index.js +55 -0
  23. package/dist/plugins/lens.d.ts +20 -0
  24. package/dist/plugins/lens.js +89 -0
  25. package/dist/plugins/stash.d.ts +8 -0
  26. package/dist/plugins/stash.js +108 -0
  27. package/dist/plugins/types.d.ts +13 -0
  28. package/dist/plugins/types.js +49 -0
  29. package/dist/plugins/veneer.d.ts +5 -0
  30. package/dist/plugins/veneer.js +37 -0
  31. package/dist/plugins/wiretap.d.ts +26 -0
  32. package/dist/plugins/wiretap.js +123 -0
  33. package/dist/realism.d.ts +3 -0
  34. package/dist/realism.js +57 -0
  35. package/dist/schema.d.ts +1 -0
  36. package/dist/schema.js +256 -0
  37. package/dist/sync_api.d.ts +3 -1
  38. package/dist/sync_api.js +13 -1
  39. package/dist/turnstile.d.ts +12 -0
  40. package/dist/turnstile.js +70 -13
  41. package/dist/uam.d.ts +4 -0
  42. package/dist/uam.js +32 -6
  43. package/dist/utils.js +9 -3
  44. package/package.json +13 -10
@@ -0,0 +1,119 @@
1
+ import { sleep } from "../random.js";
2
+ import { createClicker, findWidgets, solveTurnstile } from "../turnstile.js";
3
+ import { humanActivity, isChallenge, trackMitigation, waitForUam, } from "../uam.js";
4
+ const RESULTS = new WeakMap();
5
+ const WRAPPED = new WeakSet();
6
+ const RUNNING = new WeakSet();
7
+ export function gauntletResult(page) {
8
+ return RESULTS.get(page) ?? null;
9
+ }
10
+ async function widgetPending(page) {
11
+ try {
12
+ const widgets = await findWidgets(page);
13
+ return widgets.some((widget) => !widget.solved);
14
+ }
15
+ catch {
16
+ return false;
17
+ }
18
+ }
19
+ async function sustain(page, ms) {
20
+ const end = Date.now() + ms;
21
+ while (Date.now() < end && !page.isClosed()) {
22
+ try {
23
+ await humanActivity(page);
24
+ }
25
+ catch {
26
+ await sleep(500);
27
+ }
28
+ }
29
+ }
30
+ export async function runGauntlet(page, options = {}) {
31
+ const solve = options.solve ?? ["uam", "turnstile"];
32
+ const maxTries = options.maxTries ?? 3;
33
+ const timeout = options.timeout ?? 30000;
34
+ const result = { passed: false, tries: 0, uam: null, turnstile: null };
35
+ const wantsTurnstile = solve.includes("turnstile");
36
+ for (let attempt = 1; attempt <= maxTries && !page.isClosed(); attempt++) {
37
+ result.tries = attempt;
38
+ for (const stage of solve) {
39
+ if (stage === "uam") {
40
+ const clicker = wantsTurnstile ? createClicker() : undefined;
41
+ result.uam = await waitForUam(page, { timeout, assist: clicker });
42
+ }
43
+ else if (stage === "turnstile") {
44
+ const token = await solveTurnstile(page, timeout);
45
+ if (token)
46
+ result.turnstile = token;
47
+ }
48
+ }
49
+ const stillChallenged = await isChallenge(page);
50
+ const missingToken = wantsTurnstile && !result.turnstile && (await widgetPending(page));
51
+ if (!stillChallenged && !missingToken) {
52
+ result.passed = true;
53
+ break;
54
+ }
55
+ await sleep(1500);
56
+ }
57
+ if (result.passed && options.sustain && options.sustain > 0) {
58
+ await sustain(page, options.sustain);
59
+ }
60
+ return result;
61
+ }
62
+ async function runGuarded(page, options, waitIfBusy) {
63
+ if (RUNNING.has(page)) {
64
+ if (!waitIfBusy)
65
+ return;
66
+ const limit = Date.now() + (options.timeout ?? 30000) * (options.maxTries ?? 3);
67
+ while (RUNNING.has(page) && Date.now() < limit)
68
+ await sleep(200);
69
+ return;
70
+ }
71
+ RUNNING.add(page);
72
+ try {
73
+ RESULTS.set(page, await runGauntlet(page, options));
74
+ }
75
+ catch (error) {
76
+ console.warn(`[bexxcv] gauntlet failed: ${error.message}`);
77
+ }
78
+ finally {
79
+ RUNNING.delete(page);
80
+ }
81
+ }
82
+ export function gauntlet(options = {}) {
83
+ return {
84
+ name: "gauntlet",
85
+ order: 50,
86
+ onPage(page) {
87
+ if (WRAPPED.has(page))
88
+ return;
89
+ WRAPPED.add(page);
90
+ trackMitigation(page);
91
+ const originalGoto = page.goto.bind(page);
92
+ page.goto = (async (...args) => {
93
+ const response = await originalGoto(...args);
94
+ await runGuarded(page, options, true);
95
+ return response;
96
+ });
97
+ if (options.watch === false)
98
+ return;
99
+ let active = true;
100
+ page.on("close", () => {
101
+ active = false;
102
+ });
103
+ const interval = options.interval ?? 1500;
104
+ void (async () => {
105
+ while (active && !page.isClosed()) {
106
+ try {
107
+ if (!RUNNING.has(page) && (await isChallenge(page))) {
108
+ await runGuarded(page, options, false);
109
+ }
110
+ }
111
+ catch {
112
+ await sleep(500);
113
+ }
114
+ await sleep(interval);
115
+ }
116
+ })();
117
+ },
118
+ };
119
+ }
@@ -0,0 +1,27 @@
1
+ import { type BrakeOptions } from "./brake.js";
2
+ import { type DodgeOptions } from "./dodge.js";
3
+ import { type GauntletOptions } from "./gauntlet.js";
4
+ import { type LensOptions } from "./lens.js";
5
+ import { type StashOptions } from "./stash.js";
6
+ import type { BexxcvPlugin } from "./types.js";
7
+ import { type VeneerOptions } from "./veneer.js";
8
+ import { type WiretapOptions } from "./wiretap.js";
9
+ export interface PluginOptions {
10
+ gauntlet?: boolean | GauntletOptions;
11
+ wiretap?: boolean | WiretapOptions;
12
+ stash?: string | StashOptions;
13
+ veneer?: boolean | VeneerOptions;
14
+ brake?: boolean | BrakeOptions;
15
+ dodge?: DodgeOptions;
16
+ cocoon?: string;
17
+ lens?: boolean | LensOptions;
18
+ plugins?: BexxcvPlugin[];
19
+ }
20
+ export declare const PLUGIN_KEYS: readonly ["gauntlet", "wiretap", "stash", "veneer", "brake", "dodge", "cocoon", "lens", "plugins"];
21
+ export declare function buildPlugins(options: PluginOptions): BexxcvPlugin[];
22
+ export declare function stripPluginOptions<T extends Record<string, unknown>>(options: T): T;
23
+ export { applyPlugins, runBeforeLaunch, type BexxcvPlugin } from "./types.js";
24
+ export { auditFingerprint, lensReport } from "./lens.js";
25
+ export { gauntletResult, runGauntlet } from "./gauntlet.js";
26
+ export { wiretapEntries } from "./wiretap.js";
27
+ export type { BrakeOptions, DodgeOptions, GauntletOptions, LensOptions, StashOptions, VeneerOptions, WiretapOptions, };
@@ -0,0 +1,55 @@
1
+ import { brake } from "./brake.js";
2
+ import { cocoon } from "./cocoon.js";
3
+ import { dodge } from "./dodge.js";
4
+ import { gauntlet } from "./gauntlet.js";
5
+ import { lens } from "./lens.js";
6
+ import { stash } from "./stash.js";
7
+ import { veneer } from "./veneer.js";
8
+ import { wiretap } from "./wiretap.js";
9
+ export const PLUGIN_KEYS = [
10
+ "gauntlet",
11
+ "wiretap",
12
+ "stash",
13
+ "veneer",
14
+ "brake",
15
+ "dodge",
16
+ "cocoon",
17
+ "lens",
18
+ "plugins",
19
+ ];
20
+ function opts(value) {
21
+ return value === true ? {} : value;
22
+ }
23
+ export function buildPlugins(options) {
24
+ const list = [];
25
+ if (options.dodge)
26
+ list.push(dodge(options.dodge));
27
+ if (options.cocoon)
28
+ list.push(cocoon({ dir: options.cocoon }));
29
+ if (options.stash) {
30
+ list.push(stash(typeof options.stash === "string" ? { file: options.stash } : options.stash));
31
+ }
32
+ if (options.wiretap)
33
+ list.push(wiretap(opts(options.wiretap)));
34
+ if (options.veneer)
35
+ list.push(veneer(opts(options.veneer)));
36
+ if (options.lens)
37
+ list.push(lens(opts(options.lens)));
38
+ if (options.gauntlet)
39
+ list.push(gauntlet(opts(options.gauntlet)));
40
+ if (options.brake)
41
+ list.push(brake(opts(options.brake)));
42
+ if (options.plugins)
43
+ list.push(...options.plugins);
44
+ return list;
45
+ }
46
+ export function stripPluginOptions(options) {
47
+ const copy = { ...options };
48
+ for (const key of PLUGIN_KEYS)
49
+ delete copy[key];
50
+ return copy;
51
+ }
52
+ export { applyPlugins, runBeforeLaunch } from "./types.js";
53
+ export { auditFingerprint, lensReport } from "./lens.js";
54
+ export { gauntletResult, runGauntlet } from "./gauntlet.js";
55
+ export { wiretapEntries } from "./wiretap.js";
@@ -0,0 +1,20 @@
1
+ import type { Page } from "playwright-core";
2
+ import type { BexxcvPlugin } from "./types.js";
3
+ export interface LensOptions {
4
+ audit?: boolean;
5
+ target?: "local";
6
+ quiet?: boolean;
7
+ out?: string;
8
+ }
9
+ export interface LensCheck {
10
+ id: string;
11
+ ok: boolean;
12
+ detail: string;
13
+ }
14
+ export interface LensReport {
15
+ score: number;
16
+ checks: LensCheck[];
17
+ }
18
+ export declare function lensReport(page: Page): LensReport | null;
19
+ export declare function auditFingerprint(page: Page): Promise<LensReport>;
20
+ export declare function lens(options?: LensOptions): BexxcvPlugin;
@@ -0,0 +1,89 @@
1
+ import * as fs from "node:fs";
2
+ import * as path from "node:path";
3
+ import { isKnownPhysical } from "../realism.js";
4
+ const REPORTS = new WeakMap();
5
+ const AUDITED = new WeakSet();
6
+ export function lensReport(page) {
7
+ return REPORTS.get(page) ?? null;
8
+ }
9
+ const PLAUSIBLE_CORES = new Set([2, 4, 6, 8, 10, 12, 14, 16, 20, 24, 32]);
10
+ export async function auditFingerprint(page) {
11
+ const probe = await page.evaluate(() => {
12
+ let vendor = null;
13
+ let renderer = null;
14
+ try {
15
+ const canvas = document.createElement("canvas");
16
+ const gl = (canvas.getContext("webgl") ||
17
+ canvas.getContext("experimental-webgl"));
18
+ if (gl) {
19
+ const ext = gl.getExtension("WEBGL_debug_renderer_info");
20
+ vendor = String(gl.getParameter(ext ? ext.UNMASKED_VENDOR_WEBGL : gl.VENDOR));
21
+ renderer = String(gl.getParameter(ext ? ext.UNMASKED_RENDERER_WEBGL : gl.RENDERER));
22
+ }
23
+ }
24
+ catch {
25
+ vendor = null;
26
+ }
27
+ return {
28
+ ua: navigator.userAgent,
29
+ platform: navigator.platform,
30
+ language: navigator.language,
31
+ languages: Array.from(navigator.languages),
32
+ cores: navigator.hardwareConcurrency,
33
+ webdriver: navigator.webdriver === true,
34
+ dpr: window.devicePixelRatio,
35
+ screenW: screen.width,
36
+ screenH: screen.height,
37
+ innerW: window.innerWidth,
38
+ innerH: window.innerHeight,
39
+ outerW: window.outerWidth,
40
+ outerH: window.outerHeight,
41
+ vendor,
42
+ renderer,
43
+ };
44
+ });
45
+ const checks = [];
46
+ const add = (id, ok, detail) => checks.push({ id, ok, detail });
47
+ add("webdriver", !probe.webdriver, `navigator.webdriver is ${probe.webdriver}`);
48
+ const platformOk = (/Windows/i.test(probe.ua) && /^Win/i.test(probe.platform)) ||
49
+ (/Macintosh|Mac OS/i.test(probe.ua) && /^Mac/i.test(probe.platform)) ||
50
+ (/Linux|X11/i.test(probe.ua) && !/Windows|Macintosh/i.test(probe.ua) && /Linux|X11/i.test(probe.platform));
51
+ add("ua-platform", platformOk, `${probe.platform} against the user agent`);
52
+ add("language", probe.languages[0] === probe.language, `language ${probe.language}, first of languages ${probe.languages[0]}`);
53
+ add("dpr-screen", isKnownPhysical(probe.screenW * probe.dpr, probe.screenH * probe.dpr), `${probe.screenW}x${probe.screenH} at DPR ${probe.dpr}`);
54
+ add("window-size", probe.innerW <= probe.outerW && probe.innerH <= probe.outerH && probe.outerW <= probe.screenW + 16, `inner ${probe.innerW}x${probe.innerH}, outer ${probe.outerW}x${probe.outerH}, screen ${probe.screenW}x${probe.screenH}`);
55
+ add("cores", PLAUSIBLE_CORES.has(probe.cores), `${probe.cores} logical cores`);
56
+ add("webgl", probe.vendor !== null && probe.renderer !== null, probe.renderer ? `${probe.vendor} / ${probe.renderer}` : "WebGL is not available");
57
+ add("webgl-software", !(probe.renderer && /llvmpipe|swiftshader|software|mesa offscreen/i.test(probe.renderer)), probe.renderer ?? "no renderer");
58
+ const passed = checks.filter((check) => check.ok).length;
59
+ return { score: Math.round((passed / checks.length) * 100), checks };
60
+ }
61
+ export function lens(options = {}) {
62
+ return {
63
+ name: "lens",
64
+ order: 40,
65
+ onPage(page) {
66
+ if (options.audit === false || AUDITED.has(page))
67
+ return;
68
+ AUDITED.add(page);
69
+ page.once("load", () => {
70
+ void auditFingerprint(page)
71
+ .then((report) => {
72
+ REPORTS.set(page, report);
73
+ if (!options.quiet) {
74
+ console.log(`[bexxcv] lens: fingerprint score ${report.score}/100`);
75
+ for (const check of report.checks) {
76
+ if (!check.ok)
77
+ console.log(`[bexxcv] lens: ${check.id} failed, ${check.detail}`);
78
+ }
79
+ }
80
+ if (options.out) {
81
+ fs.mkdirSync(path.dirname(path.resolve(options.out)), { recursive: true });
82
+ fs.writeFileSync(options.out, `${JSON.stringify(report, null, 2)}\n`);
83
+ }
84
+ })
85
+ .catch(() => undefined);
86
+ });
87
+ },
88
+ };
89
+ }
@@ -0,0 +1,8 @@
1
+ import type { BexxcvPlugin } from "./types.js";
2
+ export interface StashOptions {
3
+ file: string;
4
+ names?: string[];
5
+ domains?: string[];
6
+ saveEvery?: number;
7
+ }
8
+ export declare function stash(options: StashOptions): BexxcvPlugin;
@@ -0,0 +1,108 @@
1
+ import * as fs from "node:fs";
2
+ import * as path from "node:path";
3
+ function domainKey(cookie) {
4
+ return cookie.domain.replace(/^\./, "").toLowerCase();
5
+ }
6
+ function expired(cookie) {
7
+ return cookie.expires > 0 && cookie.expires < Date.now() / 1000;
8
+ }
9
+ function readFile(file) {
10
+ try {
11
+ const raw = JSON.parse(fs.readFileSync(file, "utf-8"));
12
+ if (raw && typeof raw === "object" && raw.domains)
13
+ return raw;
14
+ }
15
+ catch {
16
+ return { version: 1, saved: new Date(0).toISOString(), domains: {} };
17
+ }
18
+ return { version: 1, saved: new Date(0).toISOString(), domains: {} };
19
+ }
20
+ export function stash(options) {
21
+ const file = path.resolve(options.file);
22
+ const names = options.names ? new Set(options.names) : null;
23
+ const domains = options.domains?.map((d) => d.toLowerCase().replace(/^\./, "")) ?? null;
24
+ const known = new Set();
25
+ let timer = null;
26
+ let launchProxy = "direct";
27
+ const contextProxy = new WeakMap();
28
+ const wanted = (cookie) => {
29
+ if (names && !names.has(cookie.name))
30
+ return false;
31
+ if (domains) {
32
+ const key = domainKey(cookie);
33
+ if (!domains.some((d) => key === d || key.endsWith(`.${d}`)))
34
+ return false;
35
+ }
36
+ return true;
37
+ };
38
+ const BOUND = new Set(["cf_clearance"]);
39
+ const save = async (contexts) => {
40
+ const data = readFile(file);
41
+ for (const context of contexts) {
42
+ const grouped = {};
43
+ for (const cookie of await context.cookies()) {
44
+ if (!wanted(cookie) || expired(cookie))
45
+ continue;
46
+ (grouped[domainKey(cookie)] ??= []).push(cookie);
47
+ }
48
+ for (const [key, list] of Object.entries(grouped)) {
49
+ data.domains[key] = list;
50
+ (data.bound ??= {})[key] = contextProxy.get(context) ?? launchProxy;
51
+ }
52
+ }
53
+ for (const [key, list] of Object.entries(data.domains)) {
54
+ const alive = list.filter((cookie) => !expired(cookie));
55
+ if (alive.length > 0)
56
+ data.domains[key] = alive;
57
+ else
58
+ delete data.domains[key];
59
+ }
60
+ data.saved = new Date().toISOString();
61
+ fs.mkdirSync(path.dirname(file), { recursive: true });
62
+ fs.writeFileSync(file, `${JSON.stringify(data, null, 2)}\n`, { mode: 0o600 });
63
+ };
64
+ return {
65
+ name: "stash",
66
+ order: 20,
67
+ beforeLaunch(launch) {
68
+ const proxy = launch.proxy;
69
+ if (typeof proxy === "string")
70
+ launchProxy = proxy;
71
+ else if (proxy && proxy.server)
72
+ launchProxy = proxy.server;
73
+ },
74
+ async onContext(context, contextOptions) {
75
+ known.add(context);
76
+ const current = contextOptions.proxy?.server ?? launchProxy;
77
+ contextProxy.set(context, current);
78
+ const data = readFile(file);
79
+ const cookies = Object.entries(data.domains).flatMap(([key, list]) => list.filter((cookie) => {
80
+ if (!wanted(cookie) || expired(cookie))
81
+ return false;
82
+ if (BOUND.has(cookie.name) && (data.bound?.[key] ?? "direct") !== current)
83
+ return false;
84
+ return true;
85
+ }));
86
+ if (cookies.length > 0) {
87
+ try {
88
+ await context.addCookies(cookies);
89
+ }
90
+ catch (error) {
91
+ console.warn(`[bexxcv] stash could not load cookies: ${error.message}`);
92
+ }
93
+ }
94
+ if (options.saveEvery && !timer) {
95
+ timer = setInterval(() => {
96
+ void save([...known]).catch(() => undefined);
97
+ }, options.saveEvery);
98
+ timer.unref();
99
+ }
100
+ },
101
+ async beforeClose(contexts) {
102
+ if (timer)
103
+ clearInterval(timer);
104
+ timer = null;
105
+ await save(contexts);
106
+ },
107
+ };
108
+ }
@@ -0,0 +1,13 @@
1
+ import type { Browser, BrowserContext, Page } from "playwright-core";
2
+ import { type ContextOptions } from "../pagehooks.js";
3
+ export interface BexxcvPlugin {
4
+ name: string;
5
+ order?: number;
6
+ beforeLaunch?(options: Record<string, unknown>): void | Promise<void>;
7
+ beforeContext?(options: ContextOptions): void | Promise<void>;
8
+ onContext?(context: BrowserContext, options: ContextOptions): void | Promise<void>;
9
+ onPage?(page: Page, context: BrowserContext): void;
10
+ beforeClose?(contexts: BrowserContext[]): void | Promise<void>;
11
+ }
12
+ export declare function runBeforeLaunch(plugins: BexxcvPlugin[], options: Record<string, unknown>): Promise<void>;
13
+ export declare function applyPlugins<T extends Browser | BrowserContext>(target: T, plugins: BexxcvPlugin[]): Promise<T>;
@@ -0,0 +1,49 @@
1
+ import { onEachContext, onEachPage, } from "../pagehooks.js";
2
+ const DEFAULT_ORDER = 50;
3
+ function sortPlugins(plugins) {
4
+ return [...plugins].sort((a, b) => (a.order ?? DEFAULT_ORDER) - (b.order ?? DEFAULT_ORDER));
5
+ }
6
+ export async function runBeforeLaunch(plugins, options) {
7
+ for (const plugin of sortPlugins(plugins)) {
8
+ await plugin.beforeLaunch?.(options);
9
+ }
10
+ }
11
+ export async function applyPlugins(target, plugins) {
12
+ const sorted = sortPlugins(plugins);
13
+ await onEachContext(target, {
14
+ before: async (options) => {
15
+ for (const plugin of sorted)
16
+ await plugin.beforeContext?.(options);
17
+ },
18
+ after: async (context, options) => {
19
+ for (const plugin of sorted)
20
+ await plugin.onContext?.(context, options);
21
+ },
22
+ });
23
+ for (const plugin of sorted) {
24
+ if (!plugin.onPage)
25
+ continue;
26
+ const handler = plugin.onPage.bind(plugin);
27
+ onEachPage(target, (page) => handler(page, page.context()));
28
+ }
29
+ const closers = sorted.filter((plugin) => plugin.beforeClose);
30
+ if (closers.length > 0) {
31
+ const holder = target;
32
+ const originalClose = holder.close.bind(target);
33
+ holder.close = async (...args) => {
34
+ const contexts = typeof target.contexts === "function"
35
+ ? target.contexts()
36
+ : [target];
37
+ for (const plugin of [...closers].reverse()) {
38
+ try {
39
+ await plugin.beforeClose?.(contexts);
40
+ }
41
+ catch (error) {
42
+ console.warn(`[bexxcv] plugin "${plugin.name}" failed on close: ${error.message}`);
43
+ }
44
+ }
45
+ return originalClose(...args);
46
+ };
47
+ }
48
+ return target;
49
+ }
@@ -0,0 +1,5 @@
1
+ import type { BexxcvPlugin } from "./types.js";
2
+ export interface VeneerOptions {
3
+ strict?: boolean;
4
+ }
5
+ export declare function veneer(options?: VeneerOptions): BexxcvPlugin;
@@ -0,0 +1,37 @@
1
+ export function veneer(options = {}) {
2
+ let warned = false;
3
+ return {
4
+ name: "veneer",
5
+ order: 30,
6
+ async onContext(context) {
7
+ if (options.strict) {
8
+ await context.route("**/*", async (route) => {
9
+ const headers = route.request().headers();
10
+ if (/firefox/i.test(headers["user-agent"] ?? "")) {
11
+ const cleaned = {};
12
+ for (const [key, value] of Object.entries(headers)) {
13
+ if (!key.toLowerCase().startsWith("sec-ch-ua"))
14
+ cleaned[key] = value;
15
+ }
16
+ if (Object.keys(cleaned).length !== Object.keys(headers).length) {
17
+ await route.continue({ headers: cleaned });
18
+ return;
19
+ }
20
+ }
21
+ await route.continue();
22
+ });
23
+ return;
24
+ }
25
+ context.on("request", (request) => {
26
+ if (warned)
27
+ return;
28
+ const headers = request.headers();
29
+ if (/firefox/i.test(headers["user-agent"] ?? "") &&
30
+ Object.keys(headers).some((key) => key.toLowerCase().startsWith("sec-ch-ua"))) {
31
+ warned = true;
32
+ console.warn("[bexxcv] veneer: a Firefox user agent is sending sec-ch-ua headers, something upstream is injecting them. Use veneer: { strict: true } to strip them.");
33
+ }
34
+ });
35
+ },
36
+ };
37
+ }
@@ -0,0 +1,26 @@
1
+ import type { BrowserContext } from "playwright-core";
2
+ import type { BexxcvPlugin } from "./types.js";
3
+ export interface WiretapOptions {
4
+ match?: string[];
5
+ methods?: string[];
6
+ out?: string;
7
+ bodies?: boolean;
8
+ maxBodyBytes?: number;
9
+ streamTimeout?: number;
10
+ redact?: boolean;
11
+ }
12
+ export interface WiretapEntry {
13
+ time: string;
14
+ method: string;
15
+ url: string;
16
+ status: number;
17
+ requestHeaders: Record<string, string>;
18
+ postData: string | null;
19
+ responseHeaders: Record<string, string>;
20
+ contentType: string;
21
+ body: string | null;
22
+ bodyNote?: string;
23
+ events?: string[];
24
+ }
25
+ export declare function wiretapEntries(context: BrowserContext): WiretapEntry[];
26
+ export declare function wiretap(options?: WiretapOptions): BexxcvPlugin;