---
title: "Playwright Browser Profile Automation: Persist Logins"
description: "For playwright browser profile automation, use a persistent context with one user data directory per profile. Learn what it keeps and what it leaves shared."
url: "https://donutbrowser.com/ja/playwright-browser-profile-automation/"
---

1. [ホーム](https://donutbrowser.com/ja/)

2. [ブログ](https://donutbrowser.com/ja/blog)

3. Playwright Browser Profile Automation: Persist Logins

# Playwright Browser Profile Automation: Persist Logins

November 30, 2026

playwright browser profiles persistent context

**For playwright browser profile automation, use a persistent context with [its own user data directory](https://github.com/BrowserOpsLab/playwright-browser-profile-manager) per profile: it keeps cookies, localStorage, cache and service workers between runs, while `new_context()` starts empty and `storageState` replays a saved login. Set proxy, `timezoneId`, `locale` and `geolocation` together. A profile doesn’t isolate your IP, hardware-derived signals, WebRTC or [the automation stack’s TLS signature](https://blog.send.win/playwright-multiple-browser-profiles-automation-browser-isolation-guide-2026/).**

Your Playwright script logs in fine, then the next run starts clean and you log in again. Or two scripts share one login and overwrite each other’s session. Both problems come from how Playwright keeps state, and Playwright browser profile automation fixes both.

After reading, you can pick a state method, keep each profile’s proxy and locale consistent, attach over CDP, and run many profiles without corrupting them.

> **Key Takeaways**

> - Never open one user data directory in two browsers at once; give each profile its own folder.

> - Attaching over CDP means launching the browser yourself with a separate profile folder and accepting lower fidelity.

> - Treat a profile folder with live sessions like a password: keep it out of git and off sync tools.

> - For most QA work, plain Playwright contexts are enough. Use profiles or CDP only when state must persist across runs.

## How does Playwright browser profile automation keep logins between runs?

You keep a Playwright browser profile between runs by saving state to a file with `storageState` or by launching a persistent context on a user data directory.

|  | Fresh `new_context()` | `storageState` | Persistent context |
| --- | --- | --- | --- |
| Cookies | Empty | Saved and restored | Kept |
| localStorage | Empty | Saved and restored | Kept |
| Cache | Empty |  | Kept |
| Service workers | Empty |  | Kept |
| Parallel use |  |  | One process per directory |

A fresh `new_context()` starts empty on every run, which suits tests that must not depend on earlier state.

A persistent context keeps a whole profile folder. The [profile-manager README](https://github.com/BrowserOpsLab/playwright-browser-profile-manager) says that with a separate user-data directory per profile, “Cookies, local storage, cache, service workers, and authenticated test state stay with that profile”.

The [Playwright API reference](https://playwright.dev/docs/api/class-browsertype) notes that browsers do not allow launching multiple instances with the same user data directory, so give each profile its own folder and run one process per folder. Never point it at your everyday browser profile.

```
from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    ctx = p.chromium.launch_persistent_context("./profiles/shop-us", headless=False)
    page = ctx.new_page()
    page.goto("https://example.com")
    ctx.close()  # cookies and cache stay in ./profiles/shop-us

    # The file-based alternative:
    # browser = p.chromium.launch()
    # context = browser.new_context(storage_state="state.json")
```

In Node.js the equivalent is `launchPersistentContext(userDataDir, options)` on `chromium`.

Agents face the same choice, and the comparison section below covers the Playwright MCP modes.

Choose your Playwright browser profile automation method by what the run needs:

- Fresh `new_context()`: independent tests that must start clean.

- `storageState`: logging in once, then reusing that session in later runs or CI.

- Persistent context: one long-lived identity per folder, where cache and service workers should survive a restart.

## What does Playwright browser profile automation not isolate?

A Playwright browser profile leaves four things shared between profiles on one machine: the IP address, hardware-derived signals such as canvas, WebGL and audio, WebRTC, and the TLS and HTTP/2 signature of the browser build. Those come from your network, hardware and browser build, so they need separate handling.

The [profile-manager README](https://github.com/BrowserOpsLab/playwright-browser-profile-manager) describes the same boundary: it “does not spoof browser fingerprints or bypass site security controls.”

- **IP address.** Every context uses your machine’s connection unless you pass a `proxy` option, and then it uses only the proxy you supplied.

- **Hardware-derived signals.** Canvas, WebGL and audio output depend on your GPU, drivers and operating system, so every context on one machine returns the same values. Our [guide to browser fingerprinting](https://donutbrowser.com/browser-fingerprinting/) covers how sites read them.

- **WebRTC.** The browser can reveal network addresses through its own connections, separate from page requests, so a proxy setting alone doesn’t settle it.

- **TLS and HTTP/2 signature.** The handshake and connection settings your browser build sends are the same for every context that build opens.

[Playwright’s emulation docs](https://playwright.dev/docs/emulation) show how far script-level control goes: a context can set `timezoneId`, `locale`, `geolocation` and `proxy`. These values change what the page is told; your hardware and network still send their own signals.

Fingerprint values can be changed in two places. A script-level tool injects JavaScript that overrides values after the page starts. An engine-level tool changes them inside the browser itself.

The [Wayfern docs](https://donutbrowser.com/docs/wayfern/) say Wayfern sets fingerprint values at the C++ level of the engine, so a Playwright script attached to it doesn’t need patch scripts of its own.

No browser guarantees that accounts never get banned. Platforms also judge behavior and apply their own rules.

You can test any setup yourself with free checkers such as BrowserLeaks, CreepJS and Pixelscan.

## How do you keep proxy, timezone, locale and geolocation consistent?

You keep proxy, timezone, locale and geolocation consistent by choosing one city per profile and setting all four values in the same launch call, so they all describe that city.

The contradiction to avoid looks like this: a profile exits through a New York proxy, but its context sets `timezone_id="Asia/Ho_Chi_Minh"`. The site sees a New York IP and a browser clock in Vietnam. The corrected values are `America/New_York`, `en-US` and New York coordinates (latitude 40.7128, longitude -74.0060).

1. **Pick the target city first.** Every other value comes from it. Write “New York” in the profile’s config before you touch a setting.

2. **Assign one dedicated proxy to the profile.** Two profiles on one proxy share an IP, which links them. Confirm the proxy’s exit city before you launch.

3. **Set `timezone_id` to a named IANA zone.** Matching only the UTC offset is not enough, because the browser exposes a named zone. A Berlin proxy with `Europe/Prague` is still a mismatch.

4. **Set `locale` to the region’s language.** For New York that’s `en-US`.

5. **Set `geolocation` and grant the permission.** Pass `permissions=["geolocation"]` with the coordinates, or pages can’t read them.

6. **Keep all four values in one per-profile config.** Scattering them across scripts is how a Vietnam timezone ends up beside a New York proxy.

7. **Check the result.** Open a page that prints your IP, timezone, language and coordinates. Success is all four pointing at New York. If the IP shows another city, fix the proxy, not the script.

A persistent context takes all four values in one call:

```
from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    context = p.chromium.launch_persistent_context(
        "profiles/ny-01",
        proxy={"server": "http://proxy.example:8080",
               "username": "user", "password": "pass"},
        locale="en-US",
        timezone_id="America/New_York",
        geolocation={"latitude": 40.7128, "longitude": -74.0060},
        permissions=["geolocation"],
    )
    page = context.new_page()
    page.goto("https://example.com")
```

The IP comes from the proxy you bring, and Playwright only routes traffic through it. Our guide to [proxies for anti-detect browsers](https://donutbrowser.com/proxies-for-anti-detect-browsers/) compares residential, ISP and datacenter options.

Repeat the steps for each profile, each with its own city, its own proxy and its own `user_data_dir`.

## How do you attach Playwright to a profile another browser launched?

You attach Playwright to a profile another browser launched by starting that browser yourself with a debugging port and its own profile folder, then connecting over the Chrome DevTools Protocol (CDP).

1. **Check your runtime.** [Playwright’s system requirements page](https://playwright.dev/docs/intro) lists “Node.js 20.x, 22.x or 24.x”, so Node.js 20 is the minimum for the Node.js snippet. Python needs the `playwright` package installed.

2. **Start the browser with a port and a separate directory.** [Chrome’s developer blog](https://developer.chrome.com/blog/remote-debugging-port) says that from Chrome 136, `--remote-debugging-port` is no longer respected when it points at Chrome’s standard data directory. Pass a new `--user-data-dir`, and keep one folder per profile:

```
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" \
  --remote-debugging-port=9222 \
  --user-data-dir=/tmp/profile-a
```

1. **Confirm the port answers.** Open `http://127.0.0.1:9222/json/version`. A JSON reply means the browser is listening. A blank page or refused connection usually means the default directory was used, or another instance already holds the port.

2. **Connect from Python.**

```
from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.connect_over_cdp("http://127.0.0.1:9222")
    context = browser.contexts[0]
    page = context.pages[0] if context.pages else context.new_page()
    page.goto("https://example.com")
```

1. **Or connect from Node.js.**

```
const { chromium } = require('playwright');

(async () => {
  const browser = await chromium.connectOverCDP('http://127.0.0.1:9222');
  const context = browser.contexts()[0];
  const page = context.pages()[0] ?? await context.newPage();
  await page.goto('https://example.com');
})();
```

When it works, the page loads in the window you already had open, with that profile’s cookies. Close the script and the browser stays running.

### What you lose compared with Playwright’s own launch

The [Playwright docs for `BrowserType.connectOverCDP`](https://playwright.dev/docs/api/class-browsertype) say the connection “is significantly lower fidelity than the Playwright protocol connection via browserType.connect()”. If advanced features misbehave, suspect the CDP connection first.

Launch options also move to the browser side. `args`, a proxy at launch and the executable path no longer pass through Playwright, so put them on the command line, for example `--proxy-server`.

Agents can attach the same way: [Playwright MCP](https://github.com/microsoft/playwright-mcp) accepts `--cdp-endpoint` to attach to a running browser. For driving managed profiles over CDP, see our [automation use case](https://donutbrowser.com/use-cases/automation).

## How do you run Playwright browser profile automation safely at scale?

You run many Playwright browser profiles safely by giving each profile its own folder, letting only one browser process use that folder at a time, and handling the folders like passwords. These rules fit legitimate work such as client accounts, regional checks, testing and research.

1. **One directory per profile.** The [Playwright Browser Profile Manager README](https://github.com/BrowserOpsLab/playwright-browser-profile-manager) says “Each profile owns a separate user-data directory.” Name folders after the client or region, for example `profiles/acme-us`, so nothing is shared by accident.

2. **One browser process per directory.** Run jobs for a profile in a queue and close its context before the next job starts, so each folder has a single owner.

3. **Config next to the folder.** Store a small `profile.json` beside each directory with the proxy, `locale`, `timezoneId` and `geolocation`. Load it in the same launch call that opens the folder, so the folder and its settings can’t drift apart.

4. **Folders are credentials.** Whoever holds a copy of a folder with live sessions can act as the logged-in user until the sessions expire. Keep folders out of git, limit file permissions and use an encrypted disk.

5. **No raw folder syncing.** Don’t sync user data directories between machines with a file-sync tool. A live browser writes to the folder constantly, and a sync moves every session at once. Export cookies for one profile and import them on the other machine instead.

6. **Ephemeral for throwaway work.** For one-off checks, use a fresh context or a temporary directory that you delete afterward. A folder that doesn’t exist can’t leak.

7. **Local, quiet tooling.** Choose tools that keep profile data on your machine and don’t phone home. [Donut Browser](https://donutbrowser.com), the open-source browser we make, has zero telemetry. Whichever tool you use, look for password-locked profiles, ephemeral profiles and per-profile cookie export.

## Plain Playwright, profile folder or anti-detect browser: which do you need?

The right choice depends on what sites must see: separate sessions need only Playwright, while separate devices need an anti-detect browser.

| Option | Keeps | Does not isolate | Effort | Cost |
| --- | --- | --- | --- | --- |
| Plain Playwright context | Nothing after it closes | IP, hardware signals, WebRTC, TLS | Lowest | Free |
| Persistent context with a profile folder | Cookies, localStorage, cache, service workers | IP, hardware signals, WebRTC, TLS | One folder per login | Free |
| Profile-manager script | Same, per named profile | Same, no fingerprint spoofing | Install and learn a script | Free |
| Anti-detect browser over CDP | Cookies, proxy and fingerprint per profile | Behavior; lower fidelity than Playwright’s own launch | Run the browser, then attach | Pro plan to launch with a CDP port |
| Agent through MCP | Depends on the mode | Depends on the mode | One config entry | Playwright MCP free; Donut remote MCP is paid |

For QA, a fresh `new_context()` per test gives clean state, and a persistent context covers suites that need a stored login.

An [anti-detect browser](https://donutbrowser.com/what-is-an-anti-detect-browser/) is worth the extra step when sites must see separate devices, not just separate cookies.

For agents, the [Playwright MCP docs](https://playwright.dev/docs/getting-started-mcp) list `--user-data-dir`, `--isolated`, `--storage-state`, `--cdp-endpoint` and `--extension`. `--isolated` keeps the profile in memory, and `--extension` connects to a browser you already run.

Donut’s remote MCP is one alternative. [Its pricing page](https://donutbrowser.com/pricing) lists Pro at $99 per month with remote MCP, browser control and recipes, while Solo has remote MCP without the browser automation tools.

- Plain context: tests that should start clean.

- Profile folder: one login that must survive runs.

- Profile-manager script: several named profiles on one machine.

- Anti-detect browser over CDP: separate fingerprints and proxies per identity.

- MCP: agents doing the work; pick the mode by whether state should persist.

## Where Donut Browser fits

Donut Browser is a profile manager that can sit next to Playwright, and it accepts Playwright connections only on the Pro plan. I make it, so the limits come first.

Each Donut Browser profile has its own fingerprint, cookies, local storage, cache and proxy, and none needs an account.

For Playwright, the [local REST API](https://donutbrowser.com/docs/rest-api) listens on `127.0.0.1:10108` and uses a bearer token. It can launch a profile with a `remote_debugging_port`, so Playwright, Puppeteer or Selenium can attach over CDP.

The [pricing page](https://donutbrowser.com/pricing/) lists the Browser Manipulation API under Pro, at $99 per month.

On top of Playwright, the MIT-licensed `wayfern` npm package humanizes mouse movement, typing and scroll, as described in the [Wayfern docs](https://donutbrowser.com/docs/wayfern/).

Donut Browser sells no proxies, so you bring your own. It also can’t prevent bans, because platforms still judge behavior.

To try the attach flow, start with the [Pro plan page](https://donutbrowser.com/pro/) and the Wayfern docs.

## Frequently asked questions

### What is a Playwright browser profile?

**A Playwright browser profile is [a user data directory](https://github.com/BrowserOpsLab/playwright-browser-profile-manager) that a persistent context opens, so cookies, local storage, cache and service workers survive between runs.** A context from `new_context()` starts clean and temporary unless you save and reload `storageState`.

### Can I use my everyday Chrome profile with Playwright?

**Use a dedicated profile folder for each script instead of your daily one.** Your daily profile holds saved passwords and every open session, so one script mistake can touch all of them. Copy only what you need.

### Is storageState enough to stay logged in?

**It works for sites that keep your login in cookies and localStorage.** If a site relies on cache or service workers, use a persistent context, which keeps both with the profile.

### Does a Playwright context hide my IP or fingerprint?

**A context hides neither.** The [profile-folder approach](https://github.com/BrowserOpsLab/playwright-browser-profile-manager) doesn’t spoof fingerprints, so set your proxy, `timezoneId`, `locale` and `geolocation` yourself.

### Can Playwright control a browser I launched myself?

**Playwright can attach with `connectOverCDP` to a browser you started with a debugging port and its own profile folder.** Expect less fidelity than with Playwright’s own launch.

## Next steps for Playwright browser profile automation

**Today:** Move one script to a persistent context with its own user data directory. Load that profile’s proxy and locale settings from a `profile.json` beside the folder.

**This week:** Run the profile through a fingerprint test and a WebRTC test, such as BrowserLeaks or CreepJS. If the results match the city you set, plain Playwright is enough for your playwright browser profile automation.

**Later:** If you need fingerprint values set inside the engine, try an anti-detect browser over CDP, as in our [automation use case](https://donutbrowser.com/use-cases/automation/).

[Download Donut Browser](https://donutbrowser.com) and read the REST API docs for that endpoint before you decide.

## Sources

[Playwright Browser Profile Manager - GitHub](https://github.com/BrowserOpsLab/playwright-browser-profile-manager) · [Playwright Multiple Browser Profiles Automation: Browser…](https://blog.send.win/playwright-multiple-browser-profiles-automation-browser-isolation-guide-2026/) · [BrowserType | Playwright](https://playwright.dev/docs/api/class-browsertype) · [Emulation | Playwright](https://playwright.dev/docs/emulation) · [Wayfern · Playwright · Docs — Donut Browser](https://donutbrowser.com/docs/wayfern/) · [Playwright MCP | Playwright](https://playwright.dev/docs/getting-started-mcp) · [Donut Browser pricing](https://donutbrowser.com/pricing) · [REST API · Docs — Donut Browser](https://donutbrowser.com/docs/rest-api). Every other source is linked where the article cites it.

## Google で当サイトをもっと見る

ワンクリックで Donut Browser を Google アカウントの優先ソースに設定すると、トップニュース、AI モード、AI による概要で当サイトの記事が表示されやすくなります。

Google で優先ソースに設定

## On this page

- How does Playwright browser profile automation keep logins between runs?

- What does Playwright browser profile automation not isolate?

- How do you keep proxy, timezone, locale and geolocation consistent?

- How do you attach Playwright to a profile another browser launched?

- What you lose compared with Playwright’s own launch

- How do you run Playwright browser profile automation safely at scale?

- Plain Playwright, profile folder or anti-detect browser: which do you need?

- Where Donut Browser fits

- Frequently asked questions

- What is a Playwright browser profile?

- Can I use my everyday Chrome profile with Playwright?

- Is storageState enough to stay logged in?

- Does a Playwright context hide my IP or fingerprint?

- Can Playwright control a browser I launched myself?

- Next steps for Playwright browser profile automation

- Sources
