How Sessions Work
Named Sessions
Use the-s flag to create and reuse named sessions:
Dormant Session Lifecycle
Park
When a client disconnects, the server parks the session. All state is preserved: browser instance, browser contexts, open pages, page-to-context mappings, element registries, frame contexts, and session approvals.The server also snapshots
context.storageState() for crash recovery (best-effort, non-blocking).TTL countdown
A dormant session has a configurable TTL (default: 300 seconds / 5 minutes). If no client
reconnects within the TTL, the session expires and all resources are cleaned up.
Restore
When a client connects with a matching
sessionId, the server checks if the parked browser is
still alive. If so, all state is transferred to the new client connection. If the browser crashed
during dormancy, the server starts fresh.What Gets Preserved
| State | Preserved? | Notes |
|---|---|---|
| Browser instance | Yes | Stays running during dormancy |
| Open pages and URLs | Yes | Including scroll position and form state |
| Browser contexts | Yes | Including cookies and localStorage |
| Element registries | Yes | Stable refs remain valid |
| Frame contexts | Yes | iframe state preserved |
| Session approvals | Yes | Previously approved actions stay approved |
| Storage state snapshot | Yes | Best-effort crash recovery backup |
Ghost Page Filtering
When a dormant session is restored, some pages may come back asabout:blank if the browser discarded them during dormancy. BAP filters these out automatically — any page with url === "about:blank" is treated as non-existent, and ensureReady() creates a fresh page.
MCP vs CLI Sessions
| Behavior | CLI | MCP |
|---|---|---|
| Session persistence | Yes (auto sessionId) | No (destroy on disconnect) |
| Default session ID | cli-<port> | None |
| Named sessions | -s=<name> | Not supported |
Configuration
The dormant session TTL is configured on the server:| Option | Default | Description |
|---|---|---|
dormantSessionTtl | 300s | Time before a parked session is destroyed |
session.maxDuration | 3600s | Maximum total session duration |
session.idleTimeout | 600s | Idle timeout before server-side disconnect |