fix(cli): restore V3 network capture through a CDP sidecar - #2849
Open
shrey150 wants to merge 2 commits into
Open
fix(cli): restore V3 network capture through a CDP sidecar#2849shrey150 wants to merge 2 commits into
shrey150 wants to merge 2 commits into
Conversation
|
This was referenced Aug 28, 2026
shrey150
changed the base branch from
agent/browse-v4-4-runtime
to
agent/browse-v4-cli-cursor-overlay
August 31, 2026 21:41
This was referenced Aug 31, 2026
shrey150
force-pushed
the
agent/browse-v4-network-sidecar
branch
from
September 11, 2026 17:38
61cc82f to
7dd1978
Compare
shrey150
force-pushed
the
agent/browse-v4-network-sidecar
branch
from
September 11, 2026 18:23
7dd1978 to
adbe80d
Compare
shrey150
marked this pull request as ready for review
September 11, 2026 20:13
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 7 files
Architecture diagram
sequenceDiagram
participant User as Browse CLI User
participant CLI as Browse Command Handler
participant Manager as Driver Session Manager
participant Stagehand as Stagehand V4 Client
participant Browser as Remote Browser
participant Sidecar as CLI CDP Sidecar
participant Capture as Network Capture Writer
participant Files as Private Network Files
Note over User,Files: Browse V3-compatible network capture on Stagehand V4
User->>CLI: browse network on
CLI->>Manager: Get active page
Manager-->>CLI: V4 page with pageId
CLI->>Manager: Get browser CDP debugger URL
Manager->>Stagehand: Read browserWebSocketDebuggerUrl
Stagehand-->>Manager: Signed browser WebSocket endpoint
Manager-->>CLI: Endpoint kept internal
CLI->>Capture: enable(pageId, endpoint)
Capture->>Sidecar: attach(endpoint, pageId)
Sidecar->>Browser: Open one browser-level CDP WebSocket
Browser-->>Sidecar: WebSocket connected
Sidecar->>Browser: Target.attachToTarget(flatten, pageId)
Browser-->>Sidecar: CDP sessionId
Sidecar-->>Capture: Network CDP session
Capture->>Sidecar: Network.enable
Capture->>Sidecar: Register request and response listeners
CLI-->>User: enabled=true, network path
Note over Browser,Files: CDP events are routed through the flattened page session
Browser-->>Sidecar: Network.requestWillBeSent
Sidecar-->>Capture: Request event
Capture->>Files: Write request.json and allocate counter directory
Browser-->>Sidecar: Network.responseReceived
Sidecar-->>Capture: Response metadata
Capture->>Sidecar: Network.getResponseBody
Sidecar->>Browser: Fetch response body
Browser-->>Sidecar: Body or CDP error
Sidecar-->>Capture: Response body result
Capture->>Files: Write response.json when available
alt Concurrent network on requests
User->>CLI: browse network on
CLI->>Capture: enable(...)
Capture-->>CLI: alreadyEnabled=true
else CDP sidecar connection failure
Sidecar-->>Capture: Connection or command error
Capture-->>CLI: network sidecar error
CLI-->>User: Capture enable failed
end
User->>CLI: browse network off
CLI->>Capture: disable()
Capture->>Sidecar: Remove registered listeners
Capture->>Sidecar: Network.disable
Sidecar->>Browser: Disable Network domain
Capture->>Sidecar: Target.detachFromTarget
Sidecar->>Browser: Detach page session
Sidecar-->>Capture: Page session detached
Note over Sidecar,Browser: Browser-level WebSocket remains open across off/on cycles
Capture-->>CLI: enabled=false, retained network path
CLI-->>User: Capture stopped
opt Later network on in the same Browse session
User->>CLI: browse network on
CLI->>Capture: enable(next pageId, same endpoint)
Capture->>Sidecar: Attach a new flattened page session
Sidecar->>Browser: Target.attachToTarget(flatten, pageId)
Capture->>Files: Continue from highest existing request counter
CLI-->>User: Capture resumed without overwriting files
end
User->>CLI: browse stop
CLI->>Manager: Close Browse session
Manager->>Capture: close()
Capture->>Sidecar: Disable and detach active page session
Capture->>Sidecar: Close browser-level WebSocket
Sidecar->>Browser: Close auxiliary CDP connection
Manager->>Stagehand: Close Stagehand client
CLI-->>User: Session stopped
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
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.
Summary
Restore Browse V3 network-capture behavior on Stagehand V4 through a CLI-private CDP sidecar, without committing core Stagehand, its protocol, or generated SDKs to a public network-event schema.
Stack (#2872)
--return-xpath; supported V3 parity/release checkpointArchitecture
on/off/sendsession shape.network off, remove listeners, sendNetwork.disable, and detach the page target.The request correlation and request/response JSON writer are inherited from the V3 CLI. No public protocol schema, extension, SDK, or generated-client changes are included. #2832 remains open outside the landing stack for that separate API-design discussion.
User-visible behavior
The V3 command and file surface is retained:
Each request directory contains
request.jsonand, when available,response.json, including the existing treatment of POST bodies, response bodies, failures, redirects, cache hits, and binary responses.E2E Test Matrix
Full post-propagation implementation verification ran against exact clean #2849 head
adbe80d8bbfc337fea9dc38e41a88da18c287046. Its seven-file network patch has the same stable patch ID (f062ac789108ddf640bc912776dafa210411f50c) as the previously stress-tested head, so the deterministic V3/V4 and MSN/CNN evidence below applies unchanged. Frozen install, fresh builds, focused/full tests, and the real Browserbase lifecycle were rerun onadbe80d8b. Current review-fix head9887732b6f0c32cdef0966ebfd2ac2c454321d4bchanges only the test helper timeout diagnostic; on that exact head, the targeted network-capture tests passed 2/2 and Browse formatting, ESLint, and TypeScript checks passed. The comparison CLI was the exact built V3 implementation at7365a20d52955c10d72606f2e6ddd74791609d13. Every CLI flow used a unique daemon directory; no pre-existing daemon was reused or stopped.pnpm install --frozen-lockfile; build extension, local Stagehand SDK, thenbrowsedistoutput.open → network on → eval(GET, cached GET twice, POST, redirect, binary, abort) → path → off → path → clear → stop[]; clear left 0 entries for both.Date, and fixture origin/port.browse network onsubprocesses launched together, followed by one marked navigation{ enabled: true }; the other returned{ alreadyEnabled: true, enabled: true }. The marked navigation produced exactly 1 request record with 1 unique request ID.network oncalls serialize and attach listeners once rather than duplicating capture.on → navigate → off → on → navigate → offwithout clearing000and001; both URLs remained present, and the SHA-256 of the firstrequest.jsonwas unchanged after the second cycle.0700;request.jsonandresponse.jsonwere0600;network clearleft 0 entries;browse stopreported stopped.network on → open Example Domain → offcycles in one session, then navigation with capture offopen --wait networkidleworked; final status was connected, initialized, and remote; stop completed.on → path → open → scroll → collect 12s → off → path → navigate while off → status → clearpnpm --filter browse lintadbe80d8b; passed again at current review-fix head9887732b6.pnpm --filter browse testwith isolated daemon directoryadbe80d8b: 27 files / 390 tests passed; focused network subset: 3 files / 30 tests passed. At current review-fix head9887732b6: targeted network-capture tests passed 2/2.The deterministic artifact comparison includes method, URL/path, request/response headers and bodies, status/status text, MIME type, resource type, error shape, counter naming, and file modes. The live stress test also observed GET/POST/OPTIONS, failures, base64 bodies, cross-origin documents, and request-only records for traffic still in flight at the bounded
offpoint.This matrix does not claim WebSocket-frame, SSE-message, service-worker, or every out-of-process-iframe edge-case coverage; those are outside the V3 JSON request/response file contract proven here.