# claude-firefox A Firefox extension and MCP server that let Claude Code read and drive pages in your browser. TypeScript end to end, strict. Not affiliated with Anthropic or Mozilla. ## Why it is not a port of the Chrome extension Firefox differs from Chrome in two ways that decide the architecture, both measured on **Firefox 153.0.1** rather than assumed: | | Chrome | Firefox | |---|---|---| | Keeping the background alive | WebSocket activity extends the service worker (116+); `connectNative` keeps it alive (105+) | Neither. The event page dies at **exactly 30s** unless an *extension* event wakes it — DOM activity such as `fetch` does not count | | `ws://` to a local server | Works | Upgraded to `wss://`, fails TLS, **close code 1015** | So this uses **SSE down, POST up** — which is MCP's own HTTP+SSE transport — and a **20-second alarm** as the keepalive. `EventSource` reconnects and replays `Last-Event-ID` on its own, so resume is the spec's job, not ours. The server queues commands and the extension drains on reconnect: a suspended event page delays a command, it never drops one. ## Architecture ``` Claude Code ──stdio(MCP)──> server (Node/TS) │ GET /events SSE, commands out │ POST /result results in ▼ extension (MV3 event page) ──connectNative──> native host EventSource + fetch + 20s alarm reads ~/.claude-firefox/token │ tabs.sendMessage ▼ content script a11y refs, actions, observers, indicator │ window.postMessage ▲ page-world script (page.js) console, fetch and XHR in the page's own realm ``` Each Claude Code session spawns its own server, but only one ever needs to own the port and talk to the extension. The first to bind it is the **leader**; every later session becomes a **follower** and forwards its tool calls to the leader instead, tagged with its own session id so the extension keeps each session's tabs in their own group. If the leader's session ends, the next follower to make a call takes over the port automatically — no restart, no re-pairing. That last hop exists because Firefox gives a content script Xray vision onto the page: `console` and `XMLHttpRequest` in that scope are the sandbox's own, and `window.fetch = …` there only makes an expando the page never sees. So capture is split. The content script reads resource timings through `PerformanceObserver` — the page's timeline, and `buffered: true` replays what loaded before injection — while a web-accessible script running in the page's realm supplies the console output plus the methods and status codes timings do not carry. Anything can postMessage to a page, so each message is checked for `event.source === window`, the namespaced tag, and its field types before it is believed. The token never passes through a UI. The extension asks a native messaging host for it, and Firefox spawns that host only for the extension ID named in the host manifest's `allowed_extensions`. ## Install ```sh pnpm install pnpm build ``` Install the native messaging host — the extension's only source of a token — and print the MCP registration: ```sh node dist-server/index.js --setup ``` Run the `claude mcp add` line it prints. **On Windows it also prints a `reg add` line**: Firefox finds native hosts through `HKCU\Software\Mozilla\NativeMessagingHosts` rather than a directory, and `--setup` will not write to your registry for you. The manifest and its `.bat` launcher go to `%APPDATA%\claude-firefox\`; the registry value points at the manifest. Load `dist/` in Firefox (`about:debugging` → This Firefox → Load Temporary Add-on → `manifest.json`, or `pnpm start`), then start a Claude Code session. That is the whole setup. The extension asks the native host for the port and token on its first run and stores them; there is nothing to type, and no code anywhere. The token persists, so a server restart does not need re-connecting. If the popup still says it is not set up, it names which of the two steps is outstanding: the host is not installed (`--setup` never ran, or on Windows the registry key is missing), or it is installed but no Claude Code session has minted a token yet. The port lives under **Advanced** in the popup, shown rather than set: the server names it when it pairs. Change it with `CLAUDE_FIREFOX_PORT` on the server and pair again. ### What the token is actually for The token lets its holder impersonate the browser: attach to `/events`, take the command stream, and `POST /result` with fabricated page content, steering the agent with lies about what is on screen. What it defends against is narrow: | Attacker | Stopped by | |--------------------------------|------------------------------------------------------------------------------------| | A web page | The `Origin` check. Pages cannot forge it, and get no CORS headers back either way | | A local process running as you | **Nothing here.** It reads `~/.claude-firefox/token` directly | | Another installed extension | The native host's `allowed_extensions` — Firefox will not spawn the host for it | That last row is why there is one way in and not two. The manifest names exactly one extension ID, and the enforcement is the browser's, not ours. A second path — anything a user could copy into another extension's UI — would be weaker than the guarantee it sat beside, so it was removed. ## Site access Nothing is granted at install. The first time a tool tries to act on an origin nobody has decided about yet, a small popup opens asking you to allow or decline it — `permissions.request()` needs a user gesture, which an event page does not have, so that click has to happen in a window of its own rather than in response to the call itself. The tool call waits up to 30 seconds for an answer; no answer counts as declined. An origin you have already allowed or denied is never asked again, and a call against one still awaiting a first decision returns `PERMISSION_REQUIRED` if the popup times out or nothing is there to answer it. **Allow all sites**, under Advanced in the options page or as a third option on any per-site prompt, requests Firefox's own `` permission in one click instead of one per origin — the same permission every per-site grant already draws from, just asked for in full at once. Revoked automatically the next time the connection is reset; revoking it by hand also forgets every individually approved site, since leaving those granted would otherwise go on allowing them. Administrators can block origins with the managed-storage key `blockedUrlPatterns`; the managed list overrides any user approval. Firefox reads managed storage from enterprise policy rather than a bundled schema file, so the shape is: ```json { "policies": { "3rdparty": { "Extensions": { "claude-firefox@faran52.github.io": { "blockedUrlPatterns": ["bank.example.com", "*.internal.corp"] } } } } } ``` ## Tools Nineteen, and they carry Claude-in-Chrome's names and parameter spellings so the habits Claude already has work here unchanged. `read_page` is the one to start with: it returns the page as an accessibility tree with stable refs. ``` main [ref_1] heading "Sign in" [ref_2] textbox "Email" [ref_3] type="email" placeholder="you@example.com" button "Continue" [ref_4] disabled ``` Every element-addressing tool takes that `ref`, or a coordinate in the pixels of the last screenshot. A ref whose node has gone returns `STALE_REF`, so the model re-reads the page rather than acting on whatever now sits in that position. **Read** `read_page` `get_page_text` `find` `page_info` **Act** `computer` `form_input` **Navigate** `navigate` `reload` `resize_window` **Tabs** `tabs_context_mcp` `tabs_create_mcp` `tabs_close_mcp` **Wait** `wait_for` **Observe** `read_console_messages` `read_network_requests` **Files** `file_upload` `upload_image` **Batch** `browser_batch` **Record** `gif_creator` `computer` is the coordinate-driven one: thirteen actions — `screenshot`, `left_click`, `right_click`, `double_click`, `triple_click`, `left_click_drag`, `hover`, `scroll`, `scroll_to`, `zoom`, `type`, `key`, `wait` — addressed by `ref` or by `coordinate` in screenshot pixels, which the extension maps back to CSS pixels per tab. There is deliberately **no way to execute code in a page**. See [Known limitations](#known-limitations). ## Privacy The add-on sends page content and tab URLs to a local server on `127.0.0.1` and nowhere else, only for origins you allowed. It redacts password, credit-card and one-time-code fields before describing a page. There is no telemetry, account, backend or remote runtime code. ## Development ```sh pnpm check # lint + typecheck + build + test pnpm start # load dist/ in a scratch Firefox profile ``` Tests run the real server as a subprocess and speak real MCP over stdio against a real SSE stream — everything between Claude Code and the browser is exercised, with only Firefox simulated. The current build has no recorded successful run against a real Firefox. Before release, manually check native messaging and pairing, the permission prompt inside the toolbar click, event-page suspension and wakeup, synthetic input on real sites, and screenshot coordinates on a retina display. `web-ext lint` validates the package statically; it does not load the extension. ## Known limitations - **No code execution in a page.** There is no `javascript_tool` and no `eval` anywhere. AMO's remote-code policy forbids running model-supplied strings, and no framing makes that acceptable. `read_page`, `get_page_text` and `find` cover what it was used for. - **`find` scores locally.** Chrome sends the tree to a small model to rank matches; there is no Anthropic client here, so this is token overlap over role and accessible name, with interactive elements boosted. Same output format, weaker ranking. - **`read_console_messages` starts at `document_idle`.** Nothing logged before the content script runs is recoverable — there is no buffered replay for console the way `PerformanceObserver` provides one for requests. Early *requests* do show up, without their method or status. - **Failover has a brief window.** A follower only notices the leader is gone, and promotes itself, on its next tool call — a session that is idle at that exact moment waits out one timeout first. `CLAUDE_FIREFOX_PORT=0` opts a session out of this entirely: an ephemeral port is never the same twice, so nothing else can find it to become a follower of it. - **The keepalive interval is version-observed.** If a future Firefox clamps sub-minute alarms the way Chrome does, worst-case latency becomes the clamped period. Correctness is unaffected — the queue covers it. - **The name invokes two trademarks.** AMO rejects add-ons implying affiliation, so a listing may need a different display name. Local install and self-hosting are unaffected. - **No browser e2e yet.** Firefox-specific behavior still requires the manual checks above. ## Licence MIT.