playwright stealth
Project description
playwright_stealth
Transplanted from puppeteer-extra-plugin-stealth, Not perfect. Forked from playwright_stealth and re-released.
Install
$ pip install playwright-stealth2
Usage
Default stealth
sync
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(headless=False)
page = browser.new_page()
stealth_sync(page)
page.goto('https://bot.sannysoft.com/')
page.screenshot(path=f'example-{browser_type.name}.png', full_page=True)
browser.close()
async
# -*- 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(headless=False)
page = await browser.new_page()
await stealth_async(page)
await page.goto('https://bot.sannysoft.com/')
await page.screenshot(path=f'example-{browser_type.name}.png', full_page=True)
await browser.close()
asyncio.run(main())
Desired stealth argument (as a mobile device)
sync
from playwright.sync_api import sync_playwright
from playwright_stealth import stealth_sync, StealthConfig
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()
async
# -*- 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 without stealth
Playwright with stealth(with passed argument) but as a mobile device
NB: Mobile device have no plugin unlike desktop
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
playwright_sm-0.0.1.tar.gz
(21.3 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file playwright_sm-0.0.1.tar.gz.
File metadata
- Download URL: playwright_sm-0.0.1.tar.gz
- Upload date:
- Size: 21.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7c418e7fdf481006fa9128357dc0c992b39ed0b4547f408dfe38198af8602238
|
|
| MD5 |
568ae52994b3830489920c6020b39a07
|
|
| BLAKE2b-256 |
75642070bebe07ceac8ecb2a756073e4ba181b91412b14b1089c57e0407fd4f7
|
File details
Details for the file playwright_sm-0.0.1-py3-none-any.whl.
File metadata
- Download URL: playwright_sm-0.0.1-py3-none-any.whl
- Upload date:
- Size: 28.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fbf20136350402f04cb2c38e6abdb8052627919544e363e980449a03bf20f6d4
|
|
| MD5 |
1decd4f6ce61aa48878aa6cef486382a
|
|
| BLAKE2b-256 |
15cb28fb511e0f42b7914d0489ae23d6c998f7c9c0624e4e855557eaba035b6e
|