feat: full Firefox native support for browser bridge#1633
Open
liv10let wants to merge 1 commit into
Open
Conversation
Firefox extensions cannot open WebSocket connections to localhost, and Firefox MV3 content scripts are subject to the host page's CSP which blocks eval() after navigation. This PR addresses both issues and makes all user-facing messages browser-agnostic. ## Changes ### Extension — Firefox script execution fix (cdp.ts) - Use `world: 'MAIN'` in `browser.scripting.executeScript` to bypass page CSP restrictions on eval() after navigation (Firefox 128+) - Fall back to ISOLATED world for Firefox <128 - Add `IS_FIREFOX` / `USE_DEBUGGER` guards throughout CDP paths - Firefox-compatible helpers: screenshot via captureTab, no-op for unsupported features (setFileInputFiles, network capture, frame tree) ### Extension — HTTP polling transport (background.ts, daemon.ts) - Add HTTP polling endpoints to daemon: /ext/poll-register, /ext/poll, /ext/poll-result (Firefox blocks WebSocket to localhost) - Extension falls back to HTTP long-polling when WebSocket fails - Daemon accepts both WebSocket (Chrome) and polling (Firefox) connections ### Extension — Window lifecycle (background.ts) - Minimize background automation windows on Firefox to prevent focus steal - Close container windows after command completes instead of leaving blank placeholder tabs ### CLI — Browser-agnostic messages - New `src/browser-label.ts`: shared `getBrowserLabel()` utility reading `OPENCLI_BROWSER` env var (firefox/ff → "Firefox", else "Chrome/Chromium") - `AuthRequiredError` hint adapts to target browser - `opencli doctor` install instructions adapt to Firefox vs Chrome - `opencli profile` descriptions use generic "browser" instead of "Chrome" - Daemon profile-disconnected hint uses generic "browser" ### Extension — Browser compatibility layer - New `browser-compat.ts`: IS_FIREFOX flag, CDP_VERSION abstraction, origin prefix helpers, tabGroups no-op for Firefox - Separate Firefox manifest (manifest.firefox.json) with gecko settings - Build scripts: build-firefox.mjs, package-firefox.mjs Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Merged
15 tasks
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.
Summary
world: 'MAIN'inbrowser.scripting.executeScriptto bypass page CSP restrictions that blockeval()after navigation (Firefox 128+), with ISOLATED world fallback for older versions/ext/poll-register,/ext/poll,/ext/poll-result) to the daemon since Firefox blocks WebSocket connections to localhostOPENCLI_BROWSERenv varbrowser-compat.tsabstracts Chrome/Firefox differences (CDP version, origin prefix, tabGroups API)Motivation
OpenCLI's browser bridge was designed around Chrome's
chrome.debuggerCDP API and WebSocket extension communication. Firefox doesn't supportchrome.debuggerand blocks WebSocket tolocalhost, making the CLI unusable on Firefox. Additionally, Firefox MV3 content scripts are subject to the host page's CSP, which silently blockseval()after navigation — causing all adapter commands to returnundefined.Test plan
opencli bilibili favorite— works with Firefox cookiesopencli douban marks— works with Firefox cookiesopencli doctor— shows correct Firefox-specific diagnosticsFiles changed (21 files, +1388 -381)
src/browser-label.tsgetBrowserLabel()utilitysrc/errors.tsAuthRequiredErrorhint adapts to browsersrc/doctor.tssrc/cli.tssrc/daemon.tssrc/daemon-utils.tsisExtensionOrigin()accepts both origin prefixessrc/browser/bridge.tsgetBrowserLabel()extension/src/cdp.tsworld:'MAIN'fix + Firefox execution pathsextension/src/background.tsextension/src/browser-compat.tsextension/manifest.firefox.jsonextension/scripts/build-firefox.mjsextension/scripts/package-firefox.mjs🤖 Generated with Claude Code