companion: drive your real Chrome via an extension, not Playwright#49
Merged
Conversation
The companion drove the user's live Chrome by launching it with Playwright against their real profile. That's fundamentally unstable — Chrome wants to own its profile exclusively, so every recent fix fought the same root problem: profile locks (must Cmd-Q Chrome first), the mock-keychain making sites look logged-out, and stripping disruptive launch flags one by one. Replace it with an MV3 extension that runs inside the user's already-open Chrome and drives the active tab via chrome.debugger (CDP). Nothing is launched or locked, so that whole class of bugs disappears and the user can keep browsing while the agent works. Architecture — only the laptop end of the link changes; the server is untouched. `zero browser connect` runs a loopback WebSocket bridge and forwards each BrowserAction to the extension, which executes it and returns a byte-identical BrowserResult. The CDP action logic (a11y-tree snapshot with stable [ref=eN] ids, stale-ref recovery, incremental diff, replMode evaluate with console capture) is ported from server/lib/browser/host-pool.ts, plus the CDP-trivial actions (hover/scroll/back/forward/reload/select). - extension/: MV3 package (manifest, worker, build → embedded asset module) - bridge-engine.ts: loopback WS server, secret handshake, id-correlated command/response, 20s keepalive for the MV3 worker, hardened teardown - chrome-launch.ts: one-time quit + relaunch with --load-extension --restore-last-session (macOS full; Windows/Linux best-effort) - runner.ts/companion.ts: use BridgeEngine; new connect UX and --no-launch - delete engine.ts + playwright-setup.ts; drop Playwright from the CLI bundle Verified: both packages build and typecheck; the bridge wire protocol (handshake, command/response, bad-secret rejection, keepalive, teardown) passes an end-to-end simulated-extension smoke test.
This was referenced Jun 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The companion drove the user's live Chrome by launching it with Playwright against their real profile. That's fundamentally unstable — Chrome wants to own its profile exclusively, so every recent fix fought the same root problem: profile locks (must
Cmd-QChrome first), the mock-keychain making every site look logged-out, and stripping disruptive launch flags one at a time.What
Run an MV3 extension inside the user's already-open Chrome and drive the active tab via
chrome.debugger(CDP). Nothing is launched or locked, so that whole class of bugs disappears — and the user can keep browsing while the agent works.Only the laptop end of the link changes; the server is untouched.
zero browser connectruns a loopback WebSocket bridge and forwards eachBrowserActionto the extension, which executes it and returns a byte-identicalBrowserResult.The CDP action logic — a11y-tree snapshot with stable
[ref=eN]ids, stale-ref recovery, incremental diff, replMode evaluate with console capture — is ported fromserver/lib/browser/host-pool.ts, plus the CDP-trivial actions (hover/scroll/back/forward/reload/select).Changes
extension/— MV3 package:manifest.json,src/worker.ts,build.ts(bundles the worker → embedded asset module the CLI ships).bridge-engine.ts— loopback WS server, one-time-secret handshake, id-correlated command/response (90s timeout), 20s keepalive for the MV3 worker, hardened teardown.chrome-launch.ts— one-time quit + relaunch with--load-extension --restore-last-session(macOS full; Windows/Linux best-effort).runner.ts/companion.ts— useBridgeEngine; new connect UX and--no-launch.engine.ts+playwright-setup.ts; dropped Playwright from the CLI bundle.Verified
tsc --noEmitclean.wss.close()hang under bun).Not covered by automated checks (needs a live browser)
The
chrome.debuggeractions against a real page, the one-time relaunch UX, >5-min service-worker survival, and the full round-trip through the server. The CDP logic is a line-for-line port of the already-working host-pool path.Caveat
--load-extensionisn't persistent across a full Chrome quit, soconnectre-triggers the one-time relaunch whenever Chrome was fully closed since last time (it skips when the extension is already live). A Web Store / Load-unpacked install is the natural follow-up to remove even that.🤖 Generated with Claude Code