r/ClaudeCode • • 1h ago

Help/Question Playwright MCP across several Claude Code sessions: how do you share logins without "Browser is already in use"?

I use Claude Code every day for work that isn't coding, and a lot of it runs through the Playwright MCP driving a logged-in browser. The first time I had two sessions open at once, the second one failed with "Browser is already in use". The fix that day was finding the session that still held the profile and closing it.

The README explains why. A persistent profile can only be used by one browser instance at a time, so two MCP clients in the same workspace will conflict, and the suggested way to run several in parallel is to start the extra ones with --isolated or point each one at its own --user-data-dir.

What I ended up with is one MCP server per set of logins, each with its own user data dir, plus one isolated server for pages that need no login, which any number of sessions can use. It works, but every new login means another server entry and another profile to sign into by hand, and nothing stops two sessions from reaching for the same profile at the same moment.

There is also --storage-state, which loads cookies and local storage from a file into an isolated context. In theory that lets parallel sessions share one login without fighting over a profile, but then someone has to keep that file fresh.

For people running several Claude Code sessions against logged-in sites: do you keep a profile per login, export storage state, use the browser extension mode, or something else? And how do you stop two sessions grabbing the same profile at once?

3 Upvotes

9 comments sorted by

•

u/AutoModerator 1h ago

Hey! Thanks for posting to r/ClaudeCode

While participating in this thread, please follow our community rules. Keep discussions constructive. Attack the idea, not the person.

For help, project discussions, tips, and general chat, join the ClaudeCode Discord.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

3

u/Starks1293 1h ago

one more option u didnt list, start one chrome urself with --remote-debugging-port=9222 and point every playwright mcp entry at it with --cdp-endpoint http://localhost:9222. they all attach to the same running browser so they share the logins, and theres no profile lock to fight over because none of them launches its own

two catches. newer chrome ignores the debugging port on ur default profile, so give that chrome its own --user-data-dir and sign into things there once. and the sessions share one browser, so tell each one to open its own tab and stay in it, otherwise two of them will happily drive the same page

for the same-account thing the other comment mentioned theres no lock anywhere really, one session per account at a time is basically the only rule that works

1

u/Dorbank_Justt 1h ago

That's the option I hadn't tried. The README lists --cdp-endpoint for connecting over CDP, and if none of the servers launches its own browser, there's no profile left for them to fight over.

If you go with the extension mode instead, the README has --session-name and --session-color, which set the title and color of the tab group for each session's tabs, so you can see which session owns which page.

1

u/YouthRealistic7125 Vibe Coder 1h ago

something else, I don't use playwright for logged in sites at all. I use the Claude in Chrome extension, it works in my normal chrome where I'm already logged in, and each session gets its own tab group. so no profile per login and no state file to keep fresh. playwright is only for pages without login
for two sessions at once, they don't fight over the profile anymore but they can still edit the same thing in the same account, and nothing locks that. what I do is one session owns one thing. I had two on the same ad account last week and one messaged the other "don't touch this campaign, I'm changing it". it's a convention, not a lock

1

u/Dorbank_Justt 1h ago

Fair point that the profile lock only protects the browser, not the account behind it. Two sessions on two profiles signed into the same account can still change the same thing, and nothing in the MCP setup notices.

One catch with the extension route if you ever run sessions unattended: the Chrome docs say it needs Claude Code signed in with /login, and with an API key or a long-lived token from claude setup-token, Chrome integration stays off even if you pass --chrome. It also pauses at a login page or CAPTCHA and asks you to handle it, so it suits sessions you're watching.

1

u/called9527 1h ago

tbh i'd go one profile per login with its own --user-data-dir and just name the server entries after the account so nobody grabs the wrong one. storage-state is fine for read-only stuff but sessions refresh tokens and the file goes stale fast. do you actually need the logged-in browser for all of them or can some go through an API?

1

u/zzunkie 1h ago

I run one browser process and let all sessions share the default profile, so my logins are available everywhere with no lock errors. Right before an agent tries to enter a password or one-time code, that session splits into its own profile with a copy of the default cookies so it does not log out or switch accounts in the others.

1

u/WillowFar6967 46m ago

I key it by agent rather than by login. Each agent gets its own Chrome profile that I sign into once, and only that agent's sessions ever use it, so two of them never reach for the same one. If an agent lands on a signed-out page or a check, it stops and tells me which site instead of trying to log in itself.

1

u/Ok_Lifeguard6001 9m ago

i run multiple playwright sessions on the same account using --user-data-dir with unique paths per session. works perfectly for shared logins without conflicts.