> ## Documentation Index
> Fetch the complete documentation index at: https://docs.styne.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Browsers

> A browser session is a Chromium instance in its own microVM that you drive over the Chrome DevTools Protocol (CDP) with Playwright, Puppeteer, Stagehand or Browser Use. It has its own template, its own lifecycle and its own meter, and it uses the same API key as sandboxes.

Base URL: `https://api.styne.ai`. Every request carries `Authorization: Bearer $STYNE_API_KEY`.

## Quick start

### 1. Start a session

```bash theme={"theme":"css-variables"}
curl -sS https://api.styne.ai/browsers \
  -H "Authorization: Bearer $STYNE_API_KEY" \
  -H "content-type: application/json" \
  -d '{"timeout": 900}'
```

Every field is optional: `timeout` in seconds (15 minutes by default) and `region`: `ash` (US East, Ashburn; the default). `ams` is accepted and served in Ashburn for now, see
[Regions](https://docs.styne.ai/regions.md). A browser in `ash` reports the `America/New_York` time zone and `en-US`. An unknown region is
refused with 422. [Start options](#start-options) set the page size, downloads, recording and your own metadata. The
answer:

```text theme={"theme":"css-variables"}
{ "id": "...", "state": "running", "cdp_url": "wss://...", "expires_at": 1790000000, "region": "...",
  "recording": true, "downloads": false }
```

A session started with `viewport` or `metadata` also answers those two fields, on the start and on every later
`GET /browsers/{id}` and `GET /browsers`.

`cdp_url` carries a token: treat it as a secret and do not put it in a page, a log or a screenshot.

The answer carries the API's own start time in a `Server-Timing` header (add `-D -` to the curl call to see it):
`create;dur=<ms>` is the whole start, followed by its phases (`claim`, `node-resume`, ...), so you can log how long each
start took on our side:

```text theme={"theme":"css-variables"}
server-timing: create;dur=<ms>, claim;dur=<ms>, node-resume;dur=<ms>, node-network;dur=<ms>, ...
```

### 2. Connect Playwright and take a screenshot

Python, with `cdp_url` from the answer above:

```python theme={"theme":"css-variables"}
from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.connect_over_cdp(cdp_url)
    context = browser.contexts[0] if browser.contexts else browser.new_context()
    page = context.pages[0] if context.pages else context.new_page()
    page.goto("https://example.com")
    page.screenshot(path="example.png")
    print(page.title())
```

Node:

```javascript theme={"theme":"css-variables"}
import { chromium } from "playwright";

const browser = await chromium.connectOverCDP(session.cdp_url);
const context = browser.contexts()[0] ?? await browser.newContext();
const page = context.pages()[0] ?? await context.newPage();
await page.goto("https://example.com");
await page.screenshot({ path: "example.png" });
console.log(await page.title());
await browser.close();
```

### 3. Or connect Puppeteer

```javascript theme={"theme":"css-variables"}
import puppeteer from "puppeteer-core";

const browser = await puppeteer.connect({ browserWSEndpoint: session.cdp_url });
const page = await browser.newPage();
await page.goto("https://example.com");
console.log(await page.title());
await browser.disconnect();
```

### 4. Stop the session

```bash theme={"theme":"css-variables"}
curl -sS -X DELETE https://api.styne.ai/browsers/$SESSION_ID \
  -H "Authorization: Bearer $STYNE_API_KEY"
```

A session that is not stopped expires at `expires_at` and is then stopped for you. Reading or stopping another account's
session id answers 404.

### From TypeScript without a client library

```typescript theme={"theme":"css-variables"}
const res = await fetch("https://api.styne.ai/browsers", {
  method: "POST",
  headers: { authorization: `Bearer ${process.env.STYNE_API_KEY}`, "content-type": "application/json" },
  body: JSON.stringify({ timeout: 900 }),
});
const session = await res.json(); // { id, state, cdp_url, expires_at, region }
```

## Start options

```bash theme={"theme":"css-variables"}
curl -sS https://api.styne.ai/browsers \
  -H "Authorization: Bearer $STYNE_API_KEY" \
  -H "content-type: application/json" \
  -d '{"viewport": {"width": 1920, "height": 1080}, "downloads": true, "metadata": {"run": "r-17", "attempt": 2}}'
```

| Field | What it does |
| - | - |
| `viewport` | `{"width": 1920, "height": 1080}`: the page size in CSS pixels, what `window.innerWidth` and `window.innerHeight` read, from 320x240 to 3840x2160. It is set before the start answers, so the page you connect to already has it, and pages opened later get it too. Without it a page is 1280x633. |
| `metadata` | Your own keys and JSON values (also accepted as `user_metadata`): at most 50 keys of 1 to 64 letters, digits, `_`, `-`, `.` or `:`, each value at most 512 bytes as JSON. Answered back as sent, with its types, on the start, `GET /browsers/{id}` and `GET /browsers`. |
| `recording` | `true` (the default): the session's console, network, trace and replay are recorded and read with the routes under [Operations](#operations). `false`: nothing of the session is recorded and those reads answer empty. |
| `downloads` | `true`: the browser saves every download into `/home/browser/Downloads`, under the name the site gives it, for the whole session and whichever client clicked. See [Downloads](#downloads). The default `false` saves nothing. |
| `extensions` | `["ext_..."]`: ids of extensions you uploaded (see [Extensions](#extensions)), at most 10. Each is loaded into the browser before the start answers, and the answer lists them with their Chrome ids. An id your account does not have is refused with 422 naming it. |
| `stealth` | `false`: no unblocking and no CAPTCHA clicks (`unblock` and `captcha` default to `off`; a value you name still wins). `true` or no field keeps the defaults. |
| `profile` | A [profile](https://docs.styne.ai/profiles.md) id: the session starts from the profile's saved browser, signed in as it was left. |
| `persist` | With `profile`: `true` (the default without `fork`) saves the browser into the profile on the server whenever the session ends, by a delete from any client, by its `timeout`, or by a stop of its machine. `false` writes the profile only on `POST /profiles/{id}/save`. Answered back as `persist` with `profile` on the start, `GET /browsers/{id}` and `GET /browsers`. See [Saved when the session ends](https://docs.styne.ai/profiles.md#saved-when-the-session-ends). |
| `unblock`, `captcha`, `egress`, `country`, `timezone`, `locale`, `idle_timeout_seconds`, `fork` | See [CAPTCHAs](#captchas), [Sleep, wake, fork and rewind](#sleep-wake-fork-and-rewind) and [Regions](https://docs.styne.ai/regions.md). |

A value outside these bounds is refused with 422 and a message that names the bound. Two fields take no value and are
refused with a 422 that says what to send instead: `proxy` (send `egress` and `country`) and `secure` (a session is
reached only with the token in its `cdp_url`).

## Extensions

Load your own Chrome extensions into a session: upload the extension once, then name it on every start that needs it.
The session starts as fast as any other; the extension is unpacked into the running browser and loaded before the start
answers, so its content scripts run on the first page you open.

### 1. Upload the extension

Zip the folder of an unpacked extension (the one you would pick under "Load unpacked" in `chrome://extensions`):
`manifest.json` at the top of the zip or in its one top folder. Send it as the `file` part of a form, or as the body:

[//]: # "smoke: not executed, it needs an extension zip on disk"

```bash theme={"theme":"css-variables"}
cd my-extension && zip -r ../my-extension.zip . && cd ..
curl -sS https://api.styne.ai/extensions \
  -H "Authorization: Bearer $STYNE_API_KEY" \
  -F file=@my-extension.zip
```

The answer:

```text theme={"theme":"css-variables"}
{ "id": "ext_...", "name": "My extension", "version": "1.0", "manifest_version": 3, "size": 1834,
  "chrome_id": "...", "file_name": "my-extension.zip", "created_at": "2026-11-23T17:00:00Z" }
```

`chrome_id` is the id the browser gives the extension in every session (`chrome-extension://<chrome_id>/`); a manifest
with a `key` keeps the id that key gives it. `curl --data-binary @my-extension.zip -H "content-type: application/zip"`
uploads the same zip as the body.

| Route | What it does |
| - | - |
| `POST /extensions` | Upload a zip; answers 201 with the extension |
| `GET /extensions` | List the account's extensions, newest first |
| `GET /extensions/{id}` | Read one extension |
| `DELETE /extensions/{id}` | Delete it; sessions that loaded it keep it until they end |

On the `/v1` API the same routes are `/v1/extensions` and `/v1/extensions/{ext}`.

### 2. Start a session with it

[//]: # "smoke: not executed, it needs an uploaded extension"

```bash theme={"theme":"css-variables"}
curl -sS https://api.styne.ai/browsers \
  -H "Authorization: Bearer $STYNE_API_KEY" \
  -H "content-type: application/json" \
  -d '{"extensions": ["ext_..."]}'
```

The start answer, `GET /browsers/{id}` and `GET /browsers` list what the session loaded:

```text theme={"theme":"css-variables"}
{ "id": "...", "cdp_url": "wss://...", ..., "extensions": [{ "id": "ext_...", "chrome_id": "..." }] }
```

### 3. Use it from Playwright

An extension with a content script on `<all_urls>` that sets `document.documentElement.dataset.ext = "ok"`:

[//]: # "smoke: not executed, it needs a running browser session with an extension"

```python theme={"theme":"css-variables"}
from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.connect_over_cdp(cdp_url)
    context = browser.contexts[0]
    page = context.new_page()
    page.goto("https://example.com")
    print(page.evaluate("document.documentElement.dataset.ext"))  # ok
    cdp = browser.new_browser_cdp_session()
    print(cdp.send("Extensions.getExtensions"))  # the loaded extensions with id, name, version, path, enabled
```

### Limits and errors

* A zip is at most 50 MB and unpacks to at most 200 MB in at most 5,000 entries; an entry may not point outside the
  extension's folder. Manifest versions 2 and 3 are accepted.
* An account keeps at most 100 extensions and 500 MB of zips; a session loads at most 10 (100 MB of zips together).
* An upload that is not one extension is refused with 422 `invalid_extension` and the reason (no `manifest.json`, a
  manifest that is not JSON, no `name` or `version`, an entry outside the folder); a zip over the cap with 413.
* A start that names an id your account does not have is refused with 422 `unknown_extension` before any browser starts.
  If the browser refuses an extension when it loads it (for example a manifest key it does not accept), the start fails
  with 422 `extension_refused` and the browser's own message, and the session is stopped.

## In the dashboard

The Browsers page lists the account's sessions with their state, region and end time. **Start a browser** starts one
and shows its start time (the API's own time and the time your browser waited). **Connect** copies the session's CDP
URL once, without showing it. Each session's page has a live view: its screen, console and network, attached over
the session's CDP URL from your browser next to your own client. Your client keeps driving while you watch, and the
console and network lists show what happens while the page is open. **Take control** hands the page to you (see below).
**Stop** ends the session.

## Human takeover

A person can take over a running browser, for a login, a captcha or a payment step, and hand it back to the agent.
In the dashboard, **Take control** on the live view pauses your client's input, sends your mouse, wheel and keyboard to the
page, and **Return control** gives the browser back. Through the API:

[//]: # "smoke: not executed, it needs the id of a running browser session and a person at the live view"

```bash theme={"theme":"css-variables"}
# Take control. The answer carries a control_id and a cdp_url to drive the page as the person.
curl -sS -X POST https://api.styne.ai/browsers/$BROWSER_ID/control -H "Authorization: Bearer $STYNE_API_KEY" \
  -H 'Content-Type: application/json' -d '{"holder":"alice"}'

# Who controls it, and every takeover with who held it and when it began and ended.
curl -sS https://api.styne.ai/browsers/$BROWSER_ID/control -H "Authorization: Bearer $STYNE_API_KEY"

# Return control to the agent.
curl -sS -X DELETE https://api.styne.ai/browsers/$BROWSER_ID/control -H "Authorization: Bearer $STYNE_API_KEY"
```

While a person holds control, a client command that clicks, types, scrolls, emulates a device or navigates
(`Input.*`, `Emulation.*`, `Page.navigate`, `Page.reload`, `Page.navigateToHistoryEntry`) is answered at once with a
DevTools error that names `Control.heldByHuman`, and the browser does not receive it. Reads such as screenshots,
`Runtime.evaluate` and the DOM keep working, so the agent can see what the person does. Control lasts five minutes and a
repeated `POST` renews it; it ends when the person returns it, when it lapses, or when the session ends. Another holder
gets `409` while the browser is held. Each takeover is an audit row: the holder, the time control began and the time and
reason it ended (`returned`, `expired` or `browser-ended`).

## CAPTCHAs

The `captcha` field of a start says what the session does with a CAPTCHA on a page:

| Value | What happens |
| - | - |
| `click` (default) | The checkbox of a Turnstile, reCAPTCHA or hCaptcha widget is clicked for you. |
| `solve` | A challenge the click does not pass is solved for you: reCAPTCHA v2 and v3, hCaptcha, Turnstile, GeeTest v3 and image-text CAPTCHAs. |
| `off` | Nothing; your code handles every widget. |

With `solve` the answer is put into the page (the widget's response field, or the token a reCAPTCHA v3 page asks for)
and your code submits the form. Solving is metered per solved challenge, at most 10 attempts per session, failed ones
included but not billed. If the solver cannot be reached the session carries on as `click`, and the start never fails
because of it. Any other value is refused with 422.

[//]: # "smoke: not executed, a solve start needs an account with the solver enabled and a page with a CAPTCHA"

```bash theme={"theme":"css-variables"}
curl -sS https://api.styne.ai/browsers -H "Authorization: Bearer $STYNE_API_KEY" \
  -H 'Content-Type: application/json' -d '{"captcha":"solve"}'

# The session's mode and counts: widgets clicked and passed, challenges solved, failed solves, the latest error.
curl -sS https://api.styne.ai/browsers/$BROWSER_ID/captcha -H "Authorization: Bearer $STYNE_API_KEY"
```

```text theme={"theme":"css-variables"}
{ "mode": "solve", "clicks": 1, "passed": 1, "solves": 1, "solve_failures": 0, "last_error": "" }
```

## Sleep, wake, fork and rewind

A browser session is a sandbox with the same id, so the sandbox lifecycle calls take a browser id as it is. Everything
in the browser comes along: open tabs, cookies, local and session storage, and the state of each page's scripts.

| Call | What happens to the browser |
| - | - |
| `POST /sandboxes/{id}/pause` | The browser sleeps with its memory and leaves the running count. |
| `POST /sandboxes/{id}/resume` | It wakes as it was. Read `GET /browsers/{id}` for a fresh `cdp_url` and connect again. |
| `POST /sandboxes/{id}/fork` with `{"count": 3}` | Three copies of the running browser, each logged in wherever the original was. The answer is a list; each entry's `sandbox.sandboxID` is a browser id with its own `cdp_url`. |
| `POST /sandboxes/{id}/checkpoints` with `{"label": "cart filled"}` | Saves the browser as the next step of its timeline and answers its `checkpointID`. |
| `POST /sandboxes/{id}/rewind` with `{"checkpoint": "<checkpointID>"}` | The browser goes back to that step and keeps its id. |

Log in once, then fork the logged-in browser for parallel work:

[//]: # "smoke: not executed, it needs the id of a logged-in browser session"

```bash theme={"theme":"css-variables"}
curl -sS -X POST https://api.styne.ai/sandboxes/$SESSION_ID/fork \
  -H "Authorization: Bearer $STYNE_API_KEY" \
  -H "content-type: application/json" \
  -d '{"count": 3, "timeout": 900}'
```

A browser is metered per second while it is awake; asleep it accrues no seconds and no charge, and `GET /v1/run/usage` shows both (`used.browser_seconds`, and per day `running_seconds`, `paused_seconds`, `paused_cost_micro`). Pause tiers, what a sleeping browser keeps and how it is metered are in [Timeouts, pause and resume](https://docs.styne.ai/pause-tiers.md).

## Steps you can verify

An agent can say what it just did and what must be true on the page afterwards. The check runs inside the browser on the
live page, so a step is `verified` only when the page shows it:

[//]: # "smoke: not executed, it needs the id of a running browser session"

```bash theme={"theme":"css-variables"}
curl -sS -X POST https://api.styne.ai/browsers/$BROWSER_ID/steps -H "Authorization: Bearer $STYNE_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{"name":"signed in","verify":{"url_matches":"/account$","selector_exists":"#user-menu"}}'
```

The answer holds `verified`, the result of each check, the page's address and title, and the state of the whole run
(`run.verified` is true when there are steps and every one passed). Checks: `url_matches` (a regular expression),
`selector_exists`, `text_contains`, `js_expr` (a JavaScript expression that is truthy) and `cookie` (a cookie name).
Each step keeps a screenshot, the page's HTML and the resources it loaded for seven days:
`GET /browsers/{id}/steps` lists them, `GET /browsers/{id}/steps/{n}` reads one, and
`GET /browsers/{id}/steps/{n}/screenshot` returns its JPEG. A browser records at most 500 steps.

When the browser was started from a profile that signs in with a [vault item](https://docs.styne.ai/vault.md) and a step fails on a page that
looks signed out, the answer adds `"logged_out": true` and `relogin`, and the profile signs in again on its own.

## Browserbase and Steel clients

The Browserbase session API is served under `https://api.styne.ai/browserbase` and the Steel session API under
`https://api.styne.ai/steel/v1`, both with your Styne API key. Extensions work on both: Browserbase's
`POST /v1/extensions` (the `file` form part) and `GET|DELETE /v1/extensions/{id}` are served under
`https://api.styne.ai/browserbase`, and a session takes `extensionId`; Steel's `extensionIds` takes the ids `POST /extensions`
answers. All of them use the same uploads as [Extensions](#extensions). See [Switch from Browserbase](https://docs.styne.ai/migrate-browserbase.md)
and [Switch from Steel](https://docs.styne.ai/migrate-steel.md).

## Keep a session through a dropped socket

A CDP socket can close while the browser keeps running: a network change, a proxy on the path, a client restart. The session
is not lost. Chrome, its contexts and its pages stay on the server until `expires_at`, so connect again with the same
`cdp_url` (or read it again with `GET https://api.styne.ai/browsers/{id}`) and continue from the pages that are open.

The SDKs do that for you. `run` is called again after each reconnect with the attempt number; start it from `context.pages`,
not from a page object you kept.

Python (`pip install styne-sdk`):

```python theme={"theme":"css-variables"}
from playwright.sync_api import sync_playwright
import styne

def work(pw_browser, attempt):
    context = pw_browser.contexts[0]
    page = context.pages[0] if context.pages else context.new_page()
    if attempt == 0:
        page.goto("https://example.com")
    return page.title()

with styne.Client() as client, client.browsers.create() as browser, sync_playwright() as p:
    title = browser.with_reconnect(p.chromium.connect_over_cdp, work)
```

`AsyncBrowser.with_reconnect` is the asyncio form (`connect` and `run` are coroutine functions).

Node (`npm install styne-sdk`):

```javascript theme={"theme":"css-variables"}
import { Styne } from "styne-sdk";
import { chromium } from "playwright-core";

const styne = new Styne();
const browser = await styne.browsers.create();
const title = await browser.withReconnect(chromium, async (pw, attempt) => {
  const context = pw.contexts()[0];
  const page = context.pages()[0] ?? (await context.newPage());
  if (attempt === 0) await page.goto("https://example.com");
  return page.title();
});
```

Both retry up to 5 times by default (`max_reconnects` / `maxReconnects`) with a growing pause, and raise every other error
unchanged. Without an SDK, a reconnect is one `GET /browsers/{id}` followed by a new CDP connection to the returned `cdp_url`.

## Downloads

A page can download a file, for example an export button. Playwright's `download.saveAs` and `download.createReadStream`
do not work over a remote CDP socket, so the browser saves the file in its own VM and you read it through the files API.

The simplest way is `"downloads": true` on the start: every download of the session is saved into
`/home/browser/Downloads` under the name the site gives it, whichever client clicked, with no extra socket. List and read
the files:

```bash theme={"theme":"css-variables"}
curl -sS "https://api.styne.ai/sandboxes/$BROWSER_ID/files/list?path=/home/browser/Downloads" -H "Authorization: Bearer $STYNE_API_KEY"
curl -sS "https://api.styne.ai/sandboxes/$BROWSER_ID/files?path=/home/browser/Downloads/report.csv" -H "Authorization: Bearer $STYNE_API_KEY" -o report.csv
```

On the `/v1` API the same reads are `GET /v1/browsers/{br}/files/list?path=...` and `GET /v1/browsers/{br}/files?path=...`.

To choose the folder per download, or to wait for each file, tell the browser where to save from your own socket instead.
It works next to any client that drives the session.

With the SDKs:

[//]: # "smoke: not executed, it needs a running browser session and a page that downloads a file"

```python theme={"theme":"css-variables"}
import styne

with styne.Client() as client, client.browsers.create() as browser:
    page = ...  # your Playwright page, connected to browser.cdp_url
    with browser.downloads() as downloads:  # pip install 'styne-sdk[downloads]'
        page.click("#export")
        data = downloads.read(downloads.next())
```

[//]: # "smoke: not executed, it needs a running browser session and a page that downloads a file"

```javascript theme={"theme":"css-variables"}
const downloads = await browser.downloads(); // Node 22 or newer; on Node 20 pass { webSocket } from the `ws` package
await page.click("#export");
const bytes = await downloads.read(await downloads.next());
downloads.close();
```

Without an SDK, open a second CDP socket on the same `cdp_url`, send
`Browser.setDownloadBehavior` with `{"behavior": "allow", "downloadPath": "/tmp/downloads", "eventsEnabled": true}`, and
wait for `Browser.downloadProgress` with `state` `completed`. The file is `downloadPath/<suggestedFilename>`, where
`suggestedFilename` comes from `Browser.downloadWillBegin`. Keep that socket open until the download has finished. Read
the file with `GET https://api.styne.ai/sandboxes/{id}/files?path=/tmp/downloads/<name>`, where `{id}` is the id `POST /browsers`
answered; on the `/v1` API a browser `br_x` keeps its files in the VM `vm_x`, so read
`GET https://api.styne.ai/vms/vm_x/files?path=...` (the SDKs do this for you). A file the page builds itself can also be read
without a download: `fetch` it in the page and return it from `Runtime.evaluate` as base64. Uploads go the other way:
`PUT` the file to the same files path, then point `setInputFiles` at it.

## Operations

| Method | Path | What it does |
| - | - | - |
| `POST` | `/browsers` | Start a Chromium session |
| `GET` | `/browsers/{id}` | Read a browser session and its CDP endpoint |
| `POST` | `/browsers/{id}/steps` | Record a step and check that the page shows what you expect |
| `GET` | `/browsers/{id}/steps` | List the session's steps and whether the run is verified |
| `GET` | `/browsers/{id}/steps/{n}` | Read one step with the page's HTML and the resources it loaded |
| `GET` | `/browsers/{id}/steps/{n}/screenshot` | The step's screenshot as a JPEG |
| `POST` | `/browsers/{id}/control` | Take control of a browser as a person; the answer carries a control\_id and a cdp\_url |
| `GET` | `/browsers/{id}/control` | Show who holds the browser and every takeover with its holder and times |
| `DELETE` | `/browsers/{id}/control` | Return control of a browser to your client |
| `GET` | `/browsers` | List the account's browser sessions |
| `DELETE` | `/browsers/{id}` | Stop a browser session |
| `GET` | `/browsers/{id}/trace` | A browser session's timeline: navigations, actions, documents, failed requests, console warnings and errors |
| `GET` | `/browsers/{id}/network` | A browser session's requests with status, type, size and duration |
| `GET` | `/browsers/{id}/console` | A browser session's console lines and browser log entries |
| `GET` | `/browsers/{id}/replay` | A browser session's replay frames (its screenshots, screencast frames and a paced screencast) |
| `GET` | `/browsers/{id}/metrics` | A browser session's CPU, memory and requests in flight over time |
| `GET` | `/browsers/{id}/unblock` | A browser session's unblock mode and what each step of the block chain did |
| `GET` | `/browsers/{id}/captcha` | A browser session's captcha mode and what its challenge watcher did |
| `GET` | `/browsers/concurrency` | The account's browser concurrency: limit (null when the account has no ceiling), running, queued, and creates the limit refused in the last hour |
| `POST` | `/extensions` | Upload a Chrome extension: the zip of an unpacked extension, as a form's file part or the body |
| `GET` | `/extensions` | List the account's extensions |
| `GET` | `/extensions/{id}` | Read an extension |
| `DELETE` | `/extensions/{id}` | Delete an extension |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.