# Browser Execute

> Execute actions in a headless browser session — 2 credits per call.

Source: http://localhost:3000/docs/endpoints/browser-execute

## Browser Execute: `POST /v1/browser-execute/`

Run a list of actions — click, type, scroll, wait, extract — in a session. Cost: 2 credits.

```bash
curl -X POST https://api.hushsearch.io/v1/browser-execute/ \
  -H "X-API-Key: hs_live_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "session_id": "sess_…",
  "actions": [
    {
      "type": "navigate",
      "url": "https://example.com/"
    },
    {
      "type": "extract",
      "selector": "h1"
    }
  ]
}'
```

**POST** `/v1/browser-execute/` — **2 credits per call**

Execute a sequence of actions in an existing session created via [Browser Session](http://localhost:3000/docs/endpoints/browser).

## Request

```json
{
  "session_id": "550e8400-e29b-41d4-a716-446655440000",
  "actions": [
    { "type": "goto", "url": "https://example.com" },
    { "type": "click", "selector": "#search-btn" },
    { "type": "type", "selector": "input[name=q]", "text": "HushSearch" },
    { "type": "screenshot" },
    { "type": "extract" }
  ]
}
```

### Supported action types

| Type | Fields | Description |
|---|---|---|
| `goto` | `url` | Navigate (SSRF-guarded) |
| `click` | `selector` | Click a CSS selector |
| `type` | `selector`, `text` | Fill an input |
| `screenshot` | — | Returns base64 PNG |
| `extract` | — | Returns main content as markdown |
| `wait` | `ms` | Wait up to 5000ms |

## Response

```json
{
  "session_id": "550e8400-e29b-41d4-a716-446655440000",
  "results": [
    { "type": "goto", "url": "https://example.com", "status": "ok" },
    { "type": "screenshot", "image_base64": "iVBORw0KGgo..." },
    { "type": "extract", "title": "Example Domain", "markdown": "# Example\n..." }
  ],
  "credits_used": 2,
  "credits_remaining": 92,
  "response_time_ms": 850
}
```

## Notes

- Returns 404 if the session has expired or does not exist.
- `goto` validates URLs against the SSRF blocklist.
- Empty `actions` list returns 400.
