When using Browserbase, use the bb-capture.mjs and bb-finalize.mjs helpers to manage sessions and artifacts.
Important: Browserbase ends a session as soon as its last CDP client disconnects. Use the --keep-alive flag when creating a session to ensure the tracer can attach.
Create a new session and trace
export BROWSERBASE_API_KEY=...
# 1. Create a keep-alive session AND start the tracer
node scripts/bb-capture.mjs --new my-run
# 2. Drive automation using the session's connectUrl
SID=$(jq -r .browserbase.session_id .o11y/my-run/manifest.json)
CONNECT_URL="$(browse cloud sessions get "$SID" | jq -r .connectUrl)"
BROWSE_NAME=my-run-browser
browse open https://example.com --cdp "$CONNECT_URL" --session "$BROWSE_NAME"
browse open https://news.ycombinator.com --session "$BROWSE_NAME"
# 3. Stop, bisect, and pull artifacts
node scripts/stop-capture.mjs my-run
node scripts/bisect-cdp.mjs my-run
node scripts/bb-finalize.mjs my-run --release
Attach to an existing running session
If you have a running session (e.g., from a production worker), you can attach the tracer mid-flight without disruption:
# Find a running session ID
browse cloud sessions list | jq -r '.[] | select(.status == "RUNNING") | .id'
# Attach tracer to the session
node scripts/bb-capture.mjs <session-id> mid-flight-debug
# Stop and process
node scripts/stop-capture.mjs mid-flight-debug
node scripts/bisect-cdp.mjs mid-flight-debug
node scripts/bb-finalize.mjs mid-flight-debug # omit --release to keep session running
export BROWSERBASE_API_KEY=...
# 1. Create a keep-alive session AND start the tracer in one step.
node scripts/bb-capture.mjs --new my-run
# 2. Drive automation. bb-capture stamped the session id into the manifest.
SID=$(jq -r .browserbase.session_id .o11y/my-run/manifest.json)
CONNECT_URL="$(browse cloud sessions get "$SID" | jq -r .connectUrl)"
BROWSE_NAME=my-run-browser
browse open https://example.com --cdp "$CONNECT_URL" --session "$BROWSE_NAME"
browse open https://news.ycombinator.com --session "$BROWSE_NAME"
# 3. Stop the tracer, bisect, then pull platform artifacts and release.
node scripts/stop-capture.mjs my-run
node scripts/bisect-cdp.mjs my-run
node scripts/bb-finalize.mjs my-run --release