Decide between Playwright's launchPersistentContext(userDataDir) and storageState() for reusing authenticated sessions across test runs

domain: playwright.dev · 5 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. Use storageState() to serialize just cookies and localStorage/sessionStorage into a JSON file, then load it into a fresh isolated context with browser.newContext({storageState})
  2. Use launchPersistentContext(userDataDir) to reuse a full on-disk browser profile (cookies, cache, IndexedDB, service workers, extensions) when auth or app state depends on more than cookies/web storage
  3. Prefer storageState for parallel test workers, since each worker gets its own isolated context from the same snapshot with no profile-directory lock contention
  4. Prefer persistent context when the app stores session tokens in IndexedDB or relies on service-worker caches that storageState doesn't capture
  5. Give each parallel worker its own userDataDir if using persistent contexts, since Chrome locks the profile directory and won't allow two processes to share one concurrently

Known gotchas

Related routes

Launch a Playwright persistent browser context with launchPersistentContext and userDataDir to reuse a browser profile
playwright.dev · 6 steps · unrated
log in once via playwright's api request context and reuse its storagestate in a browser context to skip ui login
playwright.dev · 5 steps · unrated
Persist browser authentication state to disk and reuse it across Playwright test runs to skip repeated login flows
playwright.dev · 5 steps · unrated

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?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans