STG-1672: Add --connect flag to browse CLI for existing Browserbase sessions

Merged
SH
8mo ago
+245-12

Summary

  • Adds a global --connect <session-id> flag to the browse CLI that connects to an existing Browserbase session instead of creating a new one
  • Uses Stagehand core's existing browserbaseSessionID support with keepAlive: true so the session stays alive after the CLI disconnects
  • Follows the same state-file pattern as --context-id (writes session ID to /tmp/browse-{session}.connect, daemon reads it during initialization)

Test procedure

# 1. Sync cookies
node cookie-sync.mjs --domains github.com
# → Session ID: 3ee737d4-237f-4557-a1ca-09a3d5dcbaf2

# 2. Connect and browse (dev build)
browse --connect 3ee737d4-... open https://github.com/notifications  ✅
browse eval "..."  ✅

Tests completed

  • browse --connect <id> open ... in local mode → errors with "only supported in remote mode"
  • browse --connect <id> open --context-id <ctx> ... → errors with mutual exclusion message
  • --connect writes session ID to connect file before daemon start
  • Commands without --connect clear stale connect file
  • browse status output includes browserbaseSessionId field
  • Manual: browse --connect <valid-bb-session> open https://example.com connects and navigates
  • Manual: browse stop disconnects without killing the BB session

🤖 Generated with Claude Code

Fixes STG-1672


Summary by cubic

Adds a --connect <session-id> flag to the browse CLI to attach to an existing Browserbase session instead of creating a new one, leaving the session running after the CLI exits. Implements STG-1672.

  • New Features
    • New global --connect <session-id> for browse to attach to an existing Browserbase session
    • Remote mode only; errors in local mode
    • Mutually exclusive with --context-id
    • Persists the session ID to /tmp/browse-{session}.connect; clears when unused and restarts the daemon if the ID changes
    • Uses browserbaseSessionID with keepAlive: true so the session persists after disconnect
    • browse status now includes a browserbaseSessionId field
    • Minor release for @browserbasehq/browse-cli