In This Article

Back to blog

Playwright Stealth in Python: Install, Setup, and Proxies

Tutorials

A working playwright-stealth setup in Python: installation, configuration, fingerprint testing, and proxy integration, with code for each step.

Eugenijus Denisov

Last updated - ‐ 7 min read

Key Takeaways

  • Playwright Stealth patches static fingerprints but cannot mimic human interactions.

  • Applying the patches to one browser context leaves your other contexts unpatched, so you can compare both side by side.

  • Matching your browser timezone and language to your proxy IP keeps the signals a site sees consistent.

Your Playwright web scraping script works on your laptop, then starts returning blocks or challenge screens once it runs headless on a server. Usually, bot detection mechanisms have picked up the default fingerprint of an automated browser, the server’s datacenter IP, or both.

This guide covers how to configure the Playwright Stealth plugin, verify the setup against bot detectors, build your Playwright scripts, and route traffic through a proxy whose location matches your browser environment.

What Is Playwright Stealth?

Playwright Stealth is a Python plugin for the Playwright browser automation framework that patches the properties that give away a headless browser, such as navigator.webdriver and the HeadlessChrome user agent, so they match a regular Chrome installation.

Playwright has no built-in option to patch these properties, so the community maintains playwright-stealth as a separate package on PyPI .

Its author calls it “a proof-of-concept starting point” and warns not to expect it to handle more than the simplest bot detection methods. In practice, it’s built for Chromium: its launch-flag and user agent patches only run there, and its JavaScript patches imitate Chrome.

How to Install and Use playwright-stealth

Installation

Install the Python package and its required browser binaries using two console commands:

pip install playwright-stealth
playwright install chromium

This installs version 2.0.3 (released April 4, 2026), which is MIT-licensed and needs Python 3.9 or newer.

The standard method uses a context manager to apply the Playwright Stealth plugin globally to your entire Playwright instance. Every page and browser context created from that Playwright instance inherits the same patches, which the docs' example checks with navigator.webdriver:

import asyncio
from playwright.async_api import async_playwright
from playwright_stealth import Stealth

async def main():
    # Every page created in this block gets the patches
    async with Stealth().use_async(async_playwright()) as p:
        browser = await p.chromium.launch()
        page = await browser.new_page()
        print("from new_page:", await page.evaluate("navigator.webdriver"))

        # A separately created context gets the same patches
        different_context = await browser.new_context()
        page_from_context = await different_context.new_page()
        print("from new_context:", await page_from_context.evaluate("navigator.webdriver"))

        await browser.close()

asyncio.run(main())

Applying Playwright Stealth to One Context

If you want granular control over browser automation, you can selectively apply the plugin to a single browser context and leave your other sessions untouched:

import asyncio
from playwright.async_api import async_playwright
from playwright_stealth import Stealth

async def main():
    async with async_playwright() as p:
        browser = await p.chromium.launch()
        context = await browser.new_context()

        # apply the patches to just this context
        stealth = Stealth(init_scripts_only=True)
        await stealth.apply_stealth_async(context)
        page = await context.new_page()

asyncio.run(main())

Passing the init_scripts_only=True parameter limits the module to page init scripts, which run before any of the page's own code, detection scripts included, and stops it from adding Chromium launch flags such as --disable-blink-features=AutomationControlled. Here, the context already exists, so only the init scripts run either way.

Turning Patches On and Off

To turn off a single patch, pass its flag to Stealth(), for example navigator_plugins=False. To start from zero, import the ALL_EVASIONS_DISABLED_KWARGS dictionary, unpack it into Stealth(), and switch single patches back on, which helps you isolate variables during testing.

To see what's active, inspect the script_payload property, which holds the combined JavaScript of every enabled patch. It's an empty string when all of them are off, and the docs' len() check counts characters, not patches.

Ready to get started?
Register now

Testing Whether Playwright Stealth Actually Works

You can test the patches by visiting the fingerprinting tool at bot.sannysoft.com to see the subtle traces browser automation leaves behind.

Standard headless mode Patched with Playwright Stealth
Fails navigator.webdriver check Passes navigator.webdriver check
Returns empty plugins array Reports valid Chrome plugins
Chrome characteristics missing Passes the window.chrome check

In standard headless mode, the page flags the user agent, which contains “HeadlessChrome”, along with navigator.webdriver set to true and an empty plugins array. Changing the user agent header alone fixes only the first of these.

When you apply the Playwright Stealth plugin, these tests pass and the page reports a normal Chrome installation, which shows the Python package patches the most common browser fingerprinting signals.

Scraping a Page With Playwright Stealth

A standard web scraping script navigates to a target URL, waits for specific elements to load , and extracts the data.

import asyncio
from playwright.async_api import async_playwright
from playwright_stealth import Stealth

async def extract_book_titles():
    async with Stealth().use_async(async_playwright()) as p:
        browser = await p.chromium.launch(headless=True)
        page = await browser.new_page()

        await page.goto("https://books.toscrape.com/")
        await page.wait_for_selector("article.product_pod")

        titles = await page.locator("article.product_pod h3 a").evaluate_all("links => links.map(a => a.title)")

        for title in titles[:5]:
            print(f"Extracted: {title}")

        await browser.close()

asyncio.run(extract_book_titles())

The script waits for the book grid to appear in the DOM and then uses Playwright locators to pull each link's full title attribute into a Python list before calling the await browser.close() method.

How to Use a Proxy With playwright-stealth

Many protected websites block datacenter IPs more readily than residential ones, and they read your location from your IP. With residential proxies pinned to one country, that location can match the timezone and language settings your browser reports.

Pass your proxy credentials or proxy rotation endpoint to launch() to route the whole patched browser through your new IP, or to new_context() to give a single browser context its own proxy.

import asyncio
from playwright.async_api import async_playwright
from playwright_stealth import Stealth

PROXY = {
    "server": "http://geo.iproyal.com:12321",
    "username": "your-username",
    "password": "your-password_country-gb",
}

# Match the patched navigator values to the exit country and your OS
stealth = Stealth(
    navigator_languages_override=("en-GB", "en"),
    navigator_platform_override="Win32",  # "MacIntel" on macOS, "Linux x86_64" on Linux
)

async def scrape_with_proxy():
    async with stealth.use_async(async_playwright()) as p:
        browser = await p.chromium.launch(proxy=PROXY)
        # Per-context alternative: launch() without a proxy, then new_context(proxy=PROXY, ...)
        context = await browser.new_context(
            locale="en-GB",
            timezone_id="Europe/London",
        )
        page = await context.new_page()

        # Confirm the exit country before the scraper runs
        response = await page.goto("https://ipinfo.io/json")
        ip_info = await response.json()
        if ip_info.get("country") != "GB":
            raise RuntimeError(f"Unexpected exit country: {ip_info.get('country')}")
        print(f"Exit IP {ip_info['ip']} in {ip_info['country']} ({ip_info['timezone']})")

        await page.goto("https://books.toscrape.com/")
        await page.wait_for_selector("article.product_pod")
        titles = await page.locator("article.product_pod h3 a").evaluate_all("links => links.map(a => a.title)")

        for title in titles[:5]:
            print(f"Extracted: {title}")

        await browser.close()

asyncio.run(scrape_with_proxy())

Rotating proxies can switch IPs on every request, so pin the exit country. With IPRoyal Residential Proxies, add _country-gb (or another two-letter country code) to your password. Then match your timezone_id and locale language settings to it, along with the plugin's navigator_languages_override, which defaults to US English.

Set navigator_platform_override to match the operating system in your user agent, as it defaults to Win32. Leave user_agent unset, so the plugin derives it from the real browser version and keeps it in line with the Sec-CH-UA header it adds.

Before it re-runs the books.toscrape.com scrape, the script checks the exit country at ipinfo.io and stops if it isn't GB, so your browser settings match the IP location the site sees. The plugin applies one language override to every context it patches, so use one exit country per Stealth() instance.

Conclusion

Playwright Stealth is a quick way to patch the most obvious automation signals, such as navigator.webdriver and the HeadlessChrome user agent, with one context manager. Test it against a fingerprinting page before you rely on it, keep your timezone and locale in line with your proxy, and expect advanced anti-bot systems to check signals it can't patch.

FAQ

Does Playwright have built-in fingerprint patching?

No. Playwright is a library for automating Chromium, Firefox, and WebKit, used for testing and scripting, and it doesn't patch its own fingerprint. Its automated browsers report signals such as navigator.webdriver, so you need a third-party Python package like playwright-stealth to patch the browser properties that anti-bot systems inspect.

Does playwright-stealth work with Firefox or WebKit?

Not in a useful way. Its JavaScript patches load in any browser, but they imitate Chrome, for example by setting navigator.vendor to “Google Inc.”, and the launch-flag and user agent patches only run on Chromium. On Firefox or WebKit, that leaves a mixed fingerprint, so launch the Chromium engine in your Playwright scripts.

Does playwright-stealth still work in 2026?

Yes, for basic checks. Version 2.0.3 came out in April 2026 and still patches signals such as navigator.webdriver. It can't change your TLS fingerprint, behavioral signals, or the reputation of your IP addresses, though, and a modern anti-bot system can also spot patched browser objects at runtime.

Does Playwright Stealth work with Cloudflare or DataDome?

Usually not. These advanced anti-bot systems use JavaScript challenges, TLS fingerprinting, and behavioral analysis of user interactions, and the plugin's property overrides don't change any of those. On pages these vendors protect, expect challenges and CAPTCHAs even with every patch turned on.

Do you still need proxies with Playwright Stealth?

For scraping protected sites at any volume, usually yes. Anti-bot systems score your IP reputation from the first request, before any of your browser's JavaScript runs, so a patched fingerprint can't make up for an IP with a poor history. Requests from known datacenter and cloud provider ranges also get challenged more often.

Create Account
Share on
Article by IPRoyal
Meet our writers
Data News in Your Inbox

No spam whatsoever, just pure data gathering news, trending topics and useful links. Unsubscribe anytime.

No spam. Unsubscribe anytime.

Related articles