Skip to content

fix(cdp): forward real attach event so agent-driving works (H2 browserContextId regression)#7

Merged
wenkaifan0720 merged 1 commit into
mainfrom
fix/cdp-browser-context-id
Jun 23, 2026
Merged

fix(cdp): forward real attach event so agent-driving works (H2 browserContextId regression)#7
wenkaifan0720 merged 1 commit into
mainfrom
fix/cdp-browser-context-id

Conversation

@wenkaifan0720

Copy link
Copy Markdown
Collaborator

Follow-up to #6. The H2 relay rewrite synthesized Target.attachedToTarget with a hard-coded browserContextId: "", which Playwright's CRBrowser._onAttachedToTarget asserts is non-empty — so the brokered agent-browser (Node + Playwright) crashed on connect and every campus webview <verb> failed with "agent-browser daemon closed the connection."

Fix: on first connect, FORWARD the genuine browser-level attachedToTarget our active attach triggers (it carries the real, non-empty browserContextId and everything else Playwright expects) and cache that context id; only on RECONNECT (page already attached → no fresh event) do we synthesize, reusing the cached real id. The active attach still fires the event regardless of relay order, so #6's "No page found" fix is preserved.

Verified end-to-end in the firebase Campus build: campus webview snapshot returns full page accessibility trees for single and concurrent multi-tile drives against one shared cef_host.

🤖 Generated with Claude Code

…gression)

The H2 hardening rewrote the relay to actively Target.attachToTarget its page and
SYNTHESIZE the client's Target.attachedToTarget instead of forwarding the real
browser-level event. The synthesized event hard-coded `browserContextId: ""` — and
Playwright's CRBrowser._onAttachedToTarget asserts browserContextId is non-empty, so
`agent-browser` (Node + Playwright, brokered by Campus) crashed the moment it
connected:

  Unhandled rejection: Error: targetInfo: {"attached":true,"targetId":"..."}
    at assert (playwright-core/.../assert.js)
    at CRBrowser._onAttachedToTarget (.../crBrowser.js:147)

So every `campus webview <verb>` ("agent-browser daemon closed the connection") broke.

Fix: on first connect FORWARD the genuine browser-level attachedToTarget our active
attach triggers — it carries the real, non-empty browserContextId (and everything else
Playwright expects) — and cache that context id. Only on RECONNECT (page already
attached, so no fresh event fires) do we synthesize, now reusing the cached real
browserContextId. The active attach still triggers the event regardless of relay
creation order, so the original "No page found" fix is preserved.

Verified end-to-end: `campus webview snapshot` returns full page a11y trees for
single and concurrent multi-tile drives against one shared host.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@wenkaifan0720 wenkaifan0720 merged commit 3fa3bb2 into main Jun 23, 2026
1 check passed
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