From bf672ee7f9e78142ab3624e41b8f32e81e6634b4 Mon Sep 17 00:00:00 2001 From: leeguooooo Date: Sat, 28 Feb 2026 11:17:02 +0900 Subject: [PATCH] fix(stealth): avoid matchMedia Illegal invocation - bind MediaQueryList methods when proxied for prefers-color-scheme light patch - add regression test for addEventListener/removeEventListener - bump version to 0.14.0-fork.6 and sync Cargo metadata --- cli/Cargo.lock | 2 +- cli/Cargo.toml | 2 +- package.json | 2 +- src/stealth.test.ts | 12 ++++++++++++ src/stealth.ts | 8 ++++++-- 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/cli/Cargo.lock b/cli/Cargo.lock index cc854b2..4a0c0fd 100644 --- a/cli/Cargo.lock +++ b/cli/Cargo.lock @@ -4,7 +4,7 @@ version = 4 [[package]] name = "agent-browser-stealth" -version = "0.14.0-fork.5" +version = "0.14.0-fork.6" dependencies = [ "base64", "dirs", diff --git a/cli/Cargo.toml b/cli/Cargo.toml index e950f6a..6a8446b 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "agent-browser-stealth" -version = "0.14.0-fork.5" +version = "0.14.0-fork.6" edition = "2021" description = "Stealth browser automation CLI for AI agents with anti-bot evasions" license = "Apache-2.0" diff --git a/package.json b/package.json index d67627d..fe9e22b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "agent-browser-stealth", - "version": "0.14.0-fork.5", + "version": "0.14.0-fork.6", "description": "Stealth browser automation CLI for AI agents with anti-bot evasions", "type": "module", "main": "dist/daemon.js", diff --git a/src/stealth.test.ts b/src/stealth.test.ts index 890ea2e..c1663c9 100644 --- a/src/stealth.test.ts +++ b/src/stealth.test.ts @@ -127,12 +127,24 @@ describe('Stealth mode', () => { activeTextColor, prefersLight: matchMedia('(prefers-color-scheme: light)').matches, prefersDark: matchMedia('(prefers-color-scheme: dark)').matches, + lightListenerCalls: (() => { + try { + const mql = matchMedia('(prefers-color-scheme: light)'); + const handler = () => {}; + mql.addEventListener('change', handler); + mql.removeEventListener('change', handler); + return 'ok'; + } catch (error) { + return String(error); + } + })(), }; }); expect(signals.activeTextColor).not.toBe('rgb(255, 0, 0)'); expect(signals.prefersLight).toBe(false); expect(typeof signals.prefersDark).toBe('boolean'); + expect(signals.lightListenerCalls).toBe('ok'); }); it('exposes realistic mimeTypes/pdf/share signals', async () => { diff --git a/src/stealth.ts b/src/stealth.ts index c993a0f..11993bf 100644 --- a/src/stealth.ts +++ b/src/stealth.ts @@ -856,9 +856,13 @@ function patchPrefersColorSchemeHeuristic(): string { const patchMediaQueryList = (mql) => { if (!mql || typeof mql !== 'object') return mql; return new Proxy(mql, { - get(target, prop, receiver) { + get(target, prop) { if (prop === 'matches') return false; - return Reflect.get(target, prop, receiver); + const value = Reflect.get(target, prop, target); + if (typeof value === 'function') { + return value.bind(target); + } + return value; }, }); };