2026-03-05 07:03:57 +01:00
|
|
|
/**
|
|
|
|
|
* Shared argument builder for Playwright and Puppeteer wrappers.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import type { LaunchOptions } from "./types.js";
|
|
|
|
|
import { getDefaultStealthArgs } from "./config.js";
|
|
|
|
|
|
|
|
|
|
const DEBUG = /\bcloakbrowser\b/.test(process.env.DEBUG ?? "");
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Build deduplicated Chromium CLI args from stealth defaults + user overrides.
|
|
|
|
|
*
|
|
|
|
|
* Priority: stealth defaults < user args < dedicated params (timezone/locale).
|
|
|
|
|
*/
|
|
|
|
|
export function buildArgs(options: LaunchOptions): string[] {
|
|
|
|
|
const seen = new Map<string, string>();
|
|
|
|
|
|
|
|
|
|
if (options.stealthArgs !== false) {
|
|
|
|
|
for (const arg of getDefaultStealthArgs()) {
|
|
|
|
|
seen.set(arg.split("=")[0], arg);
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-03-15 01:18:32 +01:00
|
|
|
// GPU blocklist bypass:
|
|
|
|
|
// - Headed mode (all platforms): Chromium blocks WebGL on software GPUs
|
|
|
|
|
// in Docker/Xvfb. Flag lets SwiftShader serve WebGL. See issue #56.
|
|
|
|
|
// - Windows (all modes): Chromium's GPU blocklist blocks WebGPU for the
|
|
|
|
|
// Microsoft Basic Render Driver. Dawn's adapter_blocklist bypass alone
|
|
|
|
|
// isn't enough. Linux doesn't need it.
|
|
|
|
|
if (options.headless === false || process.platform === "win32") {
|
|
|
|
|
seen.set("--ignore-gpu-blocklist", "--ignore-gpu-blocklist");
|
|
|
|
|
}
|
2026-03-05 07:03:57 +01:00
|
|
|
if (options.args) {
|
|
|
|
|
for (const arg of options.args) {
|
|
|
|
|
const key = arg.split("=")[0];
|
|
|
|
|
if (seen.has(key)) {
|
|
|
|
|
if (DEBUG) console.debug(`[cloakbrowser] Arg override: ${seen.get(key)} -> ${arg}`);
|
|
|
|
|
}
|
|
|
|
|
seen.set(key, arg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (options.timezone) {
|
|
|
|
|
const key = "--fingerprint-timezone";
|
|
|
|
|
const flag = `${key}=${options.timezone}`;
|
|
|
|
|
if (seen.has(key)) {
|
|
|
|
|
if (DEBUG) console.debug(`[cloakbrowser] Arg override: ${seen.get(key)} -> ${flag}`);
|
|
|
|
|
}
|
|
|
|
|
seen.set(key, flag);
|
|
|
|
|
}
|
|
|
|
|
if (options.locale) {
|
2026-03-10 03:29:38 +01:00
|
|
|
for (const k of ["--lang", "--fingerprint-locale"] as const) {
|
|
|
|
|
const flag = `${k}=${options.locale}`;
|
|
|
|
|
if (seen.has(k)) {
|
|
|
|
|
if (DEBUG) console.debug(`[cloakbrowser] Arg override: ${seen.get(k)} -> ${flag}`);
|
|
|
|
|
}
|
|
|
|
|
seen.set(k, flag);
|
2026-03-05 07:03:57 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return [...seen.values()];
|
|
|
|
|
}
|