Saved Sessions

Connect with pre-authenticated cookies + localStorage, or save a session on disconnect for reuse

Saved sessions let your Browser API connections start with cookies and localStorage already loaded — no need to log in inside every script.

The flow has two steps: save a session once (log in, then disconnect — Anakin captures the auth state), then load that session on every future run.

The same flow is available in your dashboard and via the /v1/sessions API.


1. Save a session on disconnect

Pass ?save_session=<name> and ?save_url=<target> when connecting. Log in inside your script, then close the browser — the session's cookies + localStorage are captured automatically.

wss://api.anakin.io/v1/browser-connect?save_session=my-login&save_url=https://your-target-site.com
import asyncio
from playwright.async_api import async_playwright

API_KEY = "your_api_key"

async def main():
    async with async_playwright() as p:
        browser = await p.chromium.connect_over_cdp(
            "wss://api.anakin.io/v1/browser-connect?save_session=my-login&save_url=https://your-target-site.com",
            headers={"X-API-Key": API_KEY},
        )
        page = browser.contexts[0].pages[0]

        # Log in
        await page.goto("https://your-target-site.com/login")
        await page.fill("input[name='username']", "your_username")
        await page.fill("input[name='password']", "your_password")
        await page.click("button[type='submit']")
        await page.wait_for_load_state("networkidle")

        # Disconnect — cookies + localStorage are auto-saved
        await browser.close()

asyncio.run(main())

On the next run, load with ?session_name=my-login (see below).

Save parameters

ParameterRequiredDescription
save_sessionYesName for the saved session (must be unique per user)
save_urlYesWebsite URL the session belongs to (e.g. https://amazon.com)

Save error responses

StatusErrorMeaning
503session saving not configuredSaved sessions are temporarily unavailable (contact support)

If you connect with a save_session name that already exists, the connection still works but the save is skipped — pick a fresh name or delete the old one from your dashboard.


2. Load a saved session

Pass ?session_id=<uuid> or ?session_name=<name> when connecting:

wss://api.anakin.io/v1/browser-connect?session_name=my-login

The browser launches with your saved cookies and localStorage already loaded — your script can navigate straight to authenticated pages without logging in again. The session's original exit IP is reused on every load, so logins protected by IP-binding stay valid.

import asyncio
from playwright.async_api import async_playwright

API_KEY = "your_api_key"
SESSION_ID = "your_session_id"  # from dashboard or GET /v1/sessions

async def main():
    async with async_playwright() as p:
        browser = await p.chromium.connect_over_cdp(
            f"wss://api.anakin.io/v1/browser-connect?session_id={SESSION_ID}",
            headers={"X-API-Key": API_KEY},
        )
        page = browser.contexts[0].pages[0]

        # Navigate to an authenticated page — cookies are pre-loaded
        await page.goto("https://amazon.com/your-orders", wait_until="domcontentloaded")
        print("Title:", await page.title())

        await browser.close()

asyncio.run(main())

You can use the session name instead of ID:

wss://api.anakin.io/v1/browser-connect?session_name=my-login

Load parameters

ParameterDescription
session_idUUID of the saved session
session_nameName of the saved session (must be unique per user)

If both are provided, session_id takes precedence. If neither is provided, a fresh browser is launched.

Load error responses

Session validation happens before the WebSocket upgrade, so errors come back as standard HTTP responses:

StatusErrorMeaning
404session not foundSession ID or name doesn't exist for your account
422session has no stored data — save it firstSession was created but never saved — log in and save first
409session is being automatedSession is currently in use by an automation job

Tips

  • Save is on disconnect. Cookies and localStorage are captured when you close the browser, so always end your script with browser.close() (or browser.disconnect() for Puppeteer).
  • Need a confirmed save with a UI? Use the interactive browser session flow instead.
  • Listing and deleting saved sessions is available in your dashboard and via the /v1/sessions API.