Skip to content

Browser API

Manage browser sessions and execute actions.

Endpoints

MethodEndpointDescription
GET/api/agents/{id}/browserList sessions
POST/api/agents/{id}/browserCreate session
DELETE/api/agents/{id}/browserDelete session
POST/api/agents/{id}/browser/{sessionId}/executeExecute action
GET/api/agents/{id}/browser/{sessionId}/live-viewGet live view
POST/api/agents/{id}/browser/{sessionId}/takeoverRequest takeover

List Sessions

bash
GET /api/agents/{id}/browser

Response

json
{
  "sessions": [
    {
      "id": "session-123",
      "status": "active",
      "headless": true,
      "viewport": {
        "width": 1280,
        "height": 720
      },
      "created_at": "2024-12-15T10:00:00Z",
      "last_activity": "2024-12-15T10:05:00Z"
    }
  ]
}

Create Session

bash
POST /api/agents/{id}/browser
Content-Type: application/json

Request Body

json
{
  "headless": true,
  "viewport": {
    "width": 1920,
    "height": 1080
  },
  "user_agent": "Mozilla/5.0..."
}

Response

json
{
  "id": "session-123",
  "status": "active",
  "live_view_url": "https://browserbase.com/live/...",
  "created_at": "2024-12-15T10:00:00Z"
}

Delete Session

bash
DELETE /api/agents/{id}/browser?id={sessionId}

Response

json
{
  "success": true
}

Execute Action

bash
POST /api/agents/{id}/browser/{sessionId}/execute
Content-Type: application/json
json
{
  "action": "navigate",
  "url": "https://example.com"
}

Click

json
{
  "action": "click",
  "selector": "#submit-button"
}

Type

json
{
  "action": "type",
  "selector": "#email",
  "text": "user@example.com"
}

Press

json
{
  "action": "press",
  "key": "Enter"
}

Screenshot

json
{
  "action": "screenshot",
  "full_page": false
}

Response:

json
{
  "success": true,
  "result": {
    "image": "data:image/png;base64,..."
  }
}

Extract

json
{
  "action": "extract",
  "selector": ".product-price",
  "attribute": "text"
}

Response:

json
{
  "success": true,
  "result": {
    "value": "$99.99"
  }
}

Scroll

json
{
  "action": "scroll",
  "direction": "down",
  "amount": 500
}

Wait

json
{
  "action": "wait",
  "selector": "#content",
  "state": "visible",
  "timeout": 5000
}

Multiple Actions

json
{
  "actions": [
    { "action": "navigate", "url": "https://example.com" },
    { "action": "wait", "selector": "#login" },
    { "action": "click", "selector": "#login" },
    { "action": "type", "selector": "#email", "text": "user@example.com" },
    { "action": "press", "key": "Enter" }
  ]
}

Response

json
{
  "success": true,
  "results": [
    { "action": "navigate", "success": true, "duration_ms": 1500 },
    { "action": "wait", "success": true, "duration_ms": 200 },
    { "action": "click", "success": true, "duration_ms": 50 },
    { "action": "type", "success": true, "duration_ms": 300 },
    { "action": "press", "success": true, "duration_ms": 10 }
  ],
  "total_duration_ms": 2060
}

Live View

bash
GET /api/agents/{id}/browser/{sessionId}/live-view

Response

json
{
  "url": "https://browserbase.com/live/session-123",
  "expires_at": "2024-12-15T11:00:00Z"
}

Human Takeover

bash
POST /api/agents/{id}/browser/{sessionId}/takeover
Content-Type: application/json

Request Body

json
{
  "reason": "CAPTCHA detected",
  "timeout": 300
}

Response

json
{
  "takeover_id": "takeover-123",
  "status": "pending",
  "takeover_url": "https://browserbase.com/takeover/...",
  "expires_at": "2024-12-15T10:05:00Z"
}

Session Status

StatusDescription
activeSession is running
pausedTemporarily paused
takeoverHuman control active
closedSession ended
errorSession failed

Action Types

ActionDescription
navigateGo to URL
clickClick element
typeEnter text
pressPress key
screenshotCapture image
extractGet content
scrollScroll page
waitWait for condition
hoverHover element
selectSelect option
uploadUpload file
evaluateRun JavaScript

Errors

CodeDescription
400Invalid action
404Session not found
408Action timeout
500Browser error

Examples

Complete Flow

bash
# Create session
SESSION=$(curl -X POST .../browser -d '{"headless": true}' | jq -r '.id')

# Navigate
curl -X POST ".../browser/$SESSION/execute" \
  -d '{"action": "navigate", "url": "https://example.com"}'

# Fill form
curl -X POST ".../browser/$SESSION/execute" \
  -d '{
    "actions": [
      {"action": "type", "selector": "#email", "text": "user@example.com"},
      {"action": "type", "selector": "#password", "text": "password"},
      {"action": "click", "selector": "#submit"}
    ]
  }'

# Screenshot
curl -X POST ".../browser/$SESSION/execute" \
  -d '{"action": "screenshot"}' | jq -r '.result.image' > screenshot.png

# Close session
curl -X DELETE ".../browser?id=$SESSION"

Released under the MIT License.