fix(sdk-ts,cli): replace incompatible extension on --cdp attach

SH
3d ago
+735-17

why

Two failure modes when using browse open --cdp with remote Browserbase sessions:

  1. Extension path inaccessible: Sessions created without the Stagehand extension fail on --cdp attach because the CLI tries to load the bundled extension via Extensions.loadUnpacked, but the remote Chrome can't access the local filesystem. Error: "File path cannot be resolved."

  2. Incompatible extension version: Sessions created with an older Stagehand extension (e.g., from an earlier SDK version) fail because the runtime protocol versions don't match. Error: "Incompatible Stagehand runtime."

The fix addresses both: browse cloud sessions create now uploads the bundled extension by default, and the SDK auto-replaces incompatible extensions on local --cdp attach.

before / after

Remote (run on cb46fff with real BROWSERBASE_API_KEY):

# BEFORE: browse 0.12.0 from npm
$ browse cloud sessions create > session.json
$ browse open https://example.com --cdp "$(jq -r .connectUrl session.json)"
File path cannot be resolved.
# exit=1 (3/3 runs failed)

# AFTER: this branch (cb46fff)
$ browse cloud sessions create > session.json   # bundled extension uploaded, ~+300ms
$ browse open https://example.com --cdp "$(jq -r .connectUrl session.json)"
{
  "mode": "cdp",
  "pages": [{ "index": 0, "title": "Example Domain", "url": "https://example.com/" }]
}
# exit=0 (3/3 runs passed)

# AFTER, --no-stagehand-extension
$ browse cloud sessions create --no-stagehand-extension > session.json
$ browse open https://example.com --cdp "$(jq -r .connectUrl session.json)"
File path cannot be resolved.
# exit=1 (3/3, same as 0.12.0)

what changed

SDK (packages/sdk-ts/src/cdpClient.ts):

  • Auto-replace incompatible extension via Extensions.loadUnpacked when localExtensionDir is set and runtime version mismatch is detected
  • Map "File path cannot be resolved" Chrome error to extension_path_inaccessible with actionable message

CLI (packages/cli/src/commands/cloud/sessions/create.ts):

  • Auto-upload bundled Stagehand extension when creating sessions (default on)
  • Use --no-stagehand-extension to skip, or --extension-id for a pre-uploaded extension
  • On upload failure, warn to stderr and continue creating session without extension

CLI (packages/cli/src/lib/cloud/stagehand-extension.ts):

  • Helper to upload extension with 429 retry logic
  • Mirrors SDK's provisionBrowserbaseExtension pattern; separate because CLI depends on published SDK (4.4.0), not workspace:*, and linkWorkspacePackages: false
  • Each sessions create uploads a new extension (no caching)

CLI (packages/cli/src/lib/driver/session-manager.ts):

  • Handle extension_path_inaccessible with typed error code and actionable guidance

test plan

  • localExtensionReplacement.test.ts: preinstalls mutated extension (older 3.0.0 or future 4.0.0), connects, verifies replacement
  • cli-cloud-contract.test.ts: verifies sessions create includes extension in API request
  • cli-cloud-contract.test.ts: verifies graceful degradation on upload failure (warns, continues)
  • SDK tests pass (682 passed, 4 skipped)
  • CLI tests pass (702 passed)
  • Remote end-to-end on cb46fff: 3/3 passed
Open in Web Open in Cursor 

Summary by cubic

Fixes browse open --cdp failing when the connected browser has an older Stagehand extension, and makes browse cloud sessions create provision a compatible runtime up front.

  • CDPClient.connect auto-replaces an incompatible extension with the bundled one when connecting via a local extension dir with the default runtime requirement; failed replacements re-throw the original error tagged with replacementError, preserving abort cancellation.
  • Chrome's "File path cannot be resolved" error maps to extension_path_inaccessible; runtime mismatches get typed codes runtime_incompatible and runtime_incompatible_replace_failed with actionable guidance.
  • browse cloud sessions create uploads the bundled Stagehand extension by default; --extension-id or --no-stagehand-extension skip it, and upload failures (including an unavailable archive) warn without failing.
  • Telemetry on failed commands includes a redacted, 200-char-truncated error_message.
  • Tests cover older, newer, and remote incompatible extension scenarios.