Home / Articles

Playwright MCP Profiles: Why Login State Persists or Disappears

Playwright MCP profiles explained: how persistent, isolated and extension modes treat cookies and login state, how to tell which one runs, and security notes.

Publisher: REACTAPP.TOP5 min read1232 words

This article is published in English.

Sources: Understanding Playwright MCP’s “Profile”: Does Login State Survive or Vanish Across persistent (default) / isolated / extension Modes?

Sometimes Playwright MCP is still logged in when a new session starts, with nothing done to make that happen. Other times, on a site that was definitely visited before, the AI meets the login page like a stranger. Both are real experiences, and without the explanation they feel random: why does it remember now, and why does it forget now?

The behavior isn't random. It's by design. Playwright MCP has a setting called a profile, and the mode it starts in changes how login state is handled. What follows sorts out that mechanism.

Persistent is the default

Start Playwright MCP with no options and it runs the persistent profile mode. Cookies, localStorage and auth tokens are written to a directory on disk. End the session, restart the server, and the next run reads the same saved location, which is why login state is still there. It's the same logic as Chrome remembering your last sign-in after a restart.

The storage path follows the pattern ms-playwright/mcp-{channel}-{workspace-hash}. The workspace hash means each project automatically gets its own profile. Login state from project A doesn't leak into project B, and no setup is required for that isolation.

To pick the location yourself, override it with --user-data-dir. That helps on a shared machine where you want the profile path explicit. Open that directory and you'll find cookies and tokens stored as plain files.

One caveat: the docs only say the workspace hash is derived from the working directory and ends up unique per project. They don't describe the hashing algorithm. You don't need the internals. Remember the outcome: different project, different profile.

How isolated mode differs

Start with --isolated and every session begins from a clean, ephemeral context. Close the browser and every cookie and localStorage entry from that session disappears.

That doesn't force a fresh login every time. With --storage-state you can inject an initial state from a JSON file prepared in advance.

npx @playwright/mcp@latest --isolated --storage-state=./auth-state.json

That file is the same kind you can save with Playwright's context.storageState(), the mechanism used for reusing login state in tests, and it works just as well for starting an already-authenticated MCP session. Isolated doesn't mean it remembers nothing. It means it won't keep remembering across sessions by itself, though you can hand it state once at the start.

The choice is simple. If the AI does everyday browser tasks and you want it logged in next time too, stay with persistent. If you need an identical clean state every run, for testing or because you don't want other sessions bleeding in, use isolated and add --storage-state when authentication is needed. When unsure, try the default first. Feeling how it behaves makes the contrast easier to understand.

The third mode: extension

Persistent and isolated both launch their own browser. Extension mode connects to a browser you already have open instead. It's useful when the AI should work with the exact state of a tab you're using by hand, because connecting to your current browser is more direct than letting MCP prepare a profile.

A good case is an internal tool behind two-factor authentication. Playwright MCP can't clear 2FA by itself, and it would be worrying if it could. The quickest path is to connect to the tab where a human has already finished logging in. A saved persistent profile doesn't help much, since once the 2FA session expires you're back to logging in by hand. Extension mode skips that step.

Which mode is running?

Check the startup command in your client config, for example in Claude Code. If --isolated isn't among the server's arguments, it's persistent.

{
  "mcpServers": {
    "playwright": {
      "command": "npx",
      "args": ["@playwright/mcp@latest"]
    }
  }
}

That configuration is persistent. Add "--isolated" and it becomes isolated. Add "--storage-state", "./auth-state.json" as well and it becomes isolated starting from an authenticated state. Reading the arguments tells you immediately.

When unsure whether state really persisted, read the config file first. Judging from behavior alone is tricky: slow network and a fresh profile initialization can look alike.

Named sessions aren't official yet

You may wonder whether multiple login states could be named and swapped, an admin session versus a regular-user session with one command. A feature request on the microsoft/playwright-mcp GitHub issues (#1530) asks for exactly that: creating, saving, restoring and duplicating named persistent contexts, for example to hand an authenticated context between agents or split admin and member roles.

As of this writing, in August 2026, it remains a request and not an implemented feature. Today you work with the three existing modes: persistent (isolation per workspace), isolated plus storage state (explicit initial state) and extension (an existing browser). A session-id parameter may arrive later, but don't build a workflow around it yet.

Security notes for stored state

Whatever mode you choose, remember what the profile directory contains. Cookies and tokens on disk are credentials. Keep the directory out of version control, avoid sharing a machine account with people who shouldn't see those sessions, and delete a profile when the project it belongs to ends. A storage-state JSON file deserves the same care: it can sign someone in without a password, so treat it like a secret and never commit it.

Isolated mode reduces the risk of leftover sessions, because nothing persists after the browser closes, but it doesn't remove the need to protect the file you inject. Extension mode adds its own consideration: the AI is acting inside a live, already-authenticated browser, so anything that tab can do, the agent can attempt. Use it for tasks where that level of access is appropriate and keep sensitive tabs closed.

Troubleshooting checklist

If login behaves unexpectedly, work through these in order. Read the server arguments for --isolated. Check whether a custom --user-data-dir is set. Confirm you are in the same project directory as before, since a different working directory means a different hash and a different profile. If a test needs a repeatable start, switch to isolated and supply storage state. If a session needs a human step such as two-factor, use extension mode.

Choosing a mode

  • Everyday research or work where the AI drives the browser: persistent. Per-project isolation happens automatically.
  • Reproducing identical conditions on every test run: isolated, with --storage-state if authentication is needed.
  • Working from the state of a tab already open: extension.
  • Switching between several named roles: no official feature yet; watch issue #1530.

A frequent trap is using Playwright MCP across several projects: logged in on one, asked to log in constantly on another. That's workspace-hash isolation working correctly. When login state seems to stick or vanish, the first thing to check is the mode.

Related reading from the original series covers the Playwright 1.62 bundling of the MCP server and prompt-injection risks when an AI controls a browser through MCP, both worth a look for safe setup.