Skip to main content
BAP sessions keep browser state alive across commands. When a client disconnects, the server parks the browser pages and contexts instead of destroying them. On reconnect with the same session ID, state is restored instantly.

How Sessions Work

Named Sessions

Use the -s flag to create and reuse named sessions:
Without -s, the CLI auto-generates a session ID as cli-<port> (e.g., cli-9222). This means even without explicit naming, your session persists across commands on the same port.

Dormant Session Lifecycle

1

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).
2

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.
3

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.
4

Expire

After TTL, dormant sessions are destroyed. Owned browsers are closed. CDP-attached (borrowed) browsers have their reference dropped without closing the external browser process.

What Gets Preserved

Ghost Page Filtering

When a dormant session is restored, some pages may come back as about: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.
Without this filter, commands after session restore would silently operate on a blank page. BAP handles this transparently.

MCP vs CLI Sessions

MCP clients get the current destroy-on-disconnect behavior. Session persistence is a CLI-specific feature designed for agents that make multiple sequential shell commands.

Configuration

The dormant session TTL is configured on the server:

Practical Patterns

Multi-task agent

Long-running workflow with breaks