### Install playwright-stealth Source: https://github.com/mattwmaster58/playwright_stealth/blob/main/README.md Command to install the library via pip. ```bash pip install playwright-stealth ``` -------------------------------- ### Manually Apply Playwright Stealth (Async) Source: https://context7.com/mattwmaster58/playwright_stealth/llms.txt This example illustrates manual application of stealth features in an asynchronous Playwright script using apply_stealth_async(). This method provides more granular control over when stealth is applied. ```python from playwright_stealth import apply_stealth_async from playwright import async_playwright async with async_playwright() as p: browser = await p.chromium.launch() page = await browser.new_page() await apply_stealth_async(page) await page.goto("https://example.com") # ... rest of your automation code ``` -------------------------------- ### Configure Stealth Evasion Options Source: https://context7.com/mattwmaster58/playwright_stealth/llms.txt Demonstrates how to initialize the Stealth class with specific evasion settings for Chrome, navigator properties, and other browser fingerprinting vectors. ```python stealth = Stealth( chrome_app=True, navigator_webdriver=True, navigator_languages_override=("en-US", "en"), navigator_platform_override="Win32", webgl_renderer_override="Intel Iris OpenGL Engine", webgl_vendor_override="Intel Inc." ) ``` -------------------------------- ### Configure Custom Stealth Overrides Source: https://context7.com/mattwmaster58/playwright_stealth/llms.txt Demonstrates how to initialize the Stealth class with specific overrides for navigator languages, platform, user agent, and WebGL properties. This allows for precise control over browser fingerprinting attributes. ```python import asyncio from playwright.async_api import async_playwright from playwright_stealth import Stealth async def main(): stealth = Stealth( navigator_languages_override=("fr-FR", "fr"), navigator_platform_override="MacIntel", navigator_user_agent_override="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36", webgl_vendor_override="Apple Inc.", webgl_renderer_override="Apple GPU", navigator_vendor_override="Apple Computer, Inc.", script_logging=True, init_scripts_only=True, ) async with stealth.use_async(async_playwright()) as p: browser = await p.chromium.launch() page = await browser.new_page() await page.goto("https://bot.sannysoft.com/") languages = await page.evaluate("navigator.languages") platform = await page.evaluate("navigator.platform") vendor = await page.evaluate("navigator.vendor") print(f"Languages: {languages}") print(f"Platform: {platform}") print(f"Vendor: {vendor}") await browser.close() asyncio.run(main()) ``` -------------------------------- ### Apply stealth using asynchronous context manager Source: https://context7.com/mattwmaster58/playwright_stealth/llms.txt Demonstrates the recommended asynchronous usage where stealth is automatically applied to all pages created within the context. ```python import asyncio 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() page = await browser.new_page() await page.goto("https://bot.sannysoft.com/") webdriver_status = await page.evaluate("navigator.webdriver") print(f"navigator.webdriver: {webdriver_status}") await browser.close() asyncio.run(main()) ``` -------------------------------- ### Build and Publish with Poetry Source: https://github.com/mattwmaster58/playwright_stealth/blob/main/CONTRIBUTING.md Maintainers use Poetry to build the project package and publish it to a repository. ```bash poetry build ``` ```bash poetry publish ``` -------------------------------- ### Apply stealth using synchronous context manager Source: https://context7.com/mattwmaster58/playwright_stealth/llms.txt Demonstrates the synchronous usage pattern for applying stealth automatically to all pages within a sync Playwright session. ```python from playwright.sync_api import sync_playwright from playwright_stealth import Stealth def main(): with Stealth().use_sync(sync_playwright()) as p: browser = p.chromium.launch() page = browser.new_page() page.goto("https://bot.sannysoft.com/") webdriver = page.evaluate("navigator.webdriver") print(f"webdriver: {webdriver}") browser.close() main() ``` -------------------------------- ### Run Local CI with act Source: https://github.com/mattwmaster58/playwright_stealth/blob/main/CONTRIBUTING.md Maintainers can run the CI process locally using the 'act' command before tagging a release. ```bash act ``` -------------------------------- ### Configure Advanced Stealth Evasions Source: https://github.com/mattwmaster58/playwright_stealth/blob/main/README.md Shows how to apply custom configuration options and manually manage evasions for specific browser contexts. ```python import asyncio from playwright.async_api import async_playwright from playwright_stealth import Stealth, ALL_EVASIONS_DISABLED_KWARGS async def advanced_example(): custom_languages = ("fr-FR", "fr") stealth = Stealth(navigator_languages_override=custom_languages, init_scripts_only=True) async with async_playwright() as p: browser = await p.chromium.launch() context = await browser.new_context() await stealth.apply_stealth_async(context) page = await context.new_page() is_mocked = await page.evaluate("navigator.languages") == custom_languages print(f"Stealth applied: {is_mocked}") asyncio.run(advanced_example()) ``` -------------------------------- ### Verify Stealth Effectiveness Source: https://context7.com/mattwmaster58/playwright_stealth/llms.txt Provides an asynchronous script to launch a headless browser with stealth enabled and verify common bot detection indicators against a test site. ```python 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://bot.sannysoft.com/") webdriver_hidden = await page.evaluate("navigator.webdriver") print(f"webdriver hidden: {webdriver_hidden is False}") ``` -------------------------------- ### Apply Stealth to Playwright Contexts Source: https://github.com/mattwmaster58/playwright_stealth/blob/main/README.md Demonstrates the recommended usage of the library to apply stealth to all pages created within a Playwright session. ```python import asyncio 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() page = await browser.new_page() webdriver_status = await page.evaluate("navigator.webdriver") print("from new_page: ", webdriver_status) asyncio.run(main()) ``` -------------------------------- ### Manually apply stealth to a browser context Source: https://context7.com/mattwmaster58/playwright_stealth/llms.txt Shows how to selectively apply stealth to a specific browser context using manual function calls for granular control. ```python import asyncio from playwright.async_api import async_playwright from playwright_stealth import Stealth async def main(): stealth = Stealth() async with async_playwright() as p: browser = await p.chromium.launch() context = await browser.new_context() await stealth.apply_stealth_async(context) page1 = await context.new_page() await page1.goto("https://bot.sannysoft.com/") status = await page1.evaluate("navigator.webdriver") print(f"Page 1 webdriver: {status}") await browser.close() asyncio.run(main()) ``` -------------------------------- ### Manually Apply Playwright Stealth (Sync) Source: https://context7.com/mattwmaster58/playwright_stealth/llms.txt This snippet demonstrates the manual application of stealth features in a synchronous Playwright script using apply_stealth_sync(). This approach is useful when you need to apply stealth at a specific point in your script. ```python from playwright_stealth import apply_stealth_sync from playwright import sync_playwright with sync_playwright() as p: browser = p.chromium.launch() page = browser.new_page() apply_stealth_sync(page) page.goto("https://example.com") # ... rest of your automation code ``` -------------------------------- ### Stealth Context Manager (Async) Source: https://context7.com/mattwmaster58/playwright_stealth/llms.txt Applies stealth evasion techniques automatically to all pages and contexts created within an asynchronous Playwright session. ```APIDOC ## Stealth().use_async(playwright_instance) ### Description Initializes an asynchronous context manager that automatically injects stealth evasion scripts into every page and browser context created. ### Method ASYNC CONTEXT MANAGER ### Parameters #### Request Body - **playwright_instance** (Object) - Required - The instance returned by async_playwright() ### Request Example async with Stealth().use_async(async_playwright()) as p: browser = await p.chromium.launch() ### Response #### Success Response (200) - **Context** (Object) - Returns a managed Playwright instance with stealth enabled. ``` -------------------------------- ### Integrate Playwright Stealth with Sync Context Manager Source: https://context7.com/mattwmaster58/playwright_stealth/llms.txt This snippet shows how to integrate Playwright Stealth using the synchronous context manager. By wrapping sync_playwright() with Stealth().use_sync(), you can easily apply stealth measures to your synchronous Playwright scripts. ```python from playwright_stealth import Stealth from playwright import sync_playwright with sync_playwright() as p: with Stealth().use_sync(p) as stealth_p: browser = stealth_p.chromium.launch() page = browser.new_page() page.goto("https://example.com") # ... rest of your automation code ``` -------------------------------- ### Integrate Playwright Stealth with Async Context Manager Source: https://context7.com/mattwmaster58/playwright_stealth/llms.txt This snippet demonstrates how to wrap the Playwright async context manager with Stealth().use_async() for automatic stealth application. This is the recommended approach for integrating stealth features into your asynchronous Playwright workflows. ```python from playwright_stealth import Stealth from playwright import async_playwright async with async_playwright() as p: async with Stealth().use_async(p) as stealth_p: browser = await stealth_p.chromium.launch() page = await browser.new_page() await page.goto("https://example.com") # ... rest of your automation code ``` -------------------------------- ### Manage Selective Evasion Control Source: https://context7.com/mattwmaster58/playwright_stealth/llms.txt Shows how to enable or disable individual evasion scripts using the ALL_EVASIONS_DISABLED_KWARGS constant. This is useful for creating minimal stealth profiles or toggling specific features like webdriver hiding. ```python import asyncio from playwright.async_api import async_playwright from playwright_stealth import Stealth, ALL_EVASIONS_DISABLED_KWARGS async def main(): no_evasions = Stealth(**ALL_EVASIONS_DISABLED_KWARGS) minimal_stealth = Stealth( **{ **ALL_EVASIONS_DISABLED_KWARGS, "navigator_webdriver": True, "navigator_plugins": True, "navigator_languages": True, } ) custom_stealth = Stealth( chrome_runtime=False, hairline=False, error_prototype=False, ) async with custom_stealth.use_async(async_playwright()) as p: browser = await p.chromium.launch() page = await browser.new_page() await page.goto("https://example.com") webdriver = await page.evaluate("navigator.webdriver") print(f"Webdriver hidden: {webdriver is False}") await browser.close() asyncio.run(main()) ``` -------------------------------- ### Playwright Stealth Integration Source: https://context7.com/mattwmaster58/playwright_stealth/llms.txt Demonstrates how to integrate Playwright Stealth for automatic or manual application of stealth measures. ```APIDOC ## Playwright Stealth Integration ### Description This section details the methods for integrating Playwright Stealth into your Playwright projects, covering both automatic and manual approaches. ### Automatic Integration Wrap your Playwright context manager with the `Stealth` class for seamless integration. ```python from playwright_stealth import Stealth, stealth async with stealth(): # Or sync_stealth() for sync context # Your Playwright code here browser = await async_playwright().chromium.launch() page = await browser.new_page() await page.goto("https://example.com") # ... ``` ### Manual Integration Use the `apply_stealth_async` or `apply_stealth_sync` functions to manually apply stealth measures to a browser instance. ```python from playwright_stealth import apply_stealth_async from playwright.async_api import async_playwright async def main(): async with async_playwright() as p: browser = await p.chromium.launch() await apply_stealth_async(browser) page = await browser.new_page() await page.goto("https://example.com") # ... # To run this example: # import asyncio # asyncio.run(main()) ``` ### Supported Browsers Playwright Stealth works best with Chromium. Firefox and WebKit are supported but with reduced effectiveness. ### Limitations This library is a proof-of-concept and is not designed to bypass sophisticated bot detection systems like Cloudflare, DataDome, or PerimeterX. It is intended for basic detection avoidance and educational purposes. ``` -------------------------------- ### Manual Stealth Application (Async) Source: https://context7.com/mattwmaster58/playwright_stealth/llms.txt Manually applies stealth evasion techniques to a specific Playwright browser context or page. ```APIDOC ## apply_stealth_async(context_or_page) ### Description Manually injects stealth evasion scripts into a specific browser context or page instance. Useful for granular control over which sessions receive stealth modifications. ### Method ASYNC FUNCTION ### Parameters #### Request Body - **context_or_page** (Object) - Required - The Playwright BrowserContext or Page instance to modify. ### Request Example await stealth.apply_stealth_async(context) ### Response #### Success Response (200) - **None** (Void) - Stealth scripts are injected directly into the target instance. ``` -------------------------------- ### Tag Version Bump Commit Source: https://github.com/mattwmaster58/playwright_stealth/blob/main/CONTRIBUTING.md Before building and publishing, maintainers must tag the version bump commit using Git. ```bash git tag x.y.z ``` -------------------------------- ### Stealth Context Application Source: https://github.com/mattwmaster58/playwright_stealth/blob/main/README.md Applies stealth evasions to a Playwright browser context to mask automation signatures. ```APIDOC ## Stealth().use_async(playwright_instance) ### Description Initializes a stealth-enabled Playwright context manager. All pages created within this context will automatically have stealth evasions applied. ### Method Python Context Manager ### Parameters #### Arguments - **playwright_instance** (async_playwright) - Required - The instance returned by async_playwright() ### Request Example ```python async with Stealth().use_async(async_playwright()) as p: browser = await p.chromium.launch() page = await browser.new_page() ``` ### Response #### Success Response - **context** (BrowserContext) - A browser context with stealth scripts pre-injected. ``` ```APIDOC ## Stealth.apply_stealth_async(context) ### Description Manually applies stealth evasions to an existing Playwright BrowserContext. ### Method Async Method ### Parameters #### Arguments - **context** (BrowserContext) - Required - The Playwright browser context to modify. ### Request Example ```python stealth = Stealth(navigator_languages_override=("fr-FR", "fr")) await stealth.apply_stealth_async(context) ``` ### Response #### Success Response - **None** (void) - The method modifies the context in-place by injecting initialization scripts. ``` -------------------------------- ### Access Stealth JavaScript Payload Source: https://context7.com/mattwmaster58/playwright_stealth/llms.txt Shows how to extract the generated stealth JavaScript payload for manual injection into browser pages or integration with other frameworks. ```python stealth = Stealth( navigator_languages_override=("de-DE", "de"), script_logging=True, ) payload = stealth.script_payload # Use payload manually # await page.evaluate(payload) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.