On this page
A Playwright script can work fine on your test page and then get blocked on a real site before it clicks anything. The block comes from the browser itself: anti-bot scripts read its properties as soon as the page starts loading.
Below are four ways to change what they see, from a one-line library to patches you write yourself, and how each did in my benchmark.
Why Playwright gets detected
Anti-bot scripts on Cloudflare, DataDome or Akamai sites read dozens of browser properties while the page loads. Stock Playwright gives itself away on several of them:
navigator.webdriveristrue, which a normal browser never reports- the headless User-Agent contains “HeadlessChrome”
window.chromeis missing or incomplete, and so are some Chrome runtime APIs- the
pluginsarray is empty - canvas and WebGL output differ from a desktop browser with a real GPU
One of these is often enough for a block.
What you need
Python 3.10 or newer (the current Playwright needs it) and Playwright:
pip install playwright
playwright install chromium
Method 1: playwright-stealth
playwright-stealth patches JavaScript properties: it hides navigator.webdriver, adds the missing Chrome objects and fills in a few other values so the page sees something closer to a normal browser.
pip install playwright-stealth
import asyncio
from playwright.async_api import async_playwright
from playwright_stealth import stealth_async
async def main():
async with async_playwright() as playwright:
browser = await playwright.chromium.launch(headless=True)
page = await browser.new_page()
# Apply stealth BEFORE navigating
await stealth_async(page)
await page.goto('https://bot.sannysoft.com')
await page.screenshot(path='result.png')
await browser.close()
asyncio.run(main())
Call stealth_async before page.goto(). The site’s scripts run during page load, so patches added later come too late for that page.
With a browser context
If the script opens several pages, apply stealth to each new page:
import asyncio
from playwright.async_api import async_playwright
from playwright_stealth import stealth_async
async def main():
async with async_playwright() as playwright:
browser = await playwright.chromium.launch(headless=True)
context = await browser.new_context(
user_agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36'
)
page = await context.new_page()
await stealth_async(page)
await page.goto('https://bot.sannysoft.com')
await browser.close()
asyncio.run(main())
Where it stops working
The library only changes what JavaScript can read. TLS fingerprints, HTTP headers and the browser’s internals stay as they were, and Cloudflare, Akamai and PerimeterX check those too. On their sites you will usually need one of the next methods.
Method 2: Patchright
Patchright is a patched build of Playwright. It changes Chrome and the automation driver rather than injecting scripts into the page, so it also fixes leaks that playwright-stealth can’t reach.
pip install patchright
patchright install chromium
import asyncio
from patchright.async_api import async_playwright
async def main():
async with async_playwright() as playwright:
browser = await playwright.chromium.launch(
channel="chrome",
headless=True
)
context = await browser.new_context(
user_agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36'
)
page = await context.new_page()
await page.goto('https://bot.sannysoft.com')
await page.screenshot(path='result.png')
await browser.close()
asyncio.run(main())
The API is the same as Playwright’s. You change the import from playwright.async_api to patchright.async_api and leave the rest of the code alone. It also runs headless, though in my benchmark headless Patchright passed far fewer sites than headed (see below).
Method 3: Camoufox
Camoufox is a Firefox build made for automation. Besides hiding automation flags, it generates a consistent fake fingerprint: canvas, WebGL, fonts, screen size, timezone and locale.
pip install camoufox
camoufox fetch
import asyncio
from camoufox import AsyncCamoufox
async def main():
async with AsyncCamoufox(
headless=True,
geoip=True, # matches IP geolocation automatically
humanize=True, # adds human-like mouse movement
) as browser:
page = await browser.new_page()
await page.goto('https://bot.sannysoft.com')
await page.screenshot(path='result.png')
asyncio.run(main())
Because it is Firefox, a site that depends on Chrome-only APIs may behave differently. Test your target before you build on it.
Setting locale and OS
async with AsyncCamoufox(
headless=True,
geoip=True,
humanize=True,
locale='en-US',
os='windows',
) as browser:
page = await browser.new_page()
await page.goto('https://bot.sannysoft.com')
Method 4: your own patches with add_init_script
add_init_script runs your JavaScript in every page before the site’s own scripts, so you decide exactly which properties to change:
import asyncio
from playwright.async_api import async_playwright
STEALTH_SCRIPT = """
Object.defineProperty(navigator, 'webdriver', {
get: () => undefined
});
Object.defineProperty(navigator, 'plugins', {
get: () => [1, 2, 3, 4, 5]
});
Object.defineProperty(navigator, 'languages', {
get: () => ['en-US', 'en']
});
window.chrome = {
runtime: {}
};
"""
async def main():
async with async_playwright() as playwright:
browser = await playwright.chromium.launch(headless=True)
context = await browser.new_context(
user_agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36',
viewport={'width': 1920, 'height': 1080},
)
await context.add_init_script(STEALTH_SCRIPT)
page = await context.new_page()
await page.goto('https://bot.sannysoft.com')
await page.screenshot(path='result.png')
await browser.close()
asyncio.run(main())
The patches above are crude (a plugins array of numbers would not fool a careful check), and you have to keep them up to date yourself as detection changes.
Benchmark results
I ran these engines against Cloudflare, DataDome, Amazon, Akamai, PerimeterX, Kasada and other protected targets with my open-source browsers-benchmark.

Bypass rate
| Engine | Bypass Rate |
|---|---|
| patchright | 100% |
| cloakbrowser | 90% |
| camoufox_headless | 90% |
| nodriver-chrome | 80% |
| seleniumbase-cdp-chrome | 80% |
| tf-playwright-stealth-firefox | 70% |
| tf-playwright-stealth-chromium | 60% |
| playwright-chrome | 60% |
| tf-playwright-stealth-chromium_headless | 50% |
| playwright-chrome_headless | 40% |
| patchright_headless | 40% |
| camoufox (headed) | 30% |
Headed Patchright passed every protected target in this run, the only engine that did. Camoufox headless got 90% while headed Camoufox got 30%, because the headed run had proxy detection problems that pulled its score down. Stock Playwright passed 60% headed and 40% headless. tf-playwright-stealth did a little better on Firefox (70%) than on Chromium (60%). Apart from Camoufox, every engine tested in both modes scored lower headless than headed.
Memory and CPU
| Engine | Memory (MB) | CPU (%) |
|---|---|---|
| playwright-chrome_headless | 517 | 7.4 |
| tf-playwright-stealth-chromium_headless | 522 | 8.2 |
| patchright | 1,314 | 53.3 |
| camoufox_headless | 1,318 | 88.6 |
Headed Patchright and headless Camoufox each used about 1.3 GB, two and a half times as much as headless Playwright. Headless Patchright was hardly lighter at 1,277 MB. With a hundred parallel sessions that is the difference between 50 and 130 GB of RAM.
The code is at github.com/techinz/browsers-benchmark, and the full benchmark write-up has per-system results and load times.
Which one to use
| playwright-stealth | Patchright | Camoufox | Manual | |
|---|---|---|---|---|
| Setup difficulty | Easy | Easy | Easy | Hard |
| JS-level patches | Yes | Yes | Yes | Yes |
| Browser-level patches | No | Yes | Yes | No |
| Headless support | Partial | Full | Full | Partial |
| Browser engine | Chrome | Chrome | Firefox | Chrome |
| Bypass rate (headed) | 60% | 100% | 30-90%* | Varies |
| Cost | Free | Free | Free | Free |
*Camoufox headed scored low because of proxy detection issues in the benchmark. Camoufox headless reached 90%.
For a quick test or a lightly protected site, playwright-stealth is enough. If you need the highest pass rate and want to stay on Chrome, use Patchright. For sites that fingerprint heavily, try Camoufox: headless, it passed 90% here. Write your own add_init_script patches only if you need to control every property and are ready to maintain them.
Common problems
navigator.webdriver is still true after playwright-stealth. You applied it after page.goto(). Apply it before navigation.
Cloudflare or Akamai still block you. playwright-stealth doesn’t touch TLS fingerprints or browser internals. Use Patchright or Camoufox for these sites.
Camoufox crashes on Linux. Run camoufox fetch again. Some distributions need extra system packages, listed in the Camoufox GitHub repo.
Headless mode is still detected. Some sites check for real GPU rendering. Run with headless=False and, on a server, give the browser a virtual display such as Xvfb.