> Source: https://vitna.ai/docs/web/browser
> Raw Markdown: https://vitna.ai/docs/web/browser.md
> Corpus index: https://vitna.ai/llms.txt
# Browser API
Drive managed Chromium or granted CloakBrowser instances over CDP WebSockets with Playwright or Puppeteer, isolated profiles, country routing, and explicit session limits.
```text
GET /v1/browser (WebSocket upgrade)
```
Drive a real Chromium with Puppeteer, Playwright or any Chrome DevTools
Protocol (CDP) client. Each connection launches one browser for that session
and removes it, with its profile, when the connection closes. Scripts, clicks,
typing, forms and screenshots are the client's to send. The endpoint is off
unless the operator sets `VITNA_WEB_BROWSER_API=true`.
Connect with a `vitna_web_` key in the `Authorization` header. The website
relay does not carry WebSockets, so connect to the Web service's own origin:
```js
import { chromium } from "playwright";
const browser = await chromium.connectOverCDP("wss://web.example.com/v1/browser", {
headers: { Authorization: `Bearer ${process.env.VITNA_WEB_KEY}` },
});
const context = await browser.newContext();
const page = await context.newPage();
await page.goto("https://example.com/");
await browser.close();
```
Puppeteer's `connect` takes the same endpoint as `browserWSEndpoint` and the
header in `headers`. Both the JavaScript SDK (`vitna.browserConnection(...)`)
and Python SDK (`vitna.browser_connection(...)`) construct the authenticated
WebSocket URL and headers directly. The relay is tested with Playwright's
`connectOverCDP` and with a raw CDP client. Add `?country=US` to select an
operator proxy route that serves that country, as page reads do, and
`?network=residential` (or `isp`, `datacenter`) to use only routes of that kind.
A session has no retries to step up through, so without `network` it uses the
cheapest configured route. Selecting a country automatically synchronizes the
browser's `--lang` and `TZ` timezone unless explicitly overridden with
`?language=BCP47` (such as `de-DE`) or `?timezone=IANA` (such as
`Europe/Berlin`). Add `?session=NAME` (1 to 64 letters, numbers, underscores or
hyphens) to keep a route and its provider address from one session to the next,
as `session` does for page reads: the provider is asked for the same address
whenever that key opens a session of that name, and an unnamed session is given
a fresh one. Whether the address is held is the provider's to decide. Add
`?persist=true` alongside `session` to hydrate and persist tenant-isolated
cookies across sessions (backed by the encrypted SQLite session store when
configured, and clearable via `DELETE /v1/sessions/NAME`). No other parameter
is accepted.
The browser starts before the handshake completes, so every refusal is an
ordinary HTTP answer with the JSON error body:
| HTTP | Codes |
|---|---|
| 400 | `invalid_request`, `country_unavailable`, `network_unavailable` |
| 401 | `unauthorized` |
| 404 | `not_found` when the Browser API is not enabled |
| 426 | `upgrade_required` for a request that is not a version 13 WebSocket upgrade |
| 429 | `session_limit`, `service_busy`, `daily_limit`, `rate_limited`, with `Retry-After` |
| 503 | `browser_unavailable`, `service_unavailable` |
### What a session may ask of its browser
Every command passes an allowlist before it reaches the browser. A refused
command is answered with a CDP error, `-32601` for a method that is not
available and `-32602` for parameters that are not, and the browser never
sees it. The relay refuses what would reach past the session:
- **This machine's files**: `DOM.setFileInputFiles`, `Page.handleFileChooser`,
`Input.dispatchDragEvent` carrying files, `Network.loadNetworkResource` and
`DOM.getFileInfo`. A navigation by `Page.navigate`, `Target.createTarget` or
a rewritten `Fetch.continueRequest` must be to an `https:`, `http:` or
`data:` URL, or `about:blank`. File uploads are therefore unavailable.
- **The network guard**: `Target.createBrowserContext` with `proxyServer`,
`proxyBypassList` or `originsWithUniversalNetworkAccess`, and
`Target.setRemoteLocations`.
- **The machine itself**: `Tethering`, `SystemInfo`, `Extensions`, `PWA`,
`Cast`, `Memory` and `Tracing`, and every `Browser` method except
`getVersion`, `close`, the window and permission methods, and
`setDownloadBehavior`, which is rewritten as below.
- **The relay**: `Target.exposeDevToolsProtocol` and
`Target.sendMessageToTarget`. Attach with `flatten: true`, as Puppeteer and
Playwright do.
Downloads are rewritten rather than refused: `Browser.setDownloadBehavior`
and `Page.setDownloadBehavior` are forwarded with `behavior: "deny"`, because
clients ask for downloads into a directory on their own machine. A domain or
method not on the allowlist, including one added in a later Chromium, is
refused until it is reviewed.
The relay keeps one browser session for itself. It denies downloads in every
new browser context before the context's id reaches the client, and it closes
any page past the page limit. Its session id is refused in a client's
commands and its events are not forwarded.
Network access is the same as for page reads: public HTTPS destinations on
port 443 through the guarded proxy, each address checked and pinned, within
the operator's `VITNA_WEB_ALLOWED_HOSTS`. Secure WebSockets are carried; QUIC
and unproxied UDP are disabled. A plain HTTP page is answered with 403 by the
guard itself.
### Session limits and close codes
| Environment | Default | Meaning |
|---|---|---|
| `VITNA_WEB_BROWSER_API` | `false` | `true` enables `/v1/browser` |
| `VITNA_WEB_BROWSER_API_SESSIONS` | 2 | Sessions open at once in this process, 1 to 20 |
| `VITNA_WEB_BROWSER_API_SESSIONS_PER_CLIENT` | 1 | Sessions open at once for one client, at most the process limit |
| `VITNA_WEB_BROWSER_API_SESSION_MS` | 300,000 | Whole-session limit, 10,000 to 3,600,000 |
| `VITNA_WEB_BROWSER_API_IDLE_MS` | 120,000 | Time without a client command, 5,000 to 3,600,000 |
| `VITNA_WEB_BROWSER_API_MAX_BYTES` | 104,857,600 | Network transfer through the guard, both directions, 1 MiB to 10 GiB |
| `VITNA_WEB_BROWSER_API_MAX_PAGES` | 10 | Pages open at once; the relay closes the newest past it, 1 to 100 |
| `VITNA_WEB_BROWSER_API_WARM_STANDBY` | 0 | Pre-warmed standby native Chromium processes for instant local direct connects, 0 to 5 |
A session also allows 10 browser contexts, 2,000 commands awaiting the
browser, 4 MiB per client message and 64 MiB per browser message. Output a
client leaves unread is capped at 64 MiB. The connection closes with:
| Code | Reason |
|---|---|
| 1000 | The client closed the connection, or sent `Browser.close` |
| 1001 | `service_shutdown` |
| 1007 | A message that was not valid UTF-8 or JSON |
| 1008 | A message that was not a command, or `client_not_reading` |
| 1009 | A client message over 4 MiB |
| 1011 | The browser failed while the session ran |
| 4001 | `session_timeout` |
| 4002 | `idle_timeout` |
| 4003 | `transfer_limit` |
| 4004 | `browser_exited`, a browser that exited unasked |
| 4005 | `output_too_large`, a browser message over 64 MiB |
A session is one request against the client's per-minute and daily limits,
or one shared-quota admission. Its browser time, from launch through cleanup,
is recorded as browser milliseconds and priced at
`VITNA_WEB_BILLING_BROWSER_SECOND_MICRO_USD`, like every other browser
operation. A session through a residential or ISP route also records its
transferred bytes for per-GB pricing. The session's entry in `/v1/usage` and
its receipt carry the operation `browser`, the close reason as its outcome,
`closeCode`, `network`, `browserProfile`, `commands`, `refusedCommands` and
`transferredBytes`. `GET /v1/status`
reports `capabilities.browserApi` and, when enabled, `limits.browserApi`,
including live `active` and `available` counts, `execution` (`{"mode":"local"}`,
or the workers and their combined capacity), and when distributed workers are
configured, `fleet` (`healthyWorkers`, `totalWorkers`, `availableCapacity`, and
`failovers`). Its `browserProfile` is the profile the calling
key's sessions launch with.
### Browser profiles
A session's browser is `native` unless the operator grants its account the
`cloakbrowser` profile, the Unblocker's profile of that name: an
operator-installed [CloakBrowser](../unblocker/overview.md#browser-profiles-and-live-checks)
executable, launched with the same fingerprint flags and a 1920 by 947
desktop window. A named session keeps its fingerprint as it keeps its address,
so it returns as the same device; an unnamed one draws a new fingerprint.
```dotenv
VITNA_WEB_BROWSER_API_CLOAKBROWSER_CLIENTS=["acct_ID","pilot"]
VITNA_WEB_BROWSER_API_CLOAKBROWSER_PATH=/opt/cloakbrowser/chrome
```
The grant lists client ids, a static key's name or an account's id, 1 to
1,000 of them. Like a proxy-access grant it is the operator's check on the
customer: confirm who the customer is and what the traffic is for before
adding one. Public signup never adds an account to it. Every other key's
sessions stay native, on `VITNA_WEB_BROWSER_PATH` or the bundled Chromium.
The path is set here when sessions run on this machine, and on each worker
otherwise (below); startup refuses a path without grants, or grants without a
path to launch them. The CloakBrowser
[binary license](https://github.com/CloakHQ/CloakBrowser/blob/main/BINARY-LICENSE.md)
is the operator's to review.
The relay does not solve challenges. A profile changes how the browser
presents itself, and the network guard and allowlist are the same for every
profile. Verification pages, CAPTCHAs and interstitials reach the client as
they would reach any browser, and what to do with them is the client's. This
differs from page reads, where the Unblocker waits on a recognised Cloudflare
challenge for its client.
By default, sessions launch on the Web process's own machine, including when
page reads use owned browser workers. The executable is
`VITNA_WEB_BROWSER_PATH`, or Playwright's bundled Chromium installed by
`npm run web:install` and `npm run web:browser`; a browser channel alone is
not accepted. The browser runs with its sandbox on, so the host must support
it, on Linux through unprivileged user namespaces or the setuid sandbox. A
reverse proxy must pass the upgrade through: `deploy/vitna-web.nginx.conf.example`
has a `location = /v1/browser` block that does.
### Sessions on owned workers
To run sessions on machines you operate, list them in
`VITNA_WEB_BROWSER_API_WORKERS`:
```dotenv
VITNA_WEB_BROWSER_API=true
VITNA_WEB_BROWSER_API_SESSIONS=8
VITNA_WEB_BROWSER_API_WORKERS=[{"id":"browser-a","origin":"https://browser-a.example.com:8792","token":"YOUR_SEPARATE_OPERATOR_TOKEN_AT_LEAST_32_CHARACTERS","sessions":8}]
```
Each worker is the `npm run web:worker` process described under
[owned browser workers](overview.md#owned-browser-workers), with
`VITNA_WEB_BROWSER_WORKER_CDP_SESSIONS` set to the sessions it may hold (1 to
20; unset or `0` leaves it off) and optionally
`VITNA_WEB_BROWSER_WORKER_CDP_WARM_STANDBY` (0 to 5, at most the session count)
to keep standby native Chromium processes pre-spawned on that worker. It uses
its own `VITNA_WEB_BROWSER_PATH`
and `VITNA_WEB_ALLOWED_HOSTS`, with the same rule that a channel alone is not
accepted. `sessions` defaults to 2, up to 20 per worker and 20 workers, and
`VITNA_WEB_BROWSER_API_SESSIONS` may not exceed their total. These workers
are separate from `VITNA_WEB_BROWSER_WORKERS`, so a machine can serve Browser
API sessions without page reads, or both.
The Web process keeps the client's connection, the command allowlist and
every limit above; the worker runs the browser and its network guard. They
share one connection per session, an HTTP upgrade to `/v1/cdp` on the
worker's server authenticated with its operator token, which carries the
DevTools messages and the guard's transfer count. The operator proxy route a
session selects is sent over that connection, credentials included, so give
workers the same trust as the Web host. A worker answers the upgrade only
once its browser is ready. The Web coordinator probes each worker's `/healthz`
at startup and every 15 seconds, applies exponential cooldowns to degraded
workers, and schedules launches health-first (most free sessions first),
failing over to the next healthy worker if a worker is full or cannot launch;
a session already running is never moved. With every worker full, `/v1/browser`
answers 429 `service_busy`. A worker closes a session's browser when its
connection drops, when the worker stops, or 30 seconds past
`VITNA_WEB_BROWSER_API_SESSION_MS` if the Web process never ends it. Its
`/healthz` reports `browserApi` (sessions, profiles, active count, and warm
`standby` stats when configured) alongside `warmPool` stats for page-read
browser reuse.
A worker offers the `cloakbrowser` profile only with its own
`VITNA_WEB_BROWSER_WORKER_CLOAKBROWSER_PATH`, an absolute path, and its native
sessions keep using `VITNA_WEB_BROWSER_PATH`. Grants stay on the Web process.
A worker asked for a profile it cannot launch answers 422 `profile_unavailable`
and is passed over like a full one; when no worker offers the account's
profile, `/v1/browser` answers 503 `browser_unavailable`.