Add cmux browser repl: a Playwright-shaped browser REPL for agents
Closed
LA
2mo ago+132873+132873+012345678901234567890123456789012345678901234567890123456789-37-37-01234567890123456789
Summary
Adds cmux browser repl, a persistent JavaScript REPL that agents use to drive cmux browser panes. It has one Playwright-shaped API with native input, budgeted accessibility snapshots and site tools. Design: docs/browser-repl/README.md; driver contract and guards: docs/browser-repl/driver-protocol.md.
- API: Playwright
page, locators, keyboard, mouse and events, plustabs,snapshot,screenshot, cookie-bearingfetch,fs/path/os,session,secretsandsites. Named sessions keep variables and tabs;cmux browser repl mcpserves a session over stdio MCP. - Snapshot: accessibility tree with refs bound to DOM nodes; nested and cross-origin frames and open and closed shadow roots inline; diffs with context;
interactiveandviewportmodes. Output is budgeted (20,000 characters printed, 25,000 per call, the rest spilled to a file). - Input and focus: native trusted events; hidden tabs render in an offscreen window. Agent work does not move the user's key window, workspace, pane, terminal focus or text: replayed keys never reach the terminal or menus, Tab cannot move focus out of a page, and dialogs, file choosers and popups that the agent's own input causes go to the agent.
- Tab states:
tabs.list()reportslive,hibernated,wakingorcrashed. A call on a hibernated tab wakes it off screen (bounded wait); a crashed tab fails with an error that says to callpage.reload(). - Guards (native, outside agent code): secrets are fill-only and redacted everywhere, including captures and typed TOTP codes; the domain policy covers every frame, fetch redirect hop and subresource; page and agent clipboard writes in session-created tabs go to a per-tab clipboard, never the system clipboard; each session has a private temp directory; cells, fetches and timers are bounded.
- Site tools: Google (Gmail, Docs, Sheets, Slides, Drive, Calendar, Search), YouTube, Slack, Notion, LinkedIn, X, GitHub, Linear, Jira, page assets, WebMCP and a secure sign-in sheet. Writes that reach other people are drafts until
{ confirm: true }.
Evidence
tests/browser-parity/gate.sh --app --app-runs 2on a fleet build of the final head (results in the merge receipt comment).- 156 differential cases against two reference agent browsers: 0 cases worse (
docs/browser-repl/parity-report.md,docs/browser-repl/edge-cases.md). Excluded: raw CDP (WebKit has none). - Snapshot performance at or ahead of a Playwright-based MCP server at p50 on large pages (
docs/browser-repl/performance.md). - Security: parallel static scans of the diff, two rounds, then fixes with red-first tests; remaining medium and low findings are in the follow-up issue.
- Live checks on a fleet Mac: focus unchanged through agent clicks, keys, Tab and Shift+Tab in focused and background workspaces; hibernated and force-discarded tabs wake; crashed tabs recover with
page.reload().
Review notes
- Private WebKit SPI behind runtime checks:
_frames:, resource-load delegate,_tryClose,_doAfterProcessingAllPendingMouseEvents:,_doAfterActivityStateUpdate:,_simulateMouseMove:,_WKContentWorldConfiguration.allowAccessToClosedShadowRoots, WebKit feature flags for the async Clipboard API. - The clipboard command redirect swizzles
+[NSPasteboard pasteboardWithName:]for WebKit callers only, bounded to one command. - Accepted gap: a page with a user gesture can still write the system clipboard through a frame whose document has not loaded (documented in Guards).
- REPL-driven tabs skip the insecure-HTTP prompt.
browser.repl.*socket methods are not allowlisted for remote relay. - The browser-parity Node suite is not part of CI; it runs through
gate.shon the fleet. CI adds only the CmuxBrowser package tests (about 15 s) and one app-host suite.
Changelog
- Added:
cmux browser repl, a persistent browser automation REPL for agents with native input, budgeted accessibility snapshots, guarded secrets and clipboard, and site tools.