feat(browser): add --via-extension flag to bypass debugger detection on anti-bot sites#1769
Open
BruceLoveDecimal wants to merge 3 commits into
Open
feat(browser): add --via-extension flag to bypass debugger detection on anti-bot sites#1769BruceLoveDecimal wants to merge 3 commits into
BruceLoveDecimal wants to merge 3 commits into
Conversation
…on anti-bot sites Closes jackwener#1757 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- extension/src/cdp.test.ts: 8 unit tests for evaluateViaScripting() covering happy path, error propagation, empty results, and verifying chrome.debugger is not called - extension/src/background.test.ts: 4 integration tests for handleExec noDebugger path, including --frame conflict error and result forwarding - tests/e2e/browser-eval-via-extension.test.ts: 5 e2e tests using a fake daemon to verify CLI sends noDebugger:true, JSON output, --frame conflict exit code - fix(background): guard isDaemonSocketActive against undefined WebSocket (Node env) Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…lback on old extensions P1: Replace noDebugger:true on 'exec' action with a dedicated 'exec-via-scripting' action. Old extensions that don't recognise the action return 'Unknown action' rather than silently falling back to CDP — exactly the behaviour the flag is meant to avoid. P2: Detect CSP-related errors in evaluateViaScripting and surface a targeted hint explaining that --via-extension runs in the page's MAIN world and is subject to its CSP (sites blocking unsafe-eval will fail here, while CDP bypasses CSP by default). Update --via-extension help text to mention the limitation upfront. - protocol.ts: add 'exec-via-scripting' to Action union; remove noDebugger field - background.ts: split handleExecViaScripting() out of handleExec(); expose via __test__ - daemon-client.ts: add 'exec-via-scripting' to action union; remove noDebugger field - page.ts: send 'exec-via-scripting' action instead of exec+noDebugger - cdp.ts: rename error prefix to --via-extension; add CSP error detection - cli.ts: note CSP limitation in --via-extension flag description - tests: update all assertions to match new action name and error strings Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1757
Problem
opencli browser <profile> eval <js>currently routes all JS execution throughchrome.debugger.attach()(CDP). Sites like BOSS直聘 (zhipin.com) detect debugger attachment within ~100ms and immediately redirect the tab toabout:blank, makingevalimpossible even when the user is browsing the page normally.CDP attachment is detectable via multiple signals:
visualViewportreflowdebugger;statements actually pause execution once a debugger is attached (timing-detectable)Runtime.enablehas observable side effects onconsole/Function.prototype/ microtask timingSolution
Add a
--via-extensionflag that routes eval throughchrome.scripting.executeScript()(MAIN world) instead of CDP. This is the same mechanism used by ad-blockers and password managers — page JS cannot detect it without breaking itself for all normal extension users.Changes
extension/manifest.json"scripting"permissionextension/src/protocol.tsnoDebugger?: booleantoCommandinterfaceextension/src/cdp.tsevaluateViaScripting()— useschrome.scripting.executeScriptwithworld: 'MAIN'and an async indirect-eval wrapperextension/src/background.tshandleExec:noDebuggerroutes toevaluateViaScripting;--via-extension+--framereturns a clear errorsrc/browser/daemon-client.tsnoDebugger?: booleantoDaemonCommandsrc/browser/page.tsevaluateNoDebugger()methodsrc/types.tsevaluateNoDebugger?onIPagesrc/cli.ts--via-extensionoption tobrowser evalKnown Limitations (intentional for v1)
--via-extensionis not a drop-in replacement for the default CDP path:objectIdreferences you can re-use; scripting API returns plain values only--frameis unsupported — combining--via-extensionwith--framereturns a clear error message; frame support can be added later viachrome.webNavigation.getAllFramesconsoleinterception — the CDP path can observe page console output; this path cannotExecution World
The implementation uses
world: 'MAIN'so that eval can access page-side JS state (Vue/React instances,window.xxx, etc.). This is required for the primary use case (readingel.__vue__.jobListon zhipin.com).world: 'ISOLATED'support can be added as a follow-up flag if needed.Manifest Permission Note
Adding
"scripting"tomanifest.jsonwill prompt users to re-approve the Browser Bridge extension on next update. Worth calling out in release notes.E2E Test Results
Tested locally against zhipin.com:
--via-extension(4 consecutive evals — page never redirected):CDP path (reproduced the issue):
🤖 Generated with Claude Code