Skip to main content
1

Get your API Key

Visit the Dashboard’s Settings tab:
Copy your API key for the next step.
2

Install Agent Browser

npm install -g agent-browser
agent-browser install
The install command downloads Chromium for local use. When using the Browserbase provider, the browser runs in the cloud instead.
3

Set environment variables

Set your Browserbase credentials:
export BROWSERBASE_API_KEY="bb_live_..."
4

Open a page with Browserbase

Use the -p browserbase flag to run commands on a Browserbase cloud browser:
agent-browser -p browserbase open https://example.com
This creates a Browserbase session and navigates to the URL. You can view the session in your Browserbase Dashboard.
5

Get an accessibility snapshot

The snapshot command returns an accessibility tree with element references — the primary way AI agents understand page content:
agent-browser -p browserbase snapshot
Output includes element refs that you can use in subsequent commands:
- heading "Example Domain" [ref=e1] [level=1]
- paragraph "This domain is for use in illustrative examples."
- link "More information..." [ref=e3]
Use the -i flag to show only interactive elements:
agent-browser -p browserbase snapshot -i
6

Interact with elements

Use element refs from the snapshot to click, type, and fill:
# Click a link by ref
agent-browser -p browserbase click @e3

# Fill a form field
agent-browser -p browserbase fill @e5 "test@example.com"

# Take a screenshot
agent-browser -p browserbase screenshot page.png
7

Close the session

agent-browser -p browserbase close
All commands support the -p browserbase flag to run on Browserbase cloud browsers. You can also set AGENT_BROWSER_PROVIDER=browserbase as an environment variable to avoid passing the flag each time. See the Agent Browser README for the full command reference.

Connecting via CDP

You can also connect Agent Browser to a Browserbase session directly using the CDP WebSocket URL:
import Browserbase from "@browserbasehq/sdk";

const bb = new Browserbase({ apiKey: process.env.BROWSERBASE_API_KEY });
const session = await bb.sessions.create();

console.log(session.connectUrl);
// wss://connect.browserbase.com/?sessionId=...
Then connect Agent Browser:
agent-browser --cdp "wss://connect.browserbase.com/?sessionId=..." snapshot