### Install playwright-stealth via pip Source: https://github.com/atubodad/playwright_stealth/blob/main/README.md Install the package using pip. This is the standard installation command. ```bash $ pip install playwright-stealth ``` -------------------------------- ### enabled_scripts override example Source: https://github.com/atubodad/playwright_stealth/blob/main/_autodocs/configuration.md Example of overriding the enabled_scripts property to prepend and append injectable scripts. Implement as a generator method/property returning str; stealth_sync()/stealth_async() iterate it linearly, and each yielded string becomes one Playwright init script. ```python @property def enabled_scripts(): yield 'console.log("first script")' yield from super().enabled_scripts() yield 'console.log("last script")' ``` -------------------------------- ### Async usage with stealth_async Source: https://github.com/atubodad/playwright_stealth/blob/main/README.md Use stealth_async with the async Playwright API. The example defines an async main function that iterates over browser types, applies stealth, navigates, and screenshots, then runs it with asyncio. ```python # -*- coding: utf-8 -*- import asyncio from playwright.async_api import async_playwright from playwright_stealth import stealth_async async def main(): async with async_playwright() as p: for browser_type in [p.chromium, p.firefox, p.webkit]: browser = await browser_type.launch() page = await browser.new_page() await stealth_async(page) await page.goto('http://whatsmyuseragent.org/') await page.screenshot(path=f'example-{browser_type.name}.png') await browser.close() asyncio.get_event_loop().run_until_complete(main()) ``` -------------------------------- ### enabled_scripts property definition Source: https://github.com/atubodad/playwright_stealth/blob/main/_autodocs/api-reference/stealth-config.md Defines the enabled_scripts property as a generator that yields JavaScript strings in execution order. The yielded sequence starts with the opts JSON, then the utils and generate_magic_arrays scripts, followed by enabled strategy scripts in a fixed order, each gated by its toggle. The property is a generator per access, so it can be subscribed to lazily. ```python @property def enabled_scripts(self): ... ``` -------------------------------- ### Serialize opts JSON and yield init script Source: https://github.com/atubodad/playwright_stealth/blob/main/_autodocs/configuration.md Shows how enabled_scripts serializes the configuration into a JSON object named 'opts' and yields it as the first init-script line. The JavaScript reads values back via opts.. ```python opts = json.dumps({ 'webgl_vendor': self.vendor, 'webgl_renderer': self.renderer, 'navigator_vendor': self.nav_vendor, 'navigator_platform': self.nav_platform, 'navigator_user_agent': self.nav_user_agent, 'languages': list(self.languages), 'runOnInsecureOrigins': self.runOnInsecureOrigins, }) yield f'const opts = {opts}' ``` -------------------------------- ### Generator-based inspection of enabled_scripts Source: https://github.com/atubodad/playwright_stealth/blob/main/_autodocs/api-reference/stealth-config.md Creates a StealthConfig with navigator_plugins disabled and lists the enabled scripts. The output shows 18 scripts (opts, utils, generate_magic_arrays plus 15 other strategies) and prints the first 60 characters of the first three. ```python config = StealthConfig(navigator_plugins=False) scripts = list(config.enabled_scripts) print(len(scripts)) # 18: opts, utils, generate_magic_arrays + 15 other strategies for s in scripts[:3]: print(s[:60], '...') ``` -------------------------------- ### stealth_async(page, config=None) Source: https://github.com/atubodad/playwright_stealth/blob/main/_autodocs/api-reference/stealth.md Teaches an asynchronous Playwright Page to be stealthy by registering init scripts. Awaits page.add_init_script for each script in the config's enabled_scripts. ```APIDOC ## stealth_async(page, config=None) ### Description Teaches an asynchronous Playwright Page to be stealthy like a ninja. Awaits page.add_init_script(script) for each script in the config's enabled_scripts. ### Signature ```python async def stealth_async(page: AsyncPage, config: StealthConfig = None): """teaches asynchronous playwright Page to be stealthy like a ninja!""" for script in (config or StealthConfig()).enabled_scripts: await page.add_init_script(script) ``` ### Parameters - **page** (playwright.async_api.Page) - Required - An asynchronous Playwright Page. - **config** (StealthConfig) - Optional - Default: None (StealthConfig() is used). Toggles which init scripts get registered. ### Return Value - Coroutine; resolves to None. ### Behavior - Same as stealth_sync, but awaits page.add_init_script(script). - This is the coroutine you await in an async def Playwright driver loop. ### Exceptions - No custom exceptions. Propagates errors from page.add_init_script. ``` -------------------------------- ### Import stealth functions in __init__.py Source: https://github.com/atubodad/playwright_stealth/blob/main/_autodocs/api-reference/stealth.md Shows the re-export of the main public API from the stealth module. This is the entire content of the package's __init__.py. ```python # playwright_stealth/__init__.py from playwright_stealth.stealth import stealth_sync, stealth_async, StealthConfig ``` -------------------------------- ### Custom StealthConfig with error-tolerant settings Source: https://github.com/atubodad/playwright_stealth/blob/main/_autodocs/api-reference/stealth.md Creates a StealthConfig that disables webdriver, navigator_plugins, and hairline, sets custom languages, vendor, and renderer, then applies it via stealth_sync. Iterates over enabled_scripts to inspect hooks, noting scripts are generated lazily. ```python from playwright.sync_api import sync_playwright from playwright_stealth import stealth_sync, StealthConfig config = StealthConfig( webdriver=False, # leave navigator.webdriver untouched navigator_plugins=False, hairline=False, languages=('de-DE', 'de', 'en-US', 'en'), vendor='Mesa', renderer='Mesa DRI R600 (TURKS)', ) with sync_playwright() as p: browser = p.chromium.launch() page = browser.new_page() stealth_sync(page, config) page.goto('https://bot.sannysoft.com/') # inspect individual hooks for script in config.enabled_scripts: pass # scripts are generated lazily ``` -------------------------------- ### Basic synchronous usage with stealth_sync Source: https://github.com/atubodad/playwright_stealth/blob/main/_autodocs/api-reference/stealth.md Launches Chromium, Firefox, and WebKit browsers, applies stealth_sync to each page, navigates to bot.sannysoft.com, and takes a screenshot. Uses the sync Playwright API. ```python from playwright.sync_api import sync_playwright from playwright_stealth import stealth_sync with sync_playwright() as p: for browser_type in [p.chromium, p.firefox, p.webkit]: browser = browser_type.launch() page = browser.new_page() stealth_sync(page) page.goto('https://bot.sannysoft.com/') page.screenshot(path=f'example-{browser_type.name}.png') browser.close() ``` -------------------------------- ### Basic custom StealthConfig Source: https://github.com/atubodad/playwright_stealth/blob/main/_autodocs/api-reference/stealth-config.md Creates a StealthConfig that disables webdriver, chrome_app, and media_codecs strategies and sets a custom language list. The webdriver=False comment notes that navigator.webdriver is left untouched. ```python from playwright_stealth import StealthConfig config = StealthConfig( webdriver=False, # don't touch navigator.webdriver chrome_app=False, media_codecs=False, languages=('fr-FR', 'fr', 'en-US', 'en'), ) ``` -------------------------------- ### stealth_sync(page, config=None) Source: https://github.com/atubodad/playwright_stealth/blob/main/_autodocs/api-reference/stealth.md Teaches a synchronous Playwright Page to be stealthy by registering init scripts. Iterates over the config's enabled_scripts and adds each script to the page. ```APIDOC ## stealth_sync(page, config=None) ### Description Teaches a synchronous Playwright Page to be stealthy like a ninja. Iterates over the config's enabled_scripts generator and registers each JavaScript snippet with page.add_init_script(script), so every future navigation re-applies the spoofing. ### Signature ```python def stealth_sync(page: SyncPage, config: StealthConfig = None): """teaches synchronous playwright Page to be stealthy like a ninja!""" for script in (config or StealthConfig()).enabled_scripts: page.add_init_script(script) ``` ### Parameters - **page** (playwright.sync_api.Page) - Required - A synchronous Playwright Page that is about to be navigated. - **config** (StealthConfig) - Optional - Default: None (StealthConfig() is used). Toggles which init scripts get registered. ### Return Value - None ### Behavior - Iterates the config's enabled_scripts generator and registers each JavaScript snippet with page.add_init_script(script). - Applies to persistent context pages and new pages. ### Exceptions - No custom exceptions. Propagates whatever page.add_init_script would raise (e.g., if page was already closed). ``` -------------------------------- ### Custom options serialized into opts Source: https://github.com/atubodad/playwright_stealth/blob/main/_autodocs/api-reference/stealth-config.md Sets vendor, renderer, and languages options that are serialized into the opts object a page sees. All keys listed here are visible to the page. ```python config = StealthConfig( vendor='Intel Inc.', renderer='Intel Iris OpenGL Engine', languages=('en-US', 'en'), ) print(config.enabled_scripts) ``` -------------------------------- ### Sync usage with stealth_sync Source: https://github.com/atubodad/playwright_stealth/blob/main/README.md Use stealth_sync with the sync Playwright API. Launches each browser type, applies stealth, navigates to a test site, and takes a screenshot. ```python from playwright.sync_api import sync_playwright from playwright_stealth import stealth_sync with sync_playwright() as p: for browser_type in [p.chromium, p.firefox, p.webkit]: browser = browser_type.launch() page = browser.new_page() stealth_sync(page) page.goto('http://whatsmyuseragent.org/') page.screenshot(path=f'example-{browser_type.name}.png') browser.close() ``` -------------------------------- ### All-off StealthConfig preset Source: https://github.com/atubodad/playwright_stealth/blob/main/_autodocs/configuration.md Configuration that disables all stealth features, for sites that need zero tampering. Note that navigator_hardware_concurrency is a dead field and always yields the script anyway. ```python StealthConfig( webdriver=False, webgl_vendor=False, chrome_app=False, chrome_csi=False, chrome_load_times=False, chrome_runtime=False, iframe_content_window=False, media_codecs=False, navigator_languages=False, navigator_permissions=False, navigator_platform=False, navigator_plugins=False, navigator_user_agent=False, navigator_vendor=False, outerdimensions=False, hairline=False, navigator_hardware_concurrency=0, # note: dead field, always yields the script anyway ) ``` -------------------------------- ### StealthConfig Constructor Source: https://github.com/atubodad/playwright_stealth/blob/main/_autodocs/api-reference/stealth-config.md Creates a StealthConfig instance. All fields are optional and default to the values shown. The dataclass synthesizes the __init__ method, so any subset of fields can be passed as keyword arguments. ```APIDOC ## StealthConfig Constructor ### Description Creates a StealthConfig instance that controls which JavaScript stealth scripts are registered as Playwright init scripts and the values they inject. ### Method Constructor (dataclass) ### Signature ```python StealthConfig( webdriver: bool = True, webgl_vendor: bool = True, chrome_app: bool = True, chrome_csi: bool = True, chrome_load_times: bool = True, chrome_runtime: bool = True, iframe_content_window: bool = True, media_codecs: bool = True, navigator_hardware_concurrency: int = 4, navigator_languages: bool = True, navigator_permissions: bool = True, navigator_platform: bool = True, navigator_plugins: bool = True, navigator_user_agent: bool = True, navigator_vendor: bool = True, outerdimensions: bool = True, hairline: bool = True, vendor: str = 'Intel Inc.', renderer: str = 'Intel Iris OpenGL Engine', nav_vendor: str = 'Google Inc.', nav_user_agent: str = None, nav_platform: str = None, languages: Tuple[str] = ('en-US', 'en'), runOnInsecureOrigins: Optional[bool] = None, ) ``` ### Parameters All parameters are optional (keyword arguments). - **webdriver** (bool) - Optional - Enable/disable the webdriver stealth script. - **webgl_vendor** (bool) - Optional - Enable/disable the WebGL vendor stealth script. - **chrome_app** (bool) - Optional - Enable/disable the chrome.app stealth script. - **chrome_csi** (bool) - Optional - Enable/disable the chrome.csi stealth script. - **chrome_load_times** (bool) - Optional - Enable/disable the chrome.loadTimes stealth script. - **chrome_runtime** (bool) - Optional - Enable/disable the chrome.runtime stealth script. - **iframe_content_window** (bool) - Optional - Enable/disable the iframe contentWindow stealth script. - **media_codecs** (bool) - Optional - Enable/disable the media codecs stealth script. - **navigator_hardware_concurrency** (int) - Optional - Value to inject for navigator.hardwareConcurrency. - **navigator_languages** (bool) - Optional - Enable/disable the navigator.languages stealth script. - **navigator_permissions** (bool) - Optional - Enable/disable the navigator.permissions stealth script. - **navigator_platform** (bool) - Optional - Enable/disable the navigator.platform stealth script. - **navigator_plugins** (bool) - Optional - Enable/disable the navigator.plugins stealth script. - **navigator_user_agent** (bool) - Optional - Enable/disable the navigator.userAgent stealth script. - **navigator_vendor** (bool) - Optional - Enable/disable the navigator.vendor stealth script. - **outerdimensions** (bool) - Optional - Enable/disable the outer dimensions stealth script. - **hairline** (bool) - Optional - Enable/disable the hairline stealth script. - **vendor** (str) - Optional - Value to inject for WebGL vendor. - **renderer** (str) - Optional - Value to inject for WebGL renderer. - **nav_vendor** (str) - Optional - Value to inject for navigator.vendor. - **nav_user_agent** (str) - Optional - Value to inject for navigator.userAgent. - **nav_platform** (str) - Optional - Value to inject for navigator.platform. - **languages** (Tuple[str]) - Optional - Value to inject for navigator.languages. - **runOnInsecureOrigins** (Optional[bool]) - Optional - Whether to run on insecure origins. ### Usage Notes - Each call to `stealth_sync(page)` / `stealth_async(page)` without an explicit config constructs a fresh `StealthConfig()`. - Passing the same config object to multiple calls re-runs the identical scripts (Playwright deduplicates identical init scripts per page). ``` -------------------------------- ### stealth_sync: Apply stealth scripts to a synchronous Playwright page Source: https://github.com/atubodad/playwright_stealth/blob/main/_autodocs/api-reference/stealth.md Registers each enabled init script from the config on a synchronous Playwright page. If config is None, a default StealthConfig is used. Returns None. Propagates any errors from page.add_init_script. ```python def stealth_sync(page: SyncPage, config: StealthConfig = None): """teaches synchronous playwright Page to be stealthy like a ninja!""" for script in (config or StealthConfig()).enabled_scripts: page.add_init_script(script) ``` -------------------------------- ### stealth_async: Apply stealth scripts to an asynchronous Playwright page Source: https://github.com/atubodad/playwright_stealth/blob/main/_autodocs/api-reference/stealth.md Registers each enabled init script from the config on an asynchronous Playwright page, awaiting each add_init_script call. If config is None, a default StealthConfig is used. Returns a coroutine that resolves to None. Propagates any errors from page.add_init_script. ```python async def stealth_async(page: AsyncPage, config: StealthConfig = None): """teaches asynchronous playwright Page to be stealthy like a ninja!""" for script in (config or StealthConfig()).enabled_scripts: await page.add_init_script(script) ``` -------------------------------- ### Minimal StealthConfig preset Source: https://github.com/atubodad/playwright_stealth/blob/main/_autodocs/configuration.md Minimal configuration that disables only the essential stealth features, leaving others enabled. Use when you need the absolute must-haves for stealth. ```python StealthConfig( webdriver=False, # evaluate navigator.webdriver normally webgl_vendor=False, chrome_app=False, chrome_csi=False, chrome_load_times=False, chrome_runtime=False, iframe_content_window=False, media_codecs=False, navigator_languages=False, navigator_permissions=False, navigator_platform=False, navigator_plugins=False, navigator_user_agent=False, navigator_vendor=False, outerdimensions=False, hairline=False, ) ``` -------------------------------- ### StealthConfig synthesized constructor with default values Source: https://github.com/atubodad/playwright_stealth/blob/main/_autodocs/api-reference/stealth-config.md Dataclass-generated constructor call with all 18 default parameters. Each boolean toggle controls whether a corresponding JavaScript strategy script is registered as a Playwright init script; navigator_hardware_concurrency sets the injected value. ```python StealthConfig( webdriver: bool = True, webgl_vendor: bool = True, chrome_app: bool = True, chrome_csi: bool = True, chrome_load_times: bool = True, chrome_runtime: bool = True, navigator_languages: bool = True, navigator_plugins: bool = True, navigator_vendor: bool = True, navigator_user_agent: bool = True, navigator_hardware_concurrency: int = 4, navigator_platform: bool = True, navigator_do_not_track: bool = True, media_codecs: bool = True, iframe_content_window: bool = True, window_dimensions: bool = True, window_chrome: bool = True, window_permissions: bool = True, languages: bool = True, insecure_origin: bool = True, webgl_vendor_value: str = ``` ```python @dataclass class StealthConfig: ... ``` -------------------------------- ### Extending enabled_scripts via subclass Source: https://github.com/atubodad/playwright_stealth/blob/main/_autodocs/api-reference/stealth-config.md Shows the documented extension pattern for subclassing StealthConfig and overriding the enabled_scripts property. Use yield from super().enabled_scripts() to include the default scripts, and add custom scripts before and after. ```python class MyConfig(StealthConfig): @property def enabled_scripts(self): yield 'console.log("first script")' yield from super().enabled_scripts() yield 'console.log("last script")' ``` -------------------------------- ### from_file(name) Source: https://github.com/atubodad/playwright_stealth/blob/main/_autodocs/api-reference/stealth.md A module-level helper function that reads a JavaScript file from the package's js directory. It is used internally to load scripts. ```APIDOC ## from_file(name) ### Description A module-level helper function that reads a JavaScript file from the package's js directory. It is used internally to load scripts. ### Method Function call ### Endpoint N/A (Python function) ### Parameters - **name** (str) - Required - The name of the JavaScript file to read. ### Request Example ```python from playwright_stealth.stealth import from_file script = from_file('some_script.js') ``` ### Response #### Success Response The content of the JavaScript file as a string. #### Response Example No response body. ``` -------------------------------- ### Lazy iteration over enabled_scripts Source: https://github.com/atubodad/playwright_stealth/blob/main/_autodocs/api-reference/stealth-config.md Shows how to lazily iterate over the enabled_scripts generator. Because enabled_scripts is a generator per access, each access yields a fresh generator. The loop processes each yielded JavaScript snippet. ```python config = StealthConfig(webdriver=False) for script in config.enabled_scripts: # fresh generator each time ... ``` -------------------------------- ### from_file function to read JS scripts Source: https://github.com/atubodad/playwright_stealth/blob/main/_autodocs/api-reference/stealth.md Reads a JavaScript file from the js/ package directory and decodes it as UTF-8 text. Raises pkg_resources/FileNotFoundError if the file is missing. Used internally by the SCRIPTS dict. ```python def from_file(name): """Read script from ./js directory""" return pkg_resources.resource_string('playwright_stealth', f'js/{name}').decode() ``` -------------------------------- ### enabled_scripts property Source: https://github.com/atubodad/playwright_stealth/blob/main/_autodocs/api-reference/stealth-config.md Yields JavaScript strings in execution order. The yielded sequence includes options JSON, utils script, generate_magic_arrays script, and enabled strategy scripts in a fixed order. It is a generator per access, allowing lazy subscription. ```APIDOC ## Property: `enabled_scripts` ### Description Yields JavaScript strings in execution order. The yielded sequence is (literal): 1. `const opts = { ... }` — JSON with the value options only (`webgl_vendor`, `webgl_renderer`, `navigator_vendor`, `navigator_platform`, `navigator_user_agent`, `languages`, `runOnInsecureOrigins`) 2. `utils` script (`utils.js`) 3. `generate_magic_arrays` script (`generate.magic.arrays.js`) 4. Enabled strategy scripts, in this fixed order (each gated by its toggle): | Order | Toggle | Script key | |-------|--------|------------| | 4 | `chrome_csi` | `chrome_csi` | | 5 | `chrome_app` | `chrome_app` | | 6 | `hairline` | `chrome_hairline` | | 7 | `chrome_load_times` | `chrome_load_times` | | 8 | `chrome_runtime` | `chrome_runtime` | | 9 | `iframe_content_window` | `iframe_content_window` | | 10 | `media_codecs` | `media_codecs` | | 11 | `navigator_languages` | `navigator_languages` | | 12 | `navigator_permissions` | `navigator_permissions` | | 13 | `navigator_platform` | `navigator_platform` | | 14 | `navigator_plugins` | `navigator_plugins` | | 15 | `navigator_user_agent` | `navigator_user_agent` | | 16 | `navigator_vendor` | `navigator_vendor` | | 17 | `webdriver` | `webdriver` | | 18 | `outerdimensions` | `outerdimensions` | | 19 | `webgl_vendor` | `webgl_vendor` | Because `enabled_scripts` is a **generator per access**, you can subscribe to it lazily: ```python config = StealthConfig(webdriver=False) for script in config.enabled_scripts: # fresh generator each time ... ``` - Yields `str` (a complete JS snippet, each with its own Hooks/IIFE); combining yields a single init script. - If every toggle is `False`, still yields `opts`, `utils`, `generate_magic_arrays` (α helper scripts are unconditional). `utils.js` additionally is re-injected front by `enabled_scripts` — not user-configurable. - Does not yield `navigator_hardware_concurrency` regardless of value (dead field — see [errors.md](../errors.md#dead-configuration-fields)). ### Extension pattern (documented in the class docstring) The docstring shows how to subclass and extend the script list by overriding this property via `yield from super().enabled_scripts()`: ```python class MyConfig(StealthConfig): @property def enabled_scripts(self): yield 'console.log("first script")' yield from super().enabled_scripts() yield 'console.log("last script")' ``` ``` -------------------------------- ### Asynchronous usage with stealth_async Source: https://github.com/atubodad/playwright_stealth/blob/main/_autodocs/api-reference/stealth.md Uses the async Playwright API to apply stealth_async to pages in Chromium, Firefox, and WebKit, navigating to bot.sannysoft.com. Requires asyncio and the async_playwright context manager. ```python import asyncio from playwright.async_api import async_playwright from playwright_stealth import stealth_async async def main(): async with async_playwright() as p: for browser_type in [p.chromium, p.firefox, p.webkit]: browser = await browser_type.launch() page = await browser.new_page() await stealth_async(page) await page.goto('https://bot.sannysoft.com/') await browser.close() asyncio.run(main()) ``` -------------------------------- ### SCRIPTS Source: https://github.com/atubodad/playwright_stealth/blob/main/_autodocs/api-reference/stealth.md A module-level dictionary mapping script names to their JavaScript content. These scripts are used internally for stealth evasions. ```APIDOC ## SCRIPTS ### Description A module-level dictionary mapping script names to their JavaScript content. These scripts are used internally for stealth evasions. ### Method Module constant ### Endpoint N/A (Python constant) ### Parameters No parameters. ### Request Example ```python from playwright_stealth import SCRIPTS print(SCRIPTS) ``` ### Response #### Success Response A dictionary with string keys and string values. #### Response Example No response body. ``` -------------------------------- ### StealthConfig dataclass declaration Source: https://github.com/atubodad/playwright_stealth/blob/main/_autodocs/api-reference/stealth-config.md Defines the StealthConfig value object as a plain @dataclass. No custom __init__ is defined, so the dataclass synthesizes the constructor shown in the next snippet. ```python @dataclass class StealthConfig: ... ``` -------------------------------- ### async stealth_async(page: AsyncPage[, config]) Source: https://github.com/atubodad/playwright_stealth/blob/main/_autodocs/api-reference/stealth.md Applies stealth evasions to an asynchronous Playwright page. This coroutine function is used to modify the page to avoid detection by anti-bot systems. ```APIDOC ## async stealth_async(page: AsyncPage[, config]) ### Description Applies stealth evasions to an asynchronous Playwright page. This coroutine function is used to modify the page to avoid detection by anti-bot systems. ### Method Coroutine function ### Endpoint N/A (Python coroutine) ### Parameters - **page** (AsyncPage) - Required - The asynchronous Playwright page to apply stealth to. - **config** (StealthConfig) - Optional - Configuration for the stealth evasions. ### Request Example ```python import asyncio from playwright.async_api import async_playwright from playwright_stealth import stealth_async async def main(): async with async_playwright() as p: browser = await p.chromium.launch() page = await browser.new_page() await stealth_async(page) asyncio.run(main()) ``` ### Response #### Success Response No return value (None). The page is modified in place. #### Response Example No response body. ``` -------------------------------- ### StealthConfig Source: https://github.com/atubodad/playwright_stealth/blob/main/_autodocs/api-reference/stealth.md A dataclass that holds configuration options for the stealth evasions. It is used to customize which evasions are applied. ```APIDOC ## StealthConfig ### Description A dataclass that holds configuration options for the stealth evasions. It is used to customize which evasions are applied. ### Method Dataclass instantiation ### Endpoint N/A (Python class) ### Parameters No parameters are documented in the source. The dataclass fields are not listed in the provided text. ### Request Example ```python from playwright_stealth import StealthConfig config = StealthConfig() ``` ### Response #### Success Response An instance of StealthConfig. #### Response Example No response body. ``` -------------------------------- ### stealth_sync(page: SyncPage[, config]) Source: https://github.com/atubodad/playwright_stealth/blob/main/_autodocs/api-reference/stealth.md Applies stealth evasions to a synchronous Playwright page. This function is used to modify the page to avoid detection by anti-bot systems. ```APIDOC ## stealth_sync(page: SyncPage[, config]) ### Description Applies stealth evasions to a synchronous Playwright page. This function is used to modify the page to avoid detection by anti-bot systems. ### Method Function call ### Endpoint N/A (Python function) ### Parameters - **page** (SyncPage) - Required - The synchronous Playwright page to apply stealth to. - **config** (StealthConfig) - Optional - Configuration for the stealth evasions. ### Request Example ```python from playwright.sync_api import sync_playwright from playwright_stealth import stealth_sync with sync_playwright() as p: browser = p.chromium.launch() page = browser.new_page() stealth_sync(page) ``` ### Response #### Success Response No return value (None). The page is modified in place. #### Response Example No response body. ``` -------------------------------- ### Catch page-side JS errors with page.on('pageerror') Source: https://github.com/atubodad/playwright_stealth/blob/main/_autodocs/errors.md Use this pattern to collect JavaScript exceptions thrown on the page, including those from stealth script mocks. The pageerror handler receives the exception object; convert it to a string for storage. The try/except around stealth_sync catches Playwright exceptions (e.g., TargetClosedError), not playwright_stealth errors. ```python from playwright.sync_api import sync_playwright from playwright_stealth import stealth_sync with sync_playwright() as p: browser = p.chromium.launch() page = browser.new_page() errors = [] def on_pageerror(exc): errors.append(str(exc)) # page-side JS exceptions land here page.on("pageerror", on_pageerror) try: stealth_sync(page) except Exception as exc: # This is a *Playwright* exception (e.g. TargetClosedError), # not a playwright_stealth one. print("init script registration failed:", exc) page.goto("https://bot.sannysoft.com/") print("page errors seen:", errors) ``` -------------------------------- ### magicArray TypeError throw Source: https://github.com/atubodad/playwright_stealth/blob/main/_autodocs/errors.md Thrown by the magicArray helper in generate.magic.arrays.js when item() or namedItem() is invoked with incorrect arguments. Mimics Chromium's error format to avoid detection. ```javascript throw new TypeError( `Failed to execute 'item' on '${ proto[Symbol.toStringTag] }': 1 argument required, but only 0 present.` ) ```