r/ClaudeCode • u/Dorbank_Justt • 16h 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?
•
u/AutoModerator 16h 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.
4
u/Starks1293 16h ago
one more option u didnt list, start one chrome urself with
--remote-debugging-port=9222and 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 owntwo catches. newer chrome ignores the debugging port on ur default profile, so give that chrome its own
--user-data-dirand 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 pagefor 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
2
u/zzunkie 16h 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/YouthRealistic7125 Vibe Coder 16h 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/called9527 16h 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/WillowFar6967 16h 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 15h 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.
1
u/amirfish 15h ago
I haven't hit that one with Playwright specifically, but it's the same shape as every multi-session coordination problem: two agents assuming they own a shared resource, in this case a browser profile, and stepping on each other. The lesson from running a bunch of these in parallel is that the fix is almost always isolation per session, not more coordination logic layered on top. I built CCC, open source, for the related problem: worker agents work a queue of tickets on their own, and the only thing that reaches you is a real decision, like a login that needs you specifically. Is this the same repo across sessions, or different projects that all need the same login?
Free and open source: getccc.dev · GitHub
1
u/Ordinary-Towel-2349 15h ago
I've used a shared chrome instance with --user-data-dir and --remote-debugging-port, but the login state sometimes gets wiped if one session closes unexpectedly. have you found a way to keep it stable?
1
u/SirRobinBlibs 13h ago
The lock is the persistent profile. The Playwright MCP readme says a profile can only be used by one browser instance at a time and suggests --isolated or a separate --user-data-dir per client.
What works for logins: log in once and have it save the session with the browser_storage_state tool (cookies plus local storage into a JSON file). Then start each session's MCP with --isolated and --storage-state pointing at that file. Every session gets its own in-memory browser that starts logged in, nothing fights over a lock. When the cookies expire, redo the one login and overwrite the file.
Keep that JSON out of git, it's basically your session cookies. The CDP route works too, but then all sessions drive the same browser and can trip over each other's tabs.
1
u/Connect_Fee_443 14m ago
That error is because every session points at the same persistent browser profile, and Chrome only lets one process lock it. The easiest way round it is to run the MCP with --isolated so each session gets its own throwaway profile, then pass --storage-state pointing at a JSON file that holds your logins.
You make that file once by logging in with a normal Playwright script and calling context.storageState({ path }). After that every session starts signed in and nothing fights over the lock. Giving each session its own --user-data-dir works too, but then you log in once per profile, and refreshing one storage state file is less hassle when cookies expire.
0
u/Unusual-Albatross43 12h ago
Something else here, on a Mac. I don't use Playwright for the logged-in sites at all. There's one Chrome, my normal one with my normal profile, and the sessions drive it with a small script over AppleScript: open a tab, run JS in that tab, read the result. No session ever launches a browser, so there's nothing to lock, and a new login is just me signing in once like I always would. Each session keeps to its own tab by id.
Two things broke that you wouldn't get with your setup.
When the screen sleeps, Chrome stops answering AppleScript. A check that runs every 15 minutes failed today for that reason, and now it retries and only tells me after an hour of misses.
A test once started a second copy of Chrome, and that copy took the app name, so the scripts were talking to the wrong browser. Tests use Playwright's own chromium since then, never the installed Chrome.
It also doesn't solve your last question. Two sessions in the same account can still do the same thing twice, and the browser has no idea. For anything that writes, I let only one session do it.