Skip to content

feat(browser-extension): add OpenCode Browser, an extension agents control over MCP - #52818

Closed
R44VC0RP wants to merge 3 commits into
devfrom
opencode-browser
Closed

R44VC0RP wants to merge 3 commits into
devfrom
opencode-browser

Conversation

@R44VC0RP

@R44VC0RP R44VC0RP commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

What this is

OpenCode Browser is a Chromium extension (Chrome, Edge, Brave, Opera, Vivaldi, Chromium, Helium, Arc) that lets AI agents use the user's real browser through the browse MCP tools: open and drive tabs with Playwright, take screenshots, capture network traffic, record, and hand off to the user for logins, 2FA, and payments. It has no chat UI; agents control it.

agent ── browse MCP (stdio) ── relay (127.0.0.1:19988) ── WebSocket ── extension ── chrome.debugger ── tabs
  • packages/browser-extension – the extension: relay link, agent tab groups (collapsed, at the start of the tab strip), idle agent tabs closing after 10 minutes, a toolbar button that lets agents use the current tab (or stops them), an in-page handoff banner, and a status page (also the options page).
  • packages/browser-extension/cli – the npm package opencode-browser-cli (own lockfile, outside the workspace): the relay, the browse MCP server, the opencode-browser CLI, and setup. It is Browser Control (anomalyco/browser-control 8c80ac2, MIT) ported in: renamed, on port 19988, accepting only OpenCode Browser's extension IDs.
  • execute uses patchright-core (Playwright's API without enabling CDP's Runtime domain, which pages can detect), and agent input is human-like by default (curved mouse paths, paced keys, gliding scroll).
  • Releasing is manual for now (npm publish in cli/, bun run package for the store zip); see the package README.

Install, and why there's no pairing

npx opencode-browser-cli install

This installs the CLI, adds the browse MCP server to opencode's global config, and copies the extension. If an unpacked build is already connected and older, it reloads it and checks the reload took effect. It then reports which browsers and profiles have the extension, and opens the Chrome Web Store listing when none does.

There's nothing to pair: the extension connects to the local relay, which only accepts OpenCode Browser's extension IDs (store mfnicocicmmlkpjnaffgihfjhdgjkdjg, unpacked afeafocngkodbmaipcngoamamfmekgfo).

How to test

  1. cd packages/browser-extension/cli && bun install && bun run build && node dist/cli.mjs install

  2. Load packages/browser-extension/dist unpacked (Developer mode → Load unpacked), or let install reload an already loaded copy. Its status page says Connected once an agent uses the tools.

  3. From an opencode session (restart it so it picks up the browse MCP server):

    • session_new
    • execute with await page.goto("https://news.ycombinator.com"); return page.title()
    • execute with return (await page.screenshot()).length
    • session_list

    A new agent tab group appears at the top of the tab strip.

  4. Click the toolbar button on one of your own tabs; the badge shows ON. status lists it as owner=user with its tab= id, for session_adopt({ tabId }). Click again to take the tab back.

  5. opencode-browser status shows the relay, the extension (with its build and origin), and every tab agents can use. ~/.local/share/opencode-browser/logs/relay.log has the details.

What was removed, and why

Earlier revisions of this PR also had a side panel:

  • a chat client for the opencode server, with a session picker;
  • multi-server pairing (a connect page redeeming opencode pair codes);
  • a per-prompt "browser context" message and a "share tab" strip;
  • site scripts, browsing-history and tab-request tools, which needed approval prompts in the panel.

All of that is gone. The extension is now only the piece agents control over MCP, which keeps it small (the built extension is about 90 KB, with no UI framework) and its permissions minimal.

Removed with it:

  • the sidePanel, userScripts, contextMenus, activeTab, nativeMessaging, downloads and webNavigation permissions, and the optional history/bookmarks/topSites/sessions permissions;
  • the keyboard shortcut, the native messaging host and the opencode plugin;
  • the @opencode/ui, @opencode/session-ui, @opencode/client, Solid and Tailwind dependencies;
  • the tag-triggered publish workflow.

install cleans up what earlier versions set up.

Fixed: relay crash on oversized messages

Reported with Browser Control (CLI 0.8.3, extension 0.0.25): the relay crashed with unhandled RangeError: Max payload size exceeded (WS_ERR_UNSUPPORTED_MESSAGE_LENGTH) and kept crashing until the extension was reloaded.

Cause: ws reports an oversized frame as an error event on the socket. The relay had no listener for it, so Node killed the process.

Fix:

  • The relay accepts messages up to 256 MiB, as Playwright does.
  • It logs socket and HTTP server errors instead of crashing.
  • The extension fails a single command whose result is too large, instead of sending it.

Checked on an isolated relay: a 240 MB CDP result passes, and a 260 MB client message gets a 1009 close while the relay stays up.

Also fixed while stripping it down: tab-capture recordings stopped after the first chunk, because the worker never answered the recording page's chunk messages.

Verification

  • Typecheck (extension and CLI), lint and build pass.
  • Clean headless Chrome: the extension loads, the status page connects, the worker logs no errors, and the payload tests above pass.
  • In Helium:
    • install: detection, reload with the build check, and an idempotent second run.
    • Through the browse MCP tools: session_new, execute (navigation, locators), a screenshot, session_list, a CDP recording and session_delete.
  • Not exercised end to end: a tab-capture recording, which needs a real toolbar click on the tab.

@R44VC0RP

R44VC0RP commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

@thdxr Here's why this PR adds opencode browser install, the options I considered, and why I went with this one.

The problem

The extension has to find the local opencode service: its URL, and the password from opencode service get password. An extension can't read files or run commands. The one way Chrome lets an extension talk to something local is native messaging, and that needs a small JSON file in each browser's NativeMessagingHosts folder pointing at a program to run. Something outside the extension has to write that file once. ChatGPT's extension works the same way: their desktop app writes com.openai.codexextension manifests.

What the command does

  • install writes that JSON file for each installed browser, plus a 1-line wrapper that runs opencode browser host.
  • host (started by the browser) answers one question: "what's the service URL and password?" It reuses the existing service registration and starts the service if it isn't running.
  • It also writes the plugin the extension ships (site scripts and browsing tools) into ~/.config/opencode/plugins, and adds the Browser Control MCP to the global config.
  • status and uninstall show and undo all of it.

It only adds code: about 500 lines in new files under commands/handlers/browser/ and services/browser-extension.ts, plus one spec entry and one handler entry. No new dependencies, and nothing existing changes behavior.

Options I considered

  1. No helper; paste the URL and password into the panel. This already works as a fallback ("Enter server manually"), but it's bad first-run UX. It breaks when the password or port changes, and it can't start the service.
  2. The service trusts the extension's origin and skips the password. Any local process can fake an Origin header, so this weakens auth for everyone. I don't want that.
  3. The desktop app registers the helper, like ChatGPT. That only works for desktop users; CLI-only users get nothing.
  4. A separate helper package (npx @opencode-ai/browser install). This keeps it out of the CLI, but it's one more thing to install and keep in step with the service's registration and password format. That's the code the CLI already owns.
  5. A command in the CLI (this PR). One step for anyone who has opencode, and it always matches the service it's finding.

If you'd rather not ship it in the CLI

I'm happy to go with 3 + 4 (the desktop app registers the helper automatically, with a standalone package for CLI users), or to hide the command and drop the MCP config step so it's only the bare helper. Let me know which you'd prefer.

@R44VC0RP
R44VC0RP marked this pull request as ready for review October 3, 2026 01:02
@R44VC0RP

R44VC0RP commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

@thdxr Update: I took opencode browser install out of the CLI. Setup is now a standalone npm package, npx opencode-browser-cli install (source in packages/browser-extension/cli), which uses the installed opencode service commands, so this PR no longer touches packages/cli. Releases go through a new publish-browser-extension workflow on browser-extension-v* tags.

@thdxr
thdxr changed the base branch from v2 to dev October 10, 2026 19:28
@R44VC0RP R44VC0RP changed the title feat(browser-extension): add OpenCode Browser feat(browser-extension): add OpenCode Browser, an extension agents control over MCP Oct 18, 2026
…ntrol over MCP

OpenCode Browser lets AI agents use the user's real Chromium browser
(Chrome, Edge, Brave, Opera, Vivaldi, Chromium, Helium, Arc). It has no chat
UI: agents drive it through the `browse` MCP server (added in the next
commit), which talks to it through a local relay:

  agent - browse MCP (stdio) - relay 127.0.0.1:19988 - WebSocket - extension

The extension (src/):
- background/agent-relay.ts: the WebSocket link to the relay. Runs its
  commands (CDP through chrome.debugger, tabs, groups, badges, tab-capture
  recordings) and reports tab events; reconnects with backoff; survives an
  extension reload or worker restart by re-attaching its tabs
  (debugger-hub.ts). Commands it doesn't know get an error reply instead of
  leaving the relay waiting.
- agent-groups.ts, tab-cleanup.ts: agent tabs are grouped under the session's
  name at the start of the tab strip, collapsed unless the user is looking at
  one; agent tabs nobody uses for 10 minutes close.
- background/index.ts: the toolbar button lets agents use the current tab, or
  stops them (badge ON / RUN / WAIT).
- content/page-status.ts: the in-page banner while an agent works or waits
  for a handoff (login, 2FA, payment), with Continue.
- status/ (welcome.html, also the options page): install command, relay
  connection, reconnect, close agent tabs, copy diagnostics.

Permissions: debugger, tabs, tabGroups, storage, alarms, offscreen and
tabCapture (recordings), <all_urls> (agents work on any site the user asks;
the banner content script). The manifest key pins the unpacked ID
(afeafocngkodbmaipcngoamamfmekgfo); the store build is
mfnicocicmmlkpjnaffgihfjhdgjkdjg. store/ holds the Web Store listing and
privacy policy; scripts/package.ts builds the store zip.

Verified: typecheck, lint, build; loaded in a clean headless Chrome (status
page connects, no worker errors) and in Helium, driven through the browse
MCP tools.
…browse MCP server

packages/browser-extension/cli is the npm package `opencode-browser-cli`, with
its own package.json and lockfile so its dependencies stay out of the
monorepo's. It is Browser Control (anomalyco/browser-control 8c80ac2, MIT)
ported into OpenCode Browser: renamed, on its own port (19988), accepting only
OpenCode Browser's extension IDs, with files under
~/.local/share/opencode-browser.

- The relay: a local CDP endpoint backed by the extension's chrome.debugger,
  shared by several clients, with named sessions that survive relay restarts
  and extension reloads, handoffs, recordings (CDP and tab capture), a flight
  recorder, network capture with a redacted HAR, secrets, and a journal.
  relay.log records lifecycle, connects (with the extension's build and
  origin), every HTTP request with its duration, and faults.
- The `browse` MCP server (stdio) and the `opencode-browser` CLI: execute
  (Playwright API through patchright-core, which never enables CDP's Runtime
  domain, so pages can't detect the debugger that way; pageConsole.start()
  opts one page into console capture), session_* (session_adopt also takes a
  Chrome tab id), network_*, recording_*, flight_recorder_*, secrets_*,
  tabs_cleanup, status, skill. The agent guide is skills/browse/SKILL.md.
- Human-like input (human-input.ts): curved, eased mouse paths, off-center
  clicks with a settle and hold, paced keys, gliding wheel scrolls.
  OPENCODE_BROWSER_HUMAN_INPUT=0 turns it off.
- Setup (setup.ts): `install` installs a pinned runtime, adds the `browse` MCP
  server to opencode's global config (with a fingerprint so opencode restarts
  it on updates), restarts an outdated relay, copies the unpacked extension and
  reloads a connected unpacked build only when it is older (checking the
  reload took effect), then reports which browsers and profiles have the
  extension and opens its Web Store listing when none does (unless headless,
  --no-open, or a browser couldn't be read). It removes leftovers of earlier
  versions (native messaging host, opencode plugin, `opencode-browser` MCP
  entry). `extension` and `uninstall` round it out.

Verified: cli typecheck and build; install on the user's machine (detected
Helium/Ryan as default with the unpacked build, Chrome unreadable under macOS
privacy protection, Arc without it; a second install neither restarts the
relay nor reloads the extension); through the browse MCP tools in Helium:
session_new, execute (goto, title, locators), screenshot, session_list,
a CDP recording, session_delete.
… too large

Reported with Browser Control (CLI 0.8.3, extension 0.0.25), whose relay this
is: the relay crashed on startup with "unhandled RangeError: Max payload size
exceeded (WS_ERR_UNSUPPORTED_MESSAGE_LENGTH)" when the extension sent an
oversized message, and kept crashing until the extension was reloaded.

ws closes a socket that exceeds maxPayload (100 MiB by default) and reports
it as an "error" event on that socket. The relay had no "error" listener on
the extension or CDP client sockets, so Node treated the event as unhandled
and the process died; the extension reconnected, resent, and crashed it again.

- The relay accepts messages up to 256 MiB, as Playwright's own CDP client
  does (large screenshots and response bodies come close to 100 MiB).
- The extension and CDP client sockets, and the HTTP server after it starts
  listening, log errors to relay.log (extension.error, client.error,
  http.error) instead of crashing; ws then closes the offending socket.
- The extension checks the size of what it sends (UTF-8 bytes, measured only
  when the text could be over the limit, and tolerating a result too large to
  serialize): an oversized command result fails that one command with "Result
  too large to send ... request less data" instead of breaking the connection
  and every command in flight; an oversized event is dropped and logged.

Verified against a relay and a headless Chrome on an isolated port: a 240 MB
CDP result now passes (it crashed the relay before); a client message over
256 MiB makes the relay log client.error and close that socket with 1009
while it stays up; an earlier 200 MB cap answered 210 MB with the "Result too
large" error. A result over ~256 MB crashes the extension's own process in
Chrome before it reaches this code (the relay stays up); that is a browser
limit.
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant