From c281077b635f03c5846d1274159e60c557525adf Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 22 May 2026 00:59:37 +0000 Subject: [PATCH] Derive test UA from running browser instead of hardcoded Chrome/120 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The headless-detection-bypass UA in ublock/modalcloser/istilldontcareaboutcookies tests was a literal Chrome/120.0.0.0 string, so the fixtures aged with every Chrome upgrade and risked drifting noticeably from the real browser's UA. Read the actual UA via browser.userAgent() and strip the "Headless" / "HeadlessChrome" tokens — same fingerprint-evasion effect, no baked-in version to keep up to date. --- .../tests/test_istilldontcareaboutcookies.py | 4 +++- abx_plugins/plugins/modalcloser/tests/test_modalcloser.py | 7 +++++-- abx_plugins/plugins/ublock/tests/test_ublock.py | 4 +++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/abx_plugins/plugins/istilldontcareaboutcookies/tests/test_istilldontcareaboutcookies.py b/abx_plugins/plugins/istilldontcareaboutcookies/tests/test_istilldontcareaboutcookies.py index 7fbd287..42a61b0 100755 --- a/abx_plugins/plugins/istilldontcareaboutcookies/tests/test_istilldontcareaboutcookies.py +++ b/abx_plugins/plugins/istilldontcareaboutcookies/tests/test_istilldontcareaboutcookies.py @@ -413,7 +413,9 @@ def check_cookie_consent_visibility( {{ puppeteer, browserWSEndpoint: '{cdp_url}' }}, async (browser) => {{ const page = await browser.newPage(); - await page.setUserAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'); + const browserUa = await browser.userAgent(); + const realisticUa = browserUa.replace('HeadlessChrome/', 'Chrome/').replace(' Headless', ''); + await page.setUserAgent(realisticUa); await page.setViewport({{ width: 1440, height: 900 }}); console.error('Navigating to {test_url}...'); diff --git a/abx_plugins/plugins/modalcloser/tests/test_modalcloser.py b/abx_plugins/plugins/modalcloser/tests/test_modalcloser.py index acc53e5..31a40a1 100755 --- a/abx_plugins/plugins/modalcloser/tests/test_modalcloser.py +++ b/abx_plugins/plugins/modalcloser/tests/test_modalcloser.py @@ -562,8 +562,11 @@ def test_hides_cookie_consent_on_filmin(): }); const page = await browser.newPage(); - // Set real user agent to bypass headless detection - await page.setUserAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'); + // Set a non-headless UA derived from the actual browser to bypass headless detection + // without baking a Chrome version into source that will go stale on upgrade. + const browserUa = await browser.userAgent(); + const realisticUa = browserUa.replace('HeadlessChrome/', 'Chrome/').replace(' Headless', ''); + await page.setUserAgent(realisticUa); await page.setViewport({ width: 1440, height: 900 }); console.error('Navigating to filmin.es...'); diff --git a/abx_plugins/plugins/ublock/tests/test_ublock.py b/abx_plugins/plugins/ublock/tests/test_ublock.py index 2d866f5..9e86a8f 100755 --- a/abx_plugins/plugins/ublock/tests/test_ublock.py +++ b/abx_plugins/plugins/ublock/tests/test_ublock.py @@ -333,7 +333,9 @@ def check_ad_blocking(cdp_url: str, test_url: str, env: dict, script_dir: Path) {{ puppeteer, browserWSEndpoint: '{cdp_url}' }}, async (browser) => {{ const page = await browser.newPage(); - await page.setUserAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'); + const browserUa = await browser.userAgent(); + const realisticUa = browserUa.replace('HeadlessChrome/', 'Chrome/').replace(' Headless', ''); + await page.setUserAgent(realisticUa); await page.setViewport({{ width: 1440, height: 900 }}); // Track network requests