Skip to content

fix: make the browser bridge actually connect (offscreen path + popup status) + e2e verified - #1

Merged
karngyan merged 4 commits into
mainfrom
fix/browser-connect-e2e
Jul 4, 2026
Merged

fix: make the browser bridge actually connect (offscreen path + popup status) + e2e verified#1
karngyan merged 4 commits into
mainfrom
fix/browser-connect-e2e

Conversation

@karngyan

@karngyan karngyan commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Summary

The extension could never connect to the MCP server — this branch fixes the root cause, makes the popup honest about status, and adds the logging that surfaced the bug. The full tool loop is now verified end-to-end against a real browser.

Bugs fixed

  • Offscreen doc 404 (connection blocker). background.ts called createDocument({ url: "offscreen.html" }), but crxjs emits the file at dist/src/offscreen.html (same src/ prefix as popup + worker). The bad path 404'd → the offscreen document never loaded → its onMessage listener never registered → offscreen:connect had no receiver ("Could not establish connection. Receiving end does not exist."). The WebSocket was never even dialed. Fixed the path.
  • Popup stuck on "Connecting…". The popup set connecting on submit and never updated, even after the bridge connected and authed. It now polls the worker for status on open and live-listens for reins:status-update, so the pill transitions Connecting… → Connected (and reflects reconnects).

Also

  • feat(mcp): bridge stderr logging — the WS host was silent; added connect/auth/reject/close logging (stderr only, never stdout — that carries MCP). This directly surfaced both bugs above.
  • perf(extension): reconnect backoff cap 30s → 5s — a client that climbed backoff while the server was down could wait up to 30s to reconnect after it reappeared; 5s is prompt for a local-only socket.

Verification

  • lint, typecheck, test, build all green.
  • End-to-end proof: drove the real MCP server as a client against the loaded extension in a live Dia browser — list_tabs returned 11 real tabs, isError: false. Server exposes 14 tools (ping + the 13 documented).

Server log during the successful call:

reins-mcp: bridge listening on 127.0.0.1:8765
reins-mcp: connection from origin=chrome-extension://nbjbmo…
reins-mcp: authed (browser=reins-extension)

Follow-ups (not in this PR)

  • Worker-death status desync + reconnect soak → M4 hardening.
  • ping is a 14th tool; README documents 13 → doc nit.

🤖 Generated with Claude Code

karngyan and others added 4 commits July 4, 2026 18:30
The WS host was silent, so pairing/handshake failures were undebuggable.
Emit stderr lines (never stdout — that carries MCP) for listen, connect,
origin/token rejects, auth, client-replace, and close-with-code. These
directly surfaced the offscreen connect bug fixed in this branch.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
createDocument() used "offscreen.html", but crxjs emits the file at
dist/src/offscreen.html (same src/ prefix as popup + worker). The bad
path 404'd, so the offscreen document never loaded, its onMessage
listener never registered, and offscreen:connect had no receiver
("Could not establish connection. Receiving end does not exist"). The
WebSocket was never even dialed — the extension could never connect.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The popup set "Connecting…" on submit and never updated, so it hung on
that label even after the bridge connected and authed. Query the worker
for current status on open and live-listen for reins:status-update, so
the pill transitions Connecting… → Connected (and reflects reconnects).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The 30s cap meant a client that climbed its backoff while the server was
down could wait up to 30s to reconnect after the server reappeared.
Lower the cap to 5s so recovery is prompt for a local-only WebSocket.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@karngyan
karngyan merged commit 88c0a99 into main Jul 4, 2026
1 check passed
@karngyan
karngyan deleted the fix/browser-connect-e2e branch July 4, 2026 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant