Playwright Stealth

2.0.3 · active · verified Sat Apr 11

Playwright Stealth is a Python package designed to make Playwright browser automation sessions less detectable by anti-bot systems. It achieves this by patching various browser fingerprints and automation-specific properties. Actively maintained, it currently stands at version 2.0.3 and utilizes a modern context-manager API for integration with Playwright.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates the recommended asynchronous usage of `playwright-stealth` with Playwright's context manager. It launches a stealthy Chromium browser, checks the `navigator.webdriver` property (which should be `False` or undefined when stealth is applied), and navigates to a sample page. Remember to install Playwright browser binaries via `playwright install chromium` first.

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

async def main():
    async with Stealth().use_async(async_playwright()) as p:
        browser = await p.chromium.launch(headless=True)
        page = await browser.new_page()
        
        # Example: Go to a test page and check navigator.webdriver property
        # An actual stealth check would involve visiting sannysoft.com or similar
        await page.goto("https://www.google.com")
        is_webdriver = await page.evaluate("navigator.webdriver")
        print(f"Is navigator.webdriver set? {is_webdriver}")

        # Navigate to another page
        await page.goto("https://web-scraping.dev/products")
        title = await page.title()
        print(f"Page title: {title}")
        
        await browser.close()

if __name__ == "__main__":
    asyncio.run(main())

view raw JSON →