Demonstrates Browserless Persisting State using the REST Session API. Browser data (cookies, localStorage, cache) persists on disk for the session's TTL (7 days), surviving browser restarts. Reconnect anytime without re-authenticating.
- Creates a session via
POST /sessionwithprocessKeepAliveto keep the browser alive during 2FA - Connects, enters ProtonMail credentials, detects the 2FA page, then disconnects (browser stays alive)
- You enter your 2FA code; it reconnects to the still-alive browser, types the code, waits for the inbox
- Takes a screenshot and closes the browser (session data persists on disk)
- "Refresh screenshot" opens a new browser process (cookies restored from disk — still logged in), takes a screenshot, and closes
- "Delete browser state" logs out, closes the browser, and sends
DELETEtosession.stopto permanently remove the session
npm installBROWSERLESS_TOKEN=your_token_here node index.jsOpen http://localhost:3001 in your browser.
| Variable | Default | Description |
|---|---|---|
BROWSERLESS_TOKEN |
YOUR_API_TOKEN_HERE |
Your Browserless API token |
BROWSERLESS_ENDPOINT |
production-sfo.browserless.io |
Browserless endpoint |
PORT |
3001 |
Express server port |
- Session API —
POST /sessioncreates a session; response includesconnect(WSS URL) andstop(DELETE URL) processKeepAlive— Keeps browser process alive for N ms after disconnect. Within that window, reconnecting restores the full live state- Persisted data — After
processKeepAliveexpires, data (cookies, localStorage) is still restored from disk on reconnect session.connect— Same URL works for every reconnect (unlike Standard Sessions which generate a new endpoint each time)session.stop—DELETEthis URL to permanently remove the session and all its data