# dsh-browser-firefox [English](README.md) | [中文](README.zh.md) A Firefox edition of the browser bridge for DeepSeek Harness. It lets the model read and operate the **Firefox tabs you are already using**, keeping your logins, sessions, and cookies intact. - **Silent background operation**: navigating and following links always opens a new tab — the current page is never replaced and never takes focus. - **Always on**: the extension stays resident and keeps the bridge connected as soon as it is loaded, no need to open the sidebar first. - **Per-conversation tab groups**: every dsh conversation owns one colour-coded tab group, named after the target domain (for example `bilibili.com`). - **Cards follow you**: question and approval cards appear in **whichever UI you touched last** — send a message in the sidebar and cards stay there, send one in dsh web and they move there. This project is a Firefox port of [Lum1104/dsh-browser](https://github.com/Lum1104/dsh-browser) (MIT), retaining the original author's copyright (see [LICENSE](./LICENSE)). --- ## What this is [dsh](https://github.com/deepseek-ai/deepseek-harness) (DeepSeek Harness) is DeepSeek's open-source, plugin-based agent framework. This repository ships the two components it needs: | Component | Location | Role | |---|---|---| | **bridge plugin** | `plugin/` | A local server (WebSocket bridge) installed inside dsh web | | **Firefox extension** | `extension/` | Installed in Firefox; performs the actual tab operations | Pages are rendered as structured text with a numbered inventory of interactive elements, and the model addresses elements by that number. When text cannot express what is on screen (images, charts, captchas), `browser_screenshot` sends the capture into the conversation as a **native image block**, so the model sees it directly. ## Getting started ### Step 1: install the bridge plugin > **Requirement**: dsh **≥ 0.2.3-alpha.2**. The WebServer route authentication and gateway contract changed in 0.2.3; earlier releases are skipped by dsh's compatibility check or leave the extension unable to connect. The plugin and the Firefox extension must be the same version, or a yellow version banner appears at the top of the sidebar. ```sh dsh plugin --profile web add dsh-browser-firefox@latest ``` **Restart `dsh web` after installing.** ### Step 2: install the Firefox extension The extension is published on addons.mozilla.org — install it directly: [dsh Browser Assistant](https://addons.mozilla.org/en-GB/firefox/addon/dsh-browser-firefox/) (or search for "dsh Browser Assistant" on AMO). ### Step 3: enter the token (first run only) ```sh cat ~/.dsh/ext-bridge-token # copy the output ``` Open the extension sidebar → ⚙️ settings (top right) → paste the value into **Token** → save and connect. Leave the bridge address empty; it is discovered automatically (see "Port discovery" below). > **Why Firefox always needs the token (since 0.3.1, a security tightening matched to upstream)**: a Firefox extension's `moz-extension://` origin is a per-install random UUID, so it cannot identify the extension. The bridge therefore requires every Firefox client to present the token. If it is missing or wrong, the panel shows a "token required" banner that walks you through it. ### Verify ```sh # the discovery endpoint should return the WS address curl -s http://127.0.0.1:3080/ext/bridge-config # => {"wsUrl":"ws://127.0.0.1:3080/ext/bridge"} ``` **Port discovery**: the extension probes, in order, `3080`, `3081`, `3090` (the usual `dsh web` ports), `14389` (a legacy port), and `43189`–`43198` (the plugin's discovery beacon range). If dsh runs somewhere else, type `ws://127.0.0.1:` into the extension settings. ## Updating The plugin and the extension **must stay on the same version**, so update both together: - **Plugin**: `dsh plugin --profile web add dsh-browser-firefox@latest`, then restart `dsh web` - **Extension**: update from addons.mozilla.org, or reload a fresh build via `about:debugging` When the versions differ, a yellow banner appears at the top of the sidebar (the two ends exchange versions during the handshake). The sidebar's **settings page "versions" card** also lists the current extension and plugin versions and points at any newer release on addons.mozilla.org. When building the extension from source, use `extension/manifest.example.json` as the template and keep `permissions` and the CSP `connect-src` in sync (the real `manifest.json` contains a personal Gecko ID and is not committed): a template missing `webNavigation` loses aggregated iframe snapshots, and one missing `https://addons.mozilla.org` gets its update check blocked by CSP. ## Capabilities | Capability | Tool | Notes | |---|---|---| | Read a page | `browser_snapshot` | Structured text snapshot: title/URL/main text/numbered controls/form fields (sensitive values masked); `delta: true` returns only changes; `region` reads one area; iframes are aggregated (main frame gets 80% of the budget, other sections follow) | | Click an element | `browser_click` | Click by number; an http/https link **opens a background tab** instead, anything else is a normal click | | Fill a form | `browser_type` | Type text; `replace` clears the field first | | Press keys | `browser_press` | Enter / Tab / Escape / arrows, and so on | | Scroll | `browser_scroll` | Viewport scroll (up/down/top/bottom) | | Navigate | `browser_navigate` | **Opens a silent background tab**; the current page is not replaced | | History | `browser_back` / `browser_forward` | Back/forward within the current tab | | Reload | `browser_reload` | Reload the current tab | | Read a region | `browser_get_text` | Lazy-loaded content or partial text | | Wait | `browser_wait` | Waits for load and render stability | | Screenshot | `browser_screenshot` | Captures the current viewport (visual fallback); the image reaches the model as a native image block. `fullPage` / `region` are reserved placeholders, not implemented yet | | DOM operations | `browser_evaluate` | A **fixed set of precompiled operations** (Firefox forbids injecting arbitrary JS): `count` / `getText` / `click` / `setValue` / `querySelectorAll`, addressed by CSS selector, with `index` and `frame` | | List tabs | `browser_list_tabs` | Lists every tab in this conversation's group (`*` marks the working tab) | | Open a tab | `browser_open_tab` | Opens a background tab (grouped) and returns its id | | Follow a tab | `browser_follow_tab` | Later operations target the given tab | | Close a tab | `browser_close_tab` | Only closes tabs this conversation opened or adopted; the user's own tabs are refused | ### Question cards When the assistant asks via `ask_user_question`, the card appears at the bottom of the sidebar — choose, type, or dismiss it right there without switching to dsh web. **Cards appear in whichever UI you drove last.** The bridge can see which path sent a session's latest message: sidebar messages cross the bridge, dsh web messages only reach the host log. So: - you sent a message **in the sidebar** → the card goes to the sidebar - you sent a message **in dsh web** → the card goes to dsh web - the sidebar **is not open** → the card always goes to dsh web Questions asked inside a subagent still surface on the parent conversation, so nothing is lost. When pending items belong to other conversations the sidebar offers a one-click jump, and several items in one conversation show a remaining count. > **Known limitation**: the plugin cannot tell whether the dsh web window is in the foreground. If you switch from the sidebar to dsh web without sending a message, the card still goes to the sidebar. `answerTimeoutMs` (10 minutes by default) bounds this — an unanswered card settles as "the user did not answer" instead of stalling the turn forever. ### Approval cards When the host needs a permission decision (a tool-call approval, a permission prompt), the card appears in the sidebar: it names the tool and the reason, and "Allow once" or "Reject" settles that decision without switching to dsh web. Routing follows the same rule as question cards. Approvals that arrive while the sidebar is closed are cached and replayed when it reopens; a dropped bridge falls back to dsh web. ### Permission level The shield button in the composer picks the permission level — Locked (hands off the page) / Read-only (the default: read but do not act) / Read-write (fully automatic). The button is tinted by the current level (Locked = red, Read-write = amber), and a refused call tells the model the current level and how to change it. ### Attachments The paperclip button in the composer adds images (through the host's multimodal channel; count and size limits follow the host projection) and **any other file**. Non-image files are uploaded verbatim to the local DSH host and referenced by a prompt receipt; DSH's own tools and skills decide whether and how to read them, including Office/PDF rendering and images inside documents. The extension does not parse documents or inline their text, so attachments stay compact cards. Files are capped at 20 MiB. Pasting works too. Images in message history are read back through `session/attachment`, and clicking one enlarges it. ### Silent background operation `browser_navigate` and link clicks both open tabs with `active: false` — Firefox **stays on the current page**. The extension keeps a "working tab" internally, and later `browser_snapshot`, clicks, and other operations act quietly on that background tab. If the working tab has been closed, later operations report "the working tab was closed, take a new snapshot" instead of silently switching to another page — element numbers belong to one specific page, and acting on a different one would click the wrong thing. ### Always on A Firefox MV3 background page is an event page that idles out after 45–90 seconds. This extension keeps three staggered alarms (one every 20 seconds) alive so the background stays resident and the WebSocket bridge stays connected — the agent can operate the browser at any time without opening the sidebar first. ### Screenshots (visual fallback) When the page is an image, a formula, a captcha, or anything else text cannot express, the model can call `browser_screenshot`: the capture is stored in the host's attachment store and returned as a **native image block** (DeepSeek routes with vision read it natively; text-only routes get the host's automatic placeholder). No local temporary file is produced. ### Per-conversation tab groups Every dsh **conversation owns one Firefox tab group**: tabs opened by navigation or link clicks inside that conversation join the same group, colours are assigned automatically (blue/green/red/purple, cycling), and **the group is named after the target domain** (with `www.` stripped, such as `bilibili.com`) — different conversations get different colours and domains, and continuous work stays together. ## Configuration Plugin configuration lives in the `bridge-browser` row of the profile's `cordis.patch.yml` (`~/.dsh/profiles/web/cordis.patch.yml`): | Field | Default | Meaning | |---|---|---| | `token` | generated | Fixed bearer token. When empty, one is generated on first boot and persisted to `~/.dsh/ext-bridge-token` (`0600`) | | `toolTimeoutMs` | `60000` | Timeout for one browser tool call | | `snapshotMaxChars` | `12000` | Character ceiling for one rendered snapshot (protects the model context) | | `maxInteractiveItems` | `120` | Interactive-element ceiling for one snapshot | | `sessionWorkspacePath` | `~/.dsh/browser-sessions` | Workspace used for extension-created conversations. Empty disables grouping | | `deferSessionCreate` | `true` | Materialize a conversation only on its first message (opening the sidebar leaves no trace) | | `preferWebAnswerer` | `true` | When neither UI is known to be more active (a conversation with no messages yet), prefer dsh web | | `answerTimeoutMs` | `600000` | How long a card may wait before it settles (10 minutes); `0` disables the fallback | | `discoveryBeacon` | `true` | Bind a discovery beacon port (43189–43198) so an ephemeral-port Desktop instance stays findable | ## Architecture ``` sidebar panel (React) ◄─port─► background script ◄─WS─► dsh bridge plugin │ tabs.sendMessage (DSH_ACTION / DSH_RESOLVE_ELEMENT) ▼ content script (snapshot / actions / element resolution / privacy) ``` - **bridge plugin** (`plugin/`): token-authenticated WebSocket server, tool dispatch, conversation identity passthrough; mounts `/ext/bridge` (WS) and `/ext/bridge-config` (address discovery), plus a discovery beacon on 43189–43198 that tracks ephemeral ports. - **extension background** (`extension/src/background/`): bridge connection (exponential-backoff reconnect plus alarm keepalive), tool routing (navigation and links open grouped tabs in the background, everything else goes to the content script), tab group management. - **content script** (`extension/src/content/`): text-only snapshots, stable element numbers, element resolution, action execution, sensitive-field masking. - **panel** (`extension/src/panel/`): the React sidebar conversation UI, with sanitized Markdown rendering. - **protocol**: `plugin/src/protocol.ts` is the frame format shared by both ends (`tool.call` frames carry `expiresAt`/`sessionId`/`title`; on timeout or cancellation the server withdraws the call with `tool.cancel`). A `ui.attached` frame reports sidebar presence so the plugin can tell whether a card has somewhere to appear. The protocol carries a version number, and an older plugin closes the socket on an unknown frame, so both ends must match. ## Building from source Requires Node.js `>=26.12.1`, pnpm 11.x, and Firefox `>=140` (tab groups need it). > **After cloning**, run `cp extension/manifest.example.json extension/manifest.json` and change its `gecko.id` to a unique address of your own (AMO signing needs it; the repository never contains a personal manifest). ```sh pnpm install pnpm build # builds the bridge plugin, then the extension pnpm typecheck # type checking pnpm test # unit tests ``` Build outputs: | Component | Distribution | Local artifact | |---|---|---| | Plugin | published to npm (`dsh-browser-firefox`), installed with one command | `plugin/lib/` | | Extension | submitted to AMO (addons.mozilla.org) | `extension/dsh-browser-firefox.zip` (install package), `extension/dsh-browser-firefox-extension-source.zip` (source package for AMO review) | `pnpm build` does not produce the zips; package them by hand following the steps in [AGENTS.md](./AGENTS.md). ## Layout ``` plugin/ # dsh-side bridge plugin (npm package dsh-browser-firefox) src/ # sources (protocol / server / tools / questions / approvals) lib/ # build output cordis.patch.yml # plugin registration icon.svg # icon shown in the dsh plugin list extension/ # Firefox extension src/background/ # bridge connection / tool routing / group management src/content/ # snapshots / actions / element resolution src/panel/ # React sidebar _locales/ # localized manifest strings (zh_CN, en) src/browser.d.ts # browser.* type declarations manifest.json # Firefox MV3 manifest dist/ # build output dsh-browser-firefox.zip # load / submit package dsh-browser-firefox-extension-source.zip # source package scripts/install-firefox.sh # one-shot setup on another machine README.md / README.zh.md / PRIVACY.md / LICENSE package.json / pnpm-workspace.yaml / pnpm-lock.yaml ``` ## Security - **The bridge path authenticates on its own token.** The bridge reaches the gateway as the host's owner principal, so non-loopback clients are confined to a **namespace allowlist** (`session` / `workspace` / `userQuestions`) and everything else is refused — including `terminal/*`, `dynamicCordisRunner/*`, `pluginManager/*`, `commands/execute`, and `workspaceFiles/*`, every one of which can run commands or code. Newly added host endpoints are refused by default. - **The Firefox extension always presents the token**: a `moz-extension://` origin is a per-install random UUID, so it is not an identity boundary. - **Page text is treated as untrusted**: every page-derived result (snapshots, region text, DOM reads) is wrapped in a boundary tagged with a random nonce before it reaches the model, so a page cannot forge the closing tag and inject instructions. This is defense in depth; the real gate for actions is still host approval plus the extension's permission level. - **Sensitive fields are masked**: passwords, card numbers, and similar inputs are masked to `••••` in snapshots (matched by field name, `aria-label`, associated `