Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 74 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,23 @@ $ pip install playwright-stealth
```

## Usage

Default stealth
### sync
```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()
browser = browser_type.launch(headless=False)
page = browser.new_page()
stealth_sync(page)
page.goto('http://whatsmyuseragent.org/')
page.screenshot(path=f'example-{browser_type.name}.png')
page.goto('https://bot.sannysoft.com/')
page.screenshot(path=f'example-{browser_type.name}.png', full_page=True)
browser.close()

```

### async
```python
# -*- coding: utf-8 -*-
Expand All @@ -35,22 +36,81 @@ 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()
browser = await browser_type.launch(headless=False)
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 page.goto('https://bot.sannysoft.com/')
await page.screenshot(path=f'example-{browser_type.name}.png', full_page=True)
await browser.close()

asyncio.get_event_loop().run_until_complete(main())
asyncio.run(main())
```

## Test results
Desired stealth argument (as a mobile device)
### sync
```python
from playwright.sync_api import sync_playwright
from playwright_stealth import stealth_sync, StealthConfig

### playwright with stealth
with sync_playwright() as p:
for browser_type in [p.chromium, p.firefox, p.webkit]:
browser = browser_type.launch(headless=False)
context = browser.new_context(**p.devices["Pixel 7"])
page = context.new_page()
# Setting desired values for navigator properties
stealth_config = StealthConfig(
languages = ['en-US', 'en'],
navigator_plugins = False, # Mimicking real mobile device
navigator_hardware_concurrency = 8,
# nav_vendor = "", # Use only if you need to set empty string value to mimicking Firefox browser
nav_platform= 'Linux armv81',
vendor = 'Google Inc. (Qualcomm)',
renderer = 'ANGLE (Qualcomm, Adreno (TM) 640, OpenGL ES 3.2)',
)
stealth_sync(page, stealth_config)
page.goto('https://bot.sannysoft.com/')
page.screenshot(path=f'example-{browser_type.name}.png', full_page=True)
browser.close()
```

![playwright without stealth](./images/example_with_stealth.png)
### async
```python
# -*- coding: utf-8 -*-
import asyncio
from playwright.async_api import async_playwright
from playwright_stealth import stealth_async, StealthConfig

async def main():
async with async_playwright() as p:
for browser_type in [p.chromium, p.firefox, p.webkit]:
browser = await browser_type.launch(headless=False)
context = await browser.new_context(**p.devices["Pixel 7"])
page = await context.new_page()
# Setting desired values for navigator properties
stealth_config = StealthConfig(
languages = ['en-US', 'en'],
navigator_plugins = False, # Mimicking real mobile device
navigator_hardware_concurrency = 8,
# nav_vendor = "", # Use only if you need to set empty string value to mimicking Firefox browser
nav_platform= 'Linux armv81',
vendor = 'Google Inc. (Qualcomm)',
renderer = 'ANGLE (Qualcomm, Adreno (TM) 640, OpenGL ES 3.2)',
)
await stealth_async(page, stealth_config)
await page.goto('https://bot.sannysoft.com/')
await page.screenshot(path=f'example-{browser_type.name}.png')
await browser.close()

asyncio.run(main())
```

## Test results
### Playwright with stealth(no passed argument)
![playwright with stealth](./images/example_with_stealth.png)

### playwright without stealth
### Playwright without stealth
![playwright without stealth](./images/example_without_stealth.png)

![playwright with stealth](./images/example_without_stealth.png)
### Playwright with stealth(with passed argument) but as a mobile device
*NB: Mobile device have no plugin unlike desktop*
![playwright stealth with specified arguments](./images/example_with_stealth_passed_arguments.png)
Binary file added images/example_with_stealth_passed_arguments.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.