For AI agents: a documentation index is available at /llms.txt
Skip to main content

Continue Browser State Across Runs

Create a long-lived browser session via the Session API, store data like cookies and localStorage, disconnect, then reconnect later and verify state continues across runs.

Short-lived reconnections

Need to briefly pause your script and resume the same browser within seconds or minutes? See Disconnect and Reconnect to a Browser for a simpler approach that doesn't require managing sessions via API.

Prerequisites

Steps

The Session API gives you full REST control over session lifecycle. Create a session with a TTL, connect and set state, disconnect safely, then reconnect and verify your data is still there.

Use the Session API REST endpoints to create, connect to, and manage long-lived browser sessions.

View Full Code on GitHub

1. Create a session

curl -X POST "https://production-sfo.browserless.io/session?token=YOUR_API_TOKEN_HERE" \
-H "Content-Type: application/json" \
-d '{
"ttl": 300000,
"stealth": true,
"headless": false
}'

The response returns connect (WebSocket URL) and stop (DELETE URL) fields.

2. Stop the session when done

curl -X DELETE "STOP_URL_FROM_STEP_1&force=true"

Next steps