Blog

How do I connect Playwright to an antidetect browser profile?

Published December 5, 2026 · Updated December 5, 2026 · Mirage Browser

Let the antidetect app start the profile, then connect Playwright to the running browser instead of launching a new one. The app keeps the profile's fingerprint, proxy and cookies; Playwright only drives pages. Use connect for Firefox and Chromium, or connectOverCDP for Chromium only. A browser your script launches itself has none of the profile's settings.

Why not just launch a browser from Playwright?

chromium.launch() starts a clean browser with Playwright’s defaults. It has no stored cookies, no proxy unless you pass one, and a fingerprint that is the same for every script on the machine. That is fine for testing your own site. It is not a separate identity: ten scripts on one computer look like one computer.

A browser profile keeps the identity: device values, proxy, time zone, cookies and storage. So the order is reversed. The app starts the profile with everything set, and the script attaches to it.

What are connect and connectOverCDP?

Playwright has two ways to attach to a running browser:

Method Engines Protocol
browserType.connect(wsEndpoint) Chromium, Firefox, WebKit Playwright’s own protocol
chromium.connectOverCDP(endpoint) Chromium only Chrome DevTools Protocol

connect gives the full Playwright feature set and works with a Firefox-based profile. connectOverCDP is lower fidelity but lets Puppeteer, Selenium and other CDP tools share the same browser.

How does it look in practice?

  1. The app starts the profile and returns an address.
  2. The script connects and takes the profile’s existing context, not a new one.
  3. When the script ends, it disconnects. The profile keeps running until you stop it.

With the Mirage SDK the first two steps are one call:

TypeScript
import { Mirage } from "@mirage-browser/sdk";

const mirage = new Mirage();
const profile = await mirage.profiles.find("Client A");
const { browser, context } = await mirage.profiles.connect(profile!.id);
const page = context.pages()[0] ?? (await context.newPage());
await page.goto("https://example.com");
await browser.close(); // disconnects, the profile stays open

Use context, not browser.newContext(). A new context is a fresh, empty session without the profile’s cookies.

Which Playwright version do I need?

The one the browser was built for. Playwright’s protocol changes between minor versions, so a client from another minor version may fail to connect or behave oddly. Mirage shows the version a profile accepts, and mirage playwright install installs it.

What should a script not change?

Anything that defines the identity: the user agent, viewport emulation, geolocation, time zone overrides or a proxy set through the protocol. Changing them from a script creates a mismatch between what the browser reports and what the network shows. Mirage refuses such commands on Chrome profiles and lets the rest of the script continue.

How do I make the input look less like a script?

Playwright clicks the exact centre of an element instantly and types at a fixed speed. A helper such as Mirage’s humanize moves the cursor along a curve, clicks a random point near the middle and varies typing pauses. It changes rhythm, not rules: a site’s terms still apply to automated use.

More on the setup: automation SDK and browser cores.

Where do these facts come from?