Skip to content

refactor(cli): migrate Browse runtime to Stagehand V4 - #2834

Draft
shrey150 wants to merge 12 commits into
agent/browse-v4-3-cli-baselinefrom
agent/browse-v4-4-runtime
Draft

refactor(cli): migrate Browse runtime to Stagehand V4#2834
shrey150 wants to merge 12 commits into
agent/browse-v4-3-cli-baselinefrom
agent/browse-v4-4-runtime

Conversation

@shrey150

@shrey150 shrey150 commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Migrate the exact Browse V3 baseline from #2833 onto the workspace Stagehand V4 SDK while preserving the existing CLI surface.

  • Replace the V3 constructor/init lifecycle with V4 browser factories and Stagehand.create().
  • Preserve owned-versus-attached browser cleanup and Browserbase session identity.
  • Use V4 locators for selector actions, including click/fill without act() or a model.
  • Adapt navigation, tabs, state, screenshots, viewport, input, eval, cursor, and network commands to V4 async APIs.
  • Install the cursor overlay with an idempotent CLI-owned page.evaluate() snippet.
  • Preserve the V3 network writer behind an explicit capability error; fix(cli): restore V3 network capture through a CDP sidecar #2849 supplies its CLI-private CDP transport.
  • Omit undefined optional typing/navigation/mouse values from V4 RPC payloads.

Stack

  1. chore(cli): import Browse V3 baseline #2833 — exact Browse V3 baseline import
  2. refactor(cli): migrate Browse runtime to Stagehand V4 #2834 — Stagehand V4 runtime cutover and CLI-owned cursor
  3. fix(cli): restore V3 network capture through a CDP sidecar #2849 — CLI-private CDP sidecar; restores V3 network capture
  4. refactor(cli): remove coordinate XPath return flag #2835 — remove --return-xpath; complete supported V3 parity
  5. test(evals): exercise the workspace V4 CLI #2838 — eval, packaging, and release wiring
  6. fix(cli): persist context names in Browserbase #2839 — managed Context names (fast-follow)
  7. refactor(cli): consume shared Functions core #2701 — shared Functions core consumer (fast-follow)

Review boundary

This PR carries the reviewable V4 runtime migration with two explicit stack boundaries. browse network on reports network_capture_unavailable until #2849 supplies the CLI-private CDP sidecar, and the legacy coordinate-action --return-xpath option is accepted but fails clearly until #2835 removes it. XPath selectors and snapshot xpathMap remain supported throughout.

This does not add model-free structured act() to core Stagehand. Browse's clicks are deterministic locator operations and do not require a model.

E2E Test Matrix

All flows below used the actual built CLI against real local Chromium on this PR.

Command / flow Observed output Confidence / sufficiency
Daemon lifecycle: status → open → status → stop → status Connected during the run; disconnected after stop Proves owned browser startup, persistence, and cleanup
Snapshot full/ref maps; CSS and XPath fill/click; ref click; get/is Form result Hello V4Restack; refs and XPath selectors resolved Proves the primary deterministic selector surface migrated without act()
Checkbox, select, upload, and highlight State/value/file assertions passed Covers non-text element actions and state reads
type with no options, delay, and mistakes Bare form produced BareTypeWorks; all variants passed Directly verifies the V4 optional-field fix and prevents the prior undefined-RPC regression
Cursor plus raw mouse input on rewritten head 34c5c7d2f cursor installed __browse_cursor_overlay__; hover moved it to 400px, 300px; the overlay contained its SVG at z-index 2147483647 Proves the CLI-owned page.evaluate() overlay and V4 coordinate input work together in real Chromium
Viewport, screenshot, wait selector/timeout Requested viewport and screenshot produced; wait success and timeout paths behaved correctly Covers page-control and artifact behavior
Back, forward, reload, and page metadata getters URL/title/HTML/markdown/visibility/checked assertions passed Covers navigation and page information parity
Built CLI network on on rewritten head df9111578 Exit 1 with the explicit Stagehand V4 transport-gap message (network_capture_unavailable) Deliberately exposes the one transport gap; #2849 restores the unchanged V3 command/files without a public Stagehand schema
Tabs new/list/switch/close Active tab and tab counts matched each operation Covers V4 async context/page handling
mouse click ... --return-xpath Exit 1 with Coordinate XPath lookup is not exposed by Stagehand V4 Expected and explicit temporary boundary for this PR only
Browse build/lint/full suite on rewritten head df9111578 25 files / 380 tests passed; Prettier, ESLint, and TypeScript passed Broad regression coverage after removing #2832 from the ancestry
Direct composition Base is the rewritten exact V3 import; package build/type/lint/test passed #2834 has no core-network or generated-SDK dependency

Cursor proof

CLI-owned cursor overlay installed through page.evaluate

The screenshot above was captured from the built CLI on this PR after browse cursor and browse mouse hover 400 300; the DOM assertion returned { left: "400px", top: "300px", svg: true }.

Browserbase remote mode is covered by the retained unit/contract tests; this local E2E matrix exercises the full user command surface without consuming a remote session.

@changeset-bot

changeset-bot Bot commented Aug 27, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: df91115

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

…runtime

# Conflicts:
#	packages/cli/src/lib/driver/commands/elements.ts
#	packages/cli/src/lib/driver/commands/keyboard.ts
#	packages/cli/src/lib/driver/commands/mouse.ts
#	packages/cli/src/lib/driver/commands/navigation.ts
#	packages/cli/src/lib/driver/commands/page-info.ts
#	packages/cli/src/lib/driver/commands/runtime.ts
#	packages/cli/src/lib/driver/commands/tabs.ts
#	packages/cli/src/lib/driver/daemon/client.ts
#	packages/cli/src/lib/driver/network-capture.ts
#	packages/cli/src/lib/driver/remote-types.ts
#	packages/cli/src/lib/driver/remote.disabled.ts
#	packages/cli/src/lib/driver/remote.ts
#	packages/cli/src/lib/driver/session-manager.ts
#	packages/cli/tests/driver-commands.test.ts
#	packages/cli/tests/driver-foundation.test.ts
#	packages/cli/tests/identity-attribution.test.ts
#	packages/cli/tests/remote-disabled.test.ts
#	packages/cli/tests/remote-options.test.ts
#	pnpm-lock.yaml
#	turbo.json
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