refactor(cli): migrate Browse runtime and commands to Stagehand V4 - #2834
Open
shrey150 wants to merge 7 commits into
Open
refactor(cli): migrate Browse runtime and commands to Stagehand V4#2834shrey150 wants to merge 7 commits into
shrey150 wants to merge 7 commits into
Conversation
|
This was referenced Aug 27, 2026
shrey150
force-pushed
the
agent/browse-v4-4-runtime
branch
from
August 28, 2026 02:52
7e9c944 to
34c5c7d
Compare
This was referenced Aug 28, 2026
shrey150
force-pushed
the
agent/browse-v4-4-runtime
branch
from
August 31, 2026 21:37
df91115 to
389e2da
Compare
This was referenced Aug 31, 2026
shrey150
marked this pull request as ready for review
September 1, 2026 17:13
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 22 files
Architecture diagram
sequenceDiagram
participant CLI as Browse CLI Client
participant Daemon as Driver Daemon
participant Manager as Driver Session Manager
participant Factory as Stagehand V4 Browser Factories
participant BB as Browserbase
participant Browser as Browser or CDP Target
participant Stagehand as Stagehand V4 Session
participant Context as Browser Context and Pages
participant Page as Active Page and Locators
Note over CLI,Page: Browse runtime uses a daemon-owned session and Stagehand V4 browser lifecycle
CLI->>Daemon: Open or execute driver command
Daemon->>Daemon: Resolve session, target, and forwarded environment
Daemon->>Manager: Dispatch request
alt Managed local target
Manager->>Factory: localBrowser.launch(headless, Chrome args)
Factory->>Browser: Launch local browser
Browser-->>Factory: Browser handle
else Browserbase remote target
Manager->>Factory: browserbase.launch(apiKey, userMetadata, flags)
Factory->>BB: Create managed remote session
BB-->>Factory: Browser handle and session identity
Factory->>BB: Lookup debug URL
BB-->>Factory: Optional live-view URL
Factory-->>Manager: Browser and Browserbase identity
else Attached CDP target
Manager->>Factory: localBrowser.connect(cdpUrl)
Factory->>Browser: Attach to existing browser
Browser-->>Factory: Browser handle
end
Manager->>Stagehand: Stagehand.create(browser, logging off)
Stagehand->>Context: Resolve browser context
Context-->>Manager: Context and page collection
Manager-->>Daemon: Session initialized
Daemon-->>CLI: Open result, mode, pages, and session identity
CLI->>Daemon: Navigation, query, input, tab, or runtime command
Daemon->>Manager: Dispatch command
Manager->>Context: Resolve active or requested page
Context-->>Manager: Active page
Manager->>Page: Call V4 page API
alt Standard command succeeds
Page->>Page: Navigate, query locator, click, fill, select, type, screenshot, eval, or manage tabs
Page-->>Manager: Result
Manager-->>Daemon: Command response
Daemon-->>CLI: Result data
else Coordinate XPath requested
Page-->>Manager: Error: coordinate XPath unavailable in V4
Manager-->>Daemon: Explicit capability error
Daemon-->>CLI: Command failure
else Cursor or network capability requested
Manager-->>Daemon: Explicit unavailable capability error
Daemon-->>CLI: Command failure
end
Note over Daemon,Manager: Open requests allow browser initialization time plus the configured navigation timeout
CLI->>Daemon: Stop session
Daemon->>Manager: Close session
Manager->>Stagehand: Close Stagehand session
Manager->>Browser: Close owned browser
alt Attached CDP target
Manager->>Browser: Preserve externally owned browser
else Managed local or Browserbase target
Browser-->>Manager: Owned resources cleaned up
end
Manager-->>Daemon: Session stopped
Daemon-->>CLI: Stop result
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
Migrate Browse's browser lifecycle and standard command surface together from Stagehand V3 to V4.
Stagehand.create().act()path.Stack (#2872)
--return-xpath; supported V3 parity/release checkpointReview shape
The lifecycle and command migration remain two ordered implementation commits:
389e2dae6— V4 browser/session foundation and lifecycle ownership.b45167462— standard command translation on that foundation.They are one PR because both commits rewrite the same nine command/test files. Reviewing their combined final diff avoids temporary deletion/stubbing followed by reimplementation, while the commits still provide useful lifecycle-versus-command checkpoints. Review follow-up
24178275fadds narrowly scoped ownership, error-sanitization, and timeout guards. The resulting PR diff is 23 files, +988/−436.Cursor DOM injection and private CDP network transport remain separate because they are independently reviewable mechanisms and cleanly additive diffs. The legacy coordinate
returnXPathrequest is still accepted here but fails explicitly until #2835 removes the option. This remains an intentionally non-publishable intermediate head.E2E Test Matrix
The actual built CLI on final head
24178275fwas rerun against a deterministic synthetic page in a real Browserbase browser. Attached-browser ownership was separately exercised against a real external Chromium CDP endpoint.browse open <synthetic-data-url> --remote;browse statusbrowse getwith CSS and XPath<h1>returnedReadybrowse fill;select;click;is;highlight;wait;viewport;screenshotAda, selectedb, checkbox checked, click resultClicked; screenshot 9,391 bytesbrowse tab list;tab new;tab closebrowse stop; thenbrowse cloud sessions get <redacted-id>COMPLETED--cdp; thenbrowse stoppnpm --filter browse lintpnpm --filter browse testThe fixture is synthetic and deterministic; no LLM path is involved.