AI agents and automation
Why your Playwright bot is detected
Playwright drives real browser engines, yet sites still flag it within seconds. This article lists the tells a stock launch carries, explains how they are read, and gives practical mitigations for permitted automation.
The quick answer
A default Playwright session differs from a person's browser in four places: the browser binary it ships, the flags and headless mode it launches with, the way it creates fresh contexts, and the way your script moves through pages. Each difference is small. Bot detection adds them up. Most of the fixes are configuration, not hacks, and they matter most for the sites that also show a CAPTCHA, where a cleaner session means fewer solves.
Tells in the launch
The bundled Chromium build
Playwright downloads its own Chromium build by default. It is close to Chrome but not identical: some codecs, branding strings and client hint brand lists differ from the stable Chrome that most visitors run. Launching with channel: 'chrome' (or 'msedge') uses the installed branded browser instead, which removes that class of differences. Check the Playwright docs for which channels your platform supports.
Headless mode
Older headless Chromium put HeadlessChrome in the User-Agent and lacked several features of the full browser. Chrome's newer headless mode runs the real browser without a window and is much closer to headed behavior. Playwright has changed which headless implementation it uses across releases, so print navigator.userAgent from inside your session to confirm what you actually run rather than assuming.
The webdriver flag
Under automation, navigator.webdriver is usually true. You will see advice to delete it with an init script. Removing it can hide one signal, but a careless override (a property that is defined on the wrong prototype, or a getter that looks patched) becomes a signal of its own. If you change it, verify the result looks like a normal browser's, where the property exists on the navigator prototype and reads false. The headless browser detection entry shows how scripts test for these overrides.
Tells in the context
Every browser.newContext() starts empty: no cookies, no history, no local storage, a default viewport of 1280 by 720, the locale of the machine, and the machine's timezone. On a cloud server that means UTC and English, whatever the IP. A real visitor from Germany on a German residential line does not look like that.
- Set
localeandtimezoneIdin the context options to match the IP you send traffic from. - Pick a viewport from common laptop sizes rather than the default.
- Persist the context with
storageStateor a persistent context directory, so returning visits carry cookies. - Avoid overriding the User-Agent with a string from another browser or OS; let the engine report its own, or keep any change consistent with the platform.
import { chromium as engine } from 'playwright';
const shopBrowser = await engine.launch({ channel: 'chrome', headless: true });
const shopContext = await shopBrowser.newContext({
locale: 'de-DE',
timezoneId: 'Europe/Berlin',
viewport: { width: 1440, height: 900 },
storageState: 'state/de-shop.json', // created by an earlier run
});
const tab = await shopContext.newPage();
console.log(await tab.evaluate(() => [navigator.webdriver, navigator.userAgent]));
The last line is the most useful habit in this article: log what the page sees, from inside the page, on every new setup.
Tells in your script's behavior
Playwright actions are fast and exact. page.fill() sets a whole value at once; page.click() lands in the center of the element with no prior mouse movement; navigation goes straight to deep URLs. Behavioral scoring compares this with how people use pages.
- Use
locator.pressSequentially()with a small delay for fields that sites watch, such as login and search inputs. - Reach pages through links where practical instead of loading every deep URL directly.
- Wait between page loads. A few seconds of pause rarely hurts a monitoring job and often removes challenges.
- Block heavy media if you like, but do not block the site's own scripts, since a missing analytics or challenge script is itself unusual.
Tells in the network
Cloud IPs carry poor reputation for many sites, and a large number of contexts from one address in a short time looks like a crawler. Spread work over time, keep sessions sticky to one address for their lifetime, and match geo settings to that address. The IP reputation page explains how sites score addresses.
What stealth tweaks cannot fix
Many sites challenge certain actions for everyone: a login, a sign up, a checkout, a search over a rate limit. No configuration avoids those, because the check is not a guess about you; it is policy. For these, a CAPTCHA solving API fits naturally into Playwright: read the site key from the page, create a task, place the token, submit. Our guide to reCAPTCHA v3 in Node.js shows the pattern with Playwright, and the Playwright integration page collects the snippets per type.
Cleaner sessions and solving work together. The configuration above reduces how many challenges appear; the solver deals with the rest at a fixed rate per 1,000, for example $0.56 for a reCAPTCHA v2 checkbox. Failed tasks are free.
A short diagnostic routine
- Run the same flow headed on your desktop browser, by hand. If you are challenged there too, the site challenges everyone at that step.
- Run the Playwright script headed on the same desktop. If challenges appear only now, the cause is in the launch or behavior.
- Run it headless on the desktop, then on the server. Each step changes one variable: headless mode, then hardware and network.
- Log the in page values at each stage and compare.
This takes about fifteen minutes and usually points at one or two changes worth making, instead of a pile of patches applied blindly.
Keep it legitimate
These mitigations exist to make QA suites, monitoring of public pages and internal RPA run reliably. They are not meant for mass account creation or for getting around a site that has blocked you on purpose. If a site offers an API for the data you need, it is almost always the better route.
Tracing what the site saw
Playwright's trace viewer is useful here beyond debugging selectors. Record a trace with context.tracing.start({ screenshots: true, snapshots: true }) on a run that ends in a challenge, then open it and look at the network tab for the moment the check appeared. You will often see the exact request that was answered with a challenge, its status code and the headers that went out with it. That turns "the site detected us" into "the third search request in eight seconds was answered with a 403", which is something you can change.
Compare the trace with a run that passed. If the passing run took longer between steps, or carried a cookie the failing one lacked, you have found your lever without touching any fingerprint at all.
Test runners versus long running bots
Playwright Test creates a fresh context for each test by design, which is right for isolation and wrong for looking like a returning visitor. For end to end tests against your own staging site, ask your team to allow test traffic by IP or header instead of fighting the bot rules. For monitoring jobs against public sites, step outside the test runner and keep a persistent context per job.
Common questions
Does channel chrome make Playwright undetectable?
No. It removes differences between bundled Chromium and branded Chrome, which helps, but behavior, network and context still matter.
Is headed mode always better than headless?
Headed removes some headless differences, but the newer headless Chrome is close. Measure both on your target instead of assuming.
Should I delete navigator.webdriver with an init script?
Only if you verify the result looks normal. A clumsy override is easier to detect than the original flag.
Why am I challenged only on the server, not my laptop?
The server usually differs in IP reputation, GPU, fonts and timezone. Compare in page values from both to find the gap.
Can Playwright and a CAPTCHA API run in the same script?
Yes. Playwright reads the page and places the token; the API call is a plain HTTP request made from the same script.
Keep reading
- PlaywrightPlaywright in Node.js and Python: read widget keys from the DOM or network, inject tokens, and add answers through route interception.
- Headless browser detectionThe traces a browser without a window tends to leave: automation flags, missing plugins and telltale user agent tokens.
- Puppeteer detected as a bot: what to checkA checklist for Puppeteer scripts that get flagged: the webdriver flag, headless markers, launch arguments and the request patterns sites notice.
- What is stealth mode in browser automation?Stealth mode patches tells that give away an automated browser, like the webdriver flag and headless quirks, but not everything.