Commit graph

2 commits

Author SHA1 Message Date
Ryan Vogel
89e1975ba6 fix(browser-extension): keep the relay up when a WebSocket message is 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.
2026-10-18 18:16:01 -04:00
Ryan Vogel
0f0fd4243d feat(browser-extension): add OpenCode Browser, an extension agents control 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.
2026-10-18 18:16:01 -04:00