opencode/packages/browser-extension/cli
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
..
skills/browse feat(browser-extension): add opencode-browser-cli with the relay and browse MCP server 2026-10-18 18:16:01 -04:00
src fix(browser-extension): keep the relay up when a WebSocket message is too large 2026-10-18 18:16:01 -04:00
.gitignore feat(browser-extension): add opencode-browser-cli with the relay and browse MCP server 2026-10-18 18:16:01 -04:00
build.ts feat(browser-extension): add opencode-browser-cli with the relay and browse MCP server 2026-10-18 18:16:01 -04:00
bun.lock feat(browser-extension): add opencode-browser-cli with the relay and browse MCP server 2026-10-18 18:16:01 -04:00
package.json feat(browser-extension): add opencode-browser-cli with the relay and browse MCP server 2026-10-18 18:16:01 -04:00
tsconfig.json feat(browser-extension): add opencode-browser-cli with the relay and browse MCP server 2026-10-18 18:16:01 -04:00