log in once via playwright's api request context and reuse its storagestate in a browser context to skip ui login
domain: playwright.dev · 5 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗
Steps
create a standalone APIRequestContext with playwright.request.newContext() (not tied to any page) and call the login endpoint directly with the request fixture
call requestContext.storageState({ path: 'playwright/.auth/state.json' }) to persist the cookies and origin storage produced by the API login
in a browser test project, configure use.storageState to point at that same file so browser.newContext() starts already authenticated
verify the authenticated state by navigating directly to a protected page and asserting no redirect to a login screen occurs
store the playwright/.auth directory outside version control and regenerate it via a setup project or globalSetup step
Known gotchas
storage state is interchangeable between APIRequestContext and BrowserContext, but only cookies and localStorage/sessionStorage are captured -- server-side session data tied to other signals (e.g. IP or device fingerprint checks) will not transfer
an APIRequestContext created via playwright.request.newContext() does not automatically share cookies with a page; the storageState file is the only bridge between the two
Give your agent this knowledge — and 15,500+ more routes
One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp
Need this verified for your stack — or a route we don't have yet?