tf-playwright-stealth
tf-playwright-stealth is a Python package designed to make Playwright instances stealthy by spoofing browser features, thereby reducing the chance of detection by anti-bot systems. The current version is 1.2.0, and it has seen multiple releases since its first publication in March 2024, indicating active maintenance.
Warnings
- gotcha There are two similarly named, but distinct, Python packages: `tf-playwright-stealth` (this library) and `playwright-stealth`. They have different APIs. `tf-playwright-stealth` provides `stealth_sync` and `stealth_async` functions, while `playwright-stealth` offers a `Stealth` class. Attempting to import `Stealth` from `playwright_stealth` when `tf-playwright-stealth` is installed will result in an `ImportError`. Ensure you use the correct imports for the installed package.
- gotcha Stealth plugins like `tf-playwright-stealth` primarily address browser fingerprinting (e.g., `navigator.webdriver`, plugins, user-agent consistency). They do not inherently prevent detection based on IP reputation, TLS fingerprinting (JA3/JA4), behavioral analysis, or advanced JavaScript challenges employed by sophisticated anti-bot systems (like Cloudflare Turnstile, DataDome, Kasada).
- gotcha Older versions (prior to 1.x, or specific bugfix releases) of `playwright_stealth` (the internal module name) may have suffered from a missing `__init__.py` file, leading to `ImportError` issues. While likely resolved in current versions, users experiencing import problems should verify the package structure or update to the latest release.
Install
-
pip install tf-playwright-stealth
Imports
- stealth_sync
from playwright_stealth import stealth_sync
- stealth_async
from playwright_stealth import stealth_async
- Stealth
Quickstart
from playwright.sync_api import sync_playwright
from playwright_stealth import stealth_sync
with sync_playwright() as p:
browser = p.chromium.launch(headless=True)
page = browser.new_page()
stealth_sync(page)
page.goto("https://bot.sannysoft.com/")
print(f"Page title: {page.title()}")
page.screenshot(path="example_with_stealth.png", full_page=True)
browser.close()