Playwright MCP Browser Already in Use: Parallel Agents
Prepared and checked using AI. Sources are linked in the article.
If Playwright MCP reports “browser already in use” with multiple agents, add --isolated to each agent’s MCP server arguments, or give every concurrent browser a different --user-data-dir. A persistent profile can only be used by one browser instance at a time, so launching another agent against that same profile creates a conflict.
The examples below require Node.js 18 or newer, an MCP client, and a preinstalled playwright-mcp executable available on the client’s PATH. They use the mcpServers JSON format; adapt the surrounding configuration to your client’s format while keeping the server arguments. If the executable is installed elsewhere, set command to its absolute path.
Why separate worktrees can still collide
The default persistent profile name incorporates the browser channel and a hash of the MCP client’s workspace root. Different workspace roots therefore get different default profiles. However, separate agent sessions can still collide when their clients advertise the same workspace root or explicitly select the same profile directory.
Check the profile path in the error and compare the affected agents’ launch settings. Treat browser isolation as a separate setting from working-copy isolation. For the wider process setup, see managing MCP servers across parallel agents.
Use —isolated for disposable browser sessions
With --isolated, browser profile state stays in memory. Put this configuration in each agent’s MCP client settings:
{
"mcpServers": {
"playwright": {
"command": "playwright-mcp",
"args": ["--isolated"]
}
}
}
Use this approach when agents should start with fresh browser state. Each client can launch its own server with the same arguments without competing for a persistent profile directory.
Closing the browser ends the isolated session and discards its storage state. If the task needs authentication again later, load saved state as described below.
Do not combine --isolated with --user-data-dir; these select incompatible profile modes.
Use separate —user-data-dir paths to retain logins
Choose persistent profiles when each agent should retain its own login and browser state between sessions. The --user-data-dir option selects a custom profile directory.
For example, give agents A and B separate absolute profile paths. Agent A’s configuration could be:
{
"mcpServers": {
"playwright": {
"command": "playwright-mcp",
"args": [
"--user-data-dir=/home/dev/.local/share/playwright-mcp/agent-a"
]
}
}
}
In agent B’s configuration, replace the args array with:
[
"--user-data-dir=/home/dev/.local/share/playwright-mcp/agent-b"
]
Replace these illustrative paths with locations on your machine. Allocate a directory per concurrently active browser, including multiple sessions of the same coding agent. Copying one persistent-profile configuration unchanged into every client recreates the conflict.
After changing launch arguments, restart the affected MCP server through its client so the new process receives them.
Load authentication into isolated sessions
You can keep disposable browser sessions while supplying initial authentication through --storage-state. To create that file through MCP, enable --caps=storage and save the current browser state with browser_storage_state.
The save destination must be permitted by the server’s file-access settings; by default, file access is restricted to workspace roots. For example, with /home/dev/project as an allowed workspace root, create playwright/.auth inside it and add playwright/.auth to .gitignore before saving /home/dev/project/playwright/.auth/auth-state.json:
- Add
--caps=storagealongside--isolatedin the server arguments and restart the server. - Complete the application’s login flow.
- Ask the agent to call
browser_storage_statewith this argument:
{
"filename": "/home/dev/project/playwright/.auth/auth-state.json"
}
For subsequent sessions, use this args array with the same preinstalled executable:
[
"--isolated",
"--storage-state=/home/dev/project/playwright/.auth/auth-state.json"
]
This loads saved cookies and local storage into the isolated browser context. It supplies initial state rather than turning the session into a persistent profile.
Keep authentication files out of repositories: saved browser state can contain credentials that allow account impersonation. Separate browser contexts also do not separate application accounts. When concurrent tasks change server-side state, give them different accounts or independent test data; see isolating test databases for parallel agents.
If the conflict continues
Check the effective launch settings before deleting anything:
- Confirm that every affected client received
--isolated, or that every persistent browser uses a distinct directory. - Close the browser or server that owns the conflicting profile before reusing that directory. Avoid deleting profile contents while another session is using them.
- Inspect
PLAYWRIGHT_MCP_USER_DATA_DIRand any config file for an unintended shared path. Configuration precedence is command-line arguments over environment variables over the config file. - If using a shared HTTP server, check for
--shared-browser-context. That flag deliberately shares one context between connected clients; omit it when clients need separate contexts.
Where Parallel Code fits
Parallel Code is our free, open-source desktop app for macOS and Linux that runs several coding agents in parallel, each in its own git worktree. Use the browser configuration above alongside those worktrees to give concurrent tasks separate browser state. Its diff-first review surface helps you review the resulting code changes.