Playwright Persistent Contexts and storageState for Many Logged-In Sessions: What You End Up Building Yourself
Playwright storageState covers a handful of test logins. Past that, a Playwright persistent context, one folder per account opened with launchPersistentContext, is the right first answer. It's about fifty lines, it works on day one, and anyone who tells you to buy software before you've tried it is selling something. (Yes, we sell something. Keep reading anyway; half of this post argues against us.)
The question isn't whether that script works. It's what the team has to build around it once the accounts stop being a handful.
Start with what Playwright documents about persistent contexts
Three limits from Playwright's own docs shape everything below. As of December 2026:
- The browser type docs say "browsers do not allow launching multiple instances with the same User Data Directory." That's from the BrowserType reference. One folder, one running browser.
- The same page warns that "automating the default Chrome user profile is not supported", and that pointing
userDataDirat Chrome's mainUser Datadirectory may leave pages not loading or the browser exiting. The advice is to create a separate directory as the automation profile. - The authentication guide says "Reusing authenticated state covers cookies, local storage, IndexedDB and passkey (WebAuthn) based authentication." It adds that Playwright has no API to persist session storage, and gives a snippet to save and load it by hand.
None of that is a flaw. It's an honest description of a test library. But read it as a requirements list for the tool you're about to write.
When storageState is plenty
Say you've got five logins for a staging app. You run a setup project, save storageState to a JSON file, load it in every test. Done.
Keep doing that. It's free, it's reviewed in pull requests, and it runs anywhere Playwright runs, including Linux CI. A profile manager adds nothing here except a bill.
Persistent contexts earn their place when the login is expensive to repeat: a site that emails a code on every fresh login, or a session that took a manual step to establish. Then you want the whole browser profile on disk, not a JSON snapshot.
That's where the Playwright persistent context pattern, one folder per account, starts.
Step 1: the folder-per-account script
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
ctx = p.chromium.launch_persistent_context(
user_data_dir="profiles/acct-017",
headless=False,
)
page = ctx.pages[0] if ctx.pages else ctx.new_page()
page.goto("https://example.com/dashboard")
# ... do the work ...
ctx.close()
Log in once by hand, close, and every later run starts signed in. Honestly, it's lovely. Ten accounts, ten folders, a for loop.
Now the list of things that show up, in roughly the order they show up.
Step 2: a profile store
Folder names turn into a registry. Which account is acct-017? Who owns it? When was it last used? Is it currently running?
That last question matters because of the same-directory rule. Two jobs that both pick acct-017 collide, so you add a lock file or a database row. Then a job crashes and leaves the lock behind, so you add expiry. Then someone wants to see all of it in one place, so you add a small web page.
Congratulations, you've written a profile list with a status column. Nobody planned it, and nobody wants to maintain it.
Step 3: a proxy per profile
Playwright's network docs say "Proxy can be either set globally for the entire browser, or for each browser context individually." So per-context proxies are supported, and that's good news.
But the script now has to know which proxy belongs to which account, keep that mapping stable (an account whose exit IP changes every run makes your own audit trail a mess), and store credentials somewhere. A column in the profile store, a secrets file, a rotation policy for whoever owns the proxy contract.
Each piece is small. Together they're a data model.
Step 4: syncing folders between machines
A profile folder isn't a file. It's a directory tree full of databases the browser holds open while it runs. Copying it while the browser is alive gets you a corrupt copy. Copying it between operating systems or browser builds can get you a profile the new machine can't read.
So you write a sync job: close the browser, archive the folder, upload it, record a version, download on the other side, refuse to start if someone else holds the profile. That's a distributed lock plus an artifact store, built for a use case that started as "keep me logged in."
This is the point to stop and reconsider. The script that was fifty lines is now a service, and it has exactly one person who understands it.
Step 5: handing a session to a non-engineer
Someone in support or account management needs to open acct-017 and look at what the automation saw. They don't have Python. They shouldn't need a terminal.
You can write a launcher that checks out the profile, opens a headed window and checks it back in. Or you can hand them a zip and a sentence of instructions, which works until they open it twice.
This is also where permissions arrive. Who can view a profile? Who can launch it? Who can change its proxy? A folder on a shared drive answers none of those.
Step 6: consistent per-profile settings
Each account should present the same timezone, language, screen size and window geometry every time. Playwright lets you set locale, timezone and viewport per context, so you can store those in the profile record and pass them in.
Two honest caveats. First, you're maintaining that table yourself, and nothing stops a profile from drifting when someone edits a config. Second, there's a limit to what a context option can do compared with a browser engine that applies identity parameters natively. JustBrowser runs a custom Chromium engine with native C++ integration, with 40+ identity parameters including screen. That's a different layer from what a context option reaches. Whether you need it depends on your accounts.
Step 7: and the CDP question
If you ever switch from launching the browser yourself to attaching to one that's already running, you'll reach for connectOverCDP. Playwright's docs are frank about the tradeoff: "This connection is significantly lower fidelity than the Playwright protocol connection via" browser_type.connect(). They suggest connect() if you hit issues or need advanced functionality. See the BrowserType reference.
So attaching over CDP is a supported path, with a documented fidelity cost. Plan for that in whatever tool you pick, including ours.
What a profile manager changes
Everything in steps 2 through 6 is plumbing, and plumbing is what a profile manager is. The tradeoff is simple: you stop owning the plumbing and start paying $9.99 a month, or $99.99 a year, for one plan with unlimited profiles, unlimited cloud sync, unlimited team seats and a 7-day free trial that needs a card.
With JustBrowser specifically, here's how the pieces line up:
| What you built | What you'd use instead |
|---|---|
| Profile registry and status | The app's profile list, plus GET /profiles/{id}/status over the API |
| Proxy per profile | A proxy set on each profile (bring your own, or buy a plan in the app) |
| Folder sync | Cloud sync, with a synced profile running on one device at a time |
| Hand-off to teammates | Free team seats that run profiles shared with them |
| Launch script | POST /profiles/{id}/start, which returns a cdp_url |
The attach step looks like this. The API is local, at http://127.0.0.1:36542/api/v1 by default, and uses a Bearer token from the AI page in the app:
import requests
from playwright.sync_api import sync_playwright
API = "http://127.0.0.1:36542/api/v1"
H = {"Authorization": "Bearer YOUR_TOKEN"}
r = requests.post(f"{API}/profiles/PROFILE_ID/start",
headers=H, json={"headless": False})
cdp_url = r.json()["data"]["cdp_url"]
with sync_playwright() as p:
browser = p.chromium.connect_over_cdp(cdp_url)
ctx = browser.contexts[0]
page = ctx.pages[0] if ctx.pages else ctx.new_page()
page.goto("https://example.com/dashboard")
# browser.close() only disconnects; stop the profile explicitly
requests.post(f"{API}/profiles/PROFILE_ID/stop", headers=H)
Three details that catch people. The API starts profiles headless unless the body says {"headless": false}. Use contexts[0], never new_context(), which creates an incognito context outside the profile. And browser.close() only disconnects, so end the session with the stop call.
Where JustBrowser is the wrong choice
Said plainly, because it matters more than the pitch:
- Your jobs run in Linux CI or Docker. There's no Linux build, and the API is bound to 127.0.0.1 on a Windows or macOS machine running the desktop app. Stay with plain Playwright.
- You're authenticating a test suite.
storageStateis free and sufficient. Don't pay for what the built-in feature already does. - You want to fan one session out across workers. A synced profile runs on one device at a time. It isn't a way to share a login across parallel jobs.
- You need seats to script their own profiles. Team seats have no API access.
- You plan to run Firefox profiles with native-level identity settings. Firefox profiles run a real Firefox engine, but their identity parameters are set through JavaScript, not the native C++ integration.
If none of those describe you, the comparison is just arithmetic.
The arithmetic
Count the hours your team spends a quarter on the profile store, the proxy mapping, the sync job, the hand-off launcher and the bug where two jobs grabbed the same folder. Multiply by what an hour of an engineer costs you. Put that next to $99.99 a year.
For a handful of test logins, storageState wins and it isn't close. For dozens of long-lived accounts shared with a team, the internal tool is the expensive option, and its cost keeps growing because it never reaches "finished." Don't take our word for it; run the trial against your real list of accounts and count what you'd have deleted from your repo.
(One more thing worth building either way: monitoring. If a nightly job quietly stops logging in, you want to hear about it before a person does. Our sister product JustAnalytics has a plain explainer on how uptime checks work, and the same logic applies to your automation heartbeat.)
FAQ
Is Playwright storageState enough for logged-in sessions?
For a handful of test logins, yes. It's free, it's built in, and Playwright's auth docs say reusing authenticated state covers cookies, local storage, IndexedDB and passkey (WebAuthn) based authentication. It doesn't persist session storage on its own, so you'd add a snippet for that. The trouble starts when the files multiply, move between machines or need to reach people who don't write code.
Can two Playwright processes share one user data directory?
No. Playwright's browser type docs say browsers do not allow launching multiple instances with the same User Data Directory. One folder means one running browser at a time, so a session can't be fanned out across parallel workers. You'd need one folder per worker, and then you're managing copies.
Does JustBrowser run on Linux CI or Docker?
No. JustBrowser ships for Windows x64 and macOS on Apple Silicon only, and its REST API is bound to 127.0.0.1 on the machine running the desktop app. If your jobs run in Linux CI or Docker, stay with plain Playwright.
Can team seats use the JustBrowser API?
No. Seats are free and unlimited, but a seat can only run the profiles shared with it. The API token comes from the AI page in the app and is available on a subscription or trial, not on a seat. Anyone who needs to script their own profiles needs their own subscription.
Try JustBrowser
A multi-account browser for teams, on a custom Chromium engine, always current with upstream — not extension-based. Real C++ engine patches at the canvas / WebGL / audio / font / screen layer, so 40+ identity parameters are genuine, not faked. REST API for Playwright, Puppeteer, Selenium. One plan: $9.99/month or $99.99/year — unlimited profiles, free team seats, 7-day free trial, card required.
Get started → · How it differs from Multilogin / GoLogin / AdsPower
Try the antidetect browser built for teams
Every profile gets its own fingerprint, cookies and proxy. A 7-day trial, then $9.99/month: one plan, everything included.