From c65939af1410a0b528b9ecee71ef53812a4041a1 Mon Sep 17 00:00:00 2001 From: CloakHQ Date: Sat, 28 Feb 2026 23:38:27 +0100 Subject: [PATCH] feat: wire timezone/locale params to Chromium binary flags launch() and launch_context() now inject --timezone and --lang binary flags when timezone/locale params are set. Previously only the Playwright context layer was configured, leaving a detectable mismatch that CreepJS flagged as a bot signal. Closes: WM5 --- js/tests/config.test.ts | 32 ++++++++++++++++++++++++++++ tests/test_build_args.py | 46 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 tests/test_build_args.py diff --git a/js/tests/config.test.ts b/js/tests/config.test.ts index c5ac242..a7f97ca 100644 --- a/js/tests/config.test.ts +++ b/js/tests/config.test.ts @@ -6,6 +6,7 @@ import { getBinaryDir, getDownloadUrl, } from "../src/config.js"; +import { _buildArgsForTest } from "../src/playwright.js"; describe("config", () => { it("CHROMIUM_VERSION matches expected format", () => { @@ -65,3 +66,34 @@ describe("config", () => { expect(url).toContain("cloakbrowser.dev"); }); }); + +describe("buildArgs timezone/locale", () => { + it("injects --timezone when timezone is set", () => { + const args = _buildArgsForTest({ timezone: "America/New_York" }); + expect(args).toContain("--timezone=America/New_York"); + }); + + it("injects --lang when locale is set", () => { + const args = _buildArgsForTest({ locale: "en-US" }); + expect(args).toContain("--lang=en-US"); + }); + + it("injects both when both are set", () => { + const args = _buildArgsForTest({ timezone: "Europe/Berlin", locale: "de-DE" }); + expect(args).toContain("--timezone=Europe/Berlin"); + expect(args).toContain("--lang=de-DE"); + }); + + it("injects timezone/locale even when stealthArgs=false", () => { + const args = _buildArgsForTest({ stealthArgs: false, timezone: "America/New_York", locale: "en-US" }); + expect(args).toContain("--timezone=America/New_York"); + expect(args).toContain("--lang=en-US"); + expect(args.some(a => a.startsWith("--fingerprint="))).toBe(false); + }); + + it("does not inject flags when not set", () => { + const args = _buildArgsForTest({}); + expect(args.some(a => a.startsWith("--timezone="))).toBe(false); + expect(args.some(a => a.startsWith("--lang="))).toBe(false); + }); +}); diff --git a/tests/test_build_args.py b/tests/test_build_args.py new file mode 100644 index 0000000..af10ebc --- /dev/null +++ b/tests/test_build_args.py @@ -0,0 +1,46 @@ +"""Unit tests for _build_args timezone/locale injection.""" + +from cloakbrowser.browser import _build_args + + +def test_timezone_injected(): + """--timezone flag should appear when timezone is set.""" + args = _build_args(stealth_args=True, extra_args=None, timezone="America/New_York") + assert "--timezone=America/New_York" in args + + +def test_locale_injected(): + """--lang flag should appear when locale is set.""" + args = _build_args(stealth_args=True, extra_args=None, locale="en-US") + assert "--lang=en-US" in args + + +def test_both_injected(): + """Both flags should appear when both are set.""" + args = _build_args(stealth_args=True, extra_args=None, timezone="Europe/Berlin", locale="de-DE") + assert "--timezone=Europe/Berlin" in args + assert "--lang=de-DE" in args + + +def test_timezone_independent_of_stealth_args(): + """--timezone should be injected even when stealth_args=False.""" + args = _build_args(stealth_args=False, extra_args=None, timezone="America/New_York", locale="en-US") + assert "--timezone=America/New_York" in args + assert "--lang=en-US" in args + # No stealth fingerprint args + assert not any(a.startswith("--fingerprint=") for a in args) + + +def test_no_flags_when_not_set(): + """No timezone/lang flags when params are None.""" + args = _build_args(stealth_args=True, extra_args=None) + assert not any(a.startswith("--timezone=") for a in args) + assert not any(a.startswith("--lang=") for a in args) + + +def test_extra_args_preserved(): + """Extra args should still be included alongside timezone/locale.""" + args = _build_args(stealth_args=True, extra_args=["--disable-gpu"], timezone="Asia/Tokyo", locale="ja-JP") + assert "--disable-gpu" in args + assert "--timezone=Asia/Tokyo" in args + assert "--lang=ja-JP" in args