Transfer Cookies and Storage Between Sessions
Extract and inject browser state - cookies, localStorage, and sessionStorage - across sessions to preserve login and user data without re-authenticating.
Why You Need This
Your agent needs to stay logged in across sessions. Without a way to preserve authentication state, every new session starts from scratch - your agent has to repeat the login flow each time. That wastes time, risks triggering security alerts from frequent logins, breaks on MFA prompts, and burns LLM tokens if your agent uses AI to navigate login pages.
The Context Service solves this. It captures everything the browser remembers about a user's session - login cookies, user preferences in localStorage, shopping cart data in sessionStorage - and lets you inject that state into a new session. Your agent logs in once, saves the context, and skips login entirely in every future session.
interface SessionContext {
cookies?: Cookie[];
localStorage?: Record<string, Record<string, string>>;
sessionStorage?: Record<string, Record<string, string>>;
}
Before You Begin
You need an active session with a connected page before you can extract or inject context. If you have not set that up yet, see Connect to a session.
Framework Agnostic
The Context Service auto-detects whether you pass a Puppeteer Page or a
Playwright Page/BrowserContext. The same API works with both - you never
need to specify which adapter you're using.