Skip to content

Commit

Permalink
chore: export ALL_EVASIONS_DISABLED_KWARGS
Browse files Browse the repository at this point in the history
  • Loading branch information
Mattwmaster58 committed Oct 23, 2024
1 parent 4e49e0f commit 13eee2b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ $ pip install git+https://github.com/Mattwmaster58/playwright_stealth
import asyncio

from playwright.async_api import async_playwright
from playwright_stealth import Stealth
from playwright_stealth import Stealth, ALL_EVASIONS_DISABLED_KWARGS


async def main():
Expand All @@ -30,12 +30,13 @@ async def main():
print("from new_context: ", await page_from_different_context.evaluate("navigator.webdriver"))

# Specifying config options and applying evasions manually to an entire context:
custom_languages = ["fr-FR", "fr"]
custom_languages = ("fr-FR", "fr")
stealth = Stealth(
navigator_languages_override=custom_languages,
init_scripts_only=True
)
async with async_playwright() as p:
# or, to hook every browser launched from this context: stealth.hook_playwright_context(p)
browser = await p.chromium.launch()
context = await browser.new_context()
await stealth.apply_stealth_async(context)
Expand All @@ -46,6 +47,11 @@ async def main():
concurrency_on_page_2_mocked = await page_2.evaluate("navigator.languages") == custom_languages
print("manually applied stealth applied to page 2:", concurrency_on_page_2_mocked)

# a constant "ALL_EVASIONS_DISABLED_KWARGS" is provided if only a few evasions are desired:
assert len(Stealth(**ALL_EVASIONS_DISABLED_KWARGS).script_payload) == 0
# all but navigator_webdriver disabled
assert len(Stealth(**{**ALL_EVASIONS_DISABLED_KWARGS, "navigator_webdriver": True}).script_payload) > 0


asyncio.run(main())
```
Expand Down
2 changes: 1 addition & 1 deletion playwright_stealth/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# -*- coding: utf-8 -*-
from playwright_stealth.stealth import Stealth
from playwright_stealth.stealth import Stealth, ALL_EVASIONS_DISABLED_KWARGS

0 comments on commit 13eee2b

Please sign in to comment.