Subchapter 6.1
EXAMPLES.mdMarkdown6 KBView on GitHub
Common browser automation workflows using the browse CLI. Each example demonstrates a distinct pattern using real commands.
For localhost and other local dev flows, start with browse open <url> --local for a clean isolated browser. Use browse open <url> --auto-connect only when the agent should attach to an existing debuggable Chrome session for cookies or login state.
User request: “Get the product details from example.com/product/123”
browse open https://example.com/product/123
browse snapshot # read page structure + element refs
browse get text "body" # extract all visible text content
browse stopParse the text output to extract structured data (name, price, description, etc.).
For a specific section, use a CSS selector:
browse get text ".product-details" # text from a specific containerNote: browse get text requires a CSS selector — use "body" for all page text.
User request: “Fill out the contact form on example.com with my information”
browse open https://example.com/contact
browse snapshot # find form fields and their refs
browse click @0-3 # click the Name input (ref from snapshot)
browse type "John Doe"
browse press Tab # move to next field
browse type "john@example.com"
browse fill "#message" "I would like to inquire about your services"
browse snapshot # verify fields are filled
browse click @0-8 # click Submit button (ref from snapshot)
browse snapshot # confirm submission result
browse stopKey pattern: Use browse snapshot before interacting to discover element refs, then browse click <ref> and browse type to interact.
User request: “Get headlines from the first 3 pages of results on example.com/news”
browse open https://example.com/news
browse snapshot # read page 1 content
browse get text ".headline" # extract headlines
browse snapshot # find "Next" button ref
browse click @0-12 # click Next (ref from snapshot)
browse wait load # wait for page 2 to load
browse get text ".headline" # extract page 2 headlines
browse snapshot # find Next again (ref may change)
browse click @0-15 # click Next
browse wait load
browse get text ".headline" # extract page 3 headlines
browse stopKey pattern: Re-run browse snapshot after each navigation because element refs change when the page updates.
User request: “Scrape pricing from competitor.com” (a site with Cloudflare protection)
# Attempt 1: local mode
browse open https://competitor.com/pricing --local
browse snapshot
# Output shows: "Checking your browser..." (Cloudflare interstitial)
# or: page content is empty / access denied
browse stopThe agent detects bot protection and tells the user:
This site has Cloudflare bot detection. Browserbase remote mode can use Browserbase Identity with a Verified browser and residential proxies. Want me to set it up?
If the user agrees:
# Set Browserbase credentials
export BROWSERBASE_API_KEY="bb_live_..."
# Retry in remote mode
browse open https://competitor.com/pricing --remote
browse snapshot # full page content now accessible
browse get text ".pricing-table"
browse stopUser request: “Log into my dashboard and save the session so I don’t have to log in again next time”
This uses Browserbase contexts to persist cookies and storage across sessions. Requires remote mode.
# Session 1: Log in and persist state
SESSION_JSON="$(browse cloud sessions create --context-id ctx_abc123 --persist --keep-alive)"
SESSION_ID="$(echo "$SESSION_JSON" | jq -r .id)"
CONNECT_URL="$(echo "$SESSION_JSON" | jq -r .connectUrl)"
browse open https://app.example.com/login --cdp "$CONNECT_URL"
browse snapshot # find login form fields
browse click @0-3 # click email input
browse type "user@example.com"
browse press Tab
browse type "my-password"
browse click @0-7 # click Sign In button
browse wait load
browse snapshot # confirm logged-in dashboard
browse stop
browse cloud sessions update "$SESSION_ID" --status REQUEST_RELEASE # state is saved back to ctx_abc123In a later session, reuse the same context — already authenticated:
# Session 2: Resume with saved state (already logged in)
SESSION_JSON="$(browse cloud sessions create --context-id ctx_abc123 --keep-alive)"
SESSION_ID="$(echo "$SESSION_JSON" | jq -r .id)"
CONNECT_URL="$(echo "$SESSION_JSON" | jq -r .connectUrl)"
browse open https://app.example.com/dashboard --cdp "$CONNECT_URL"
browse snapshot # dashboard loads — no login needed
browse get text ".welcome-message"
browse stop
browse cloud sessions update "$SESSION_ID" --status REQUEST_RELEASEKey pattern: Use browse cloud sessions create --context-id <id> --persist for the first Browserbase session to save auth state, then attach with browse open ... --cdp "$CONNECT_URL". On subsequent sessions, create with the same --context-id and omit --persist if you don’t want changes saved back.
browse snapshot before interacting — it gives you the accessibility tree with element refsbrowse click @0-5 is more reliable than trying to describe elementsget text for data extraction: Use browse get text [selector] to pull text content from specific elementsstop when done: Always browse stop to clean up the browser session