README: Add Playwright usage example

This commit is contained in:
daijro 2024-08-16 21:43:58 -05:00
parent c144539759
commit fcacf8106d

View file

@ -350,6 +350,70 @@ Camoufox performs well against every major WAF I've tested. (Test sites from [Bo
Camoufox does **not** fully support injecting Chromium fingerprints. Some WAFs (such as [Interstitial](https://nopecha.com/demo/cloudflare)) test for Spidermonkey engine behavior, which is impossible to spoof.
## Playwright Usage
Camoufox is fully compatible with your existing Playwright code. You only have to change your browser initialization:
```py
browser = pw.firefox.launch(
executable_path='/path/to/camoufox/launch', # Path to the Camoufox launcher
args=['--config', '/path/to/config.json'], # Pass in file path or JSON string
)
```
<details>
<summary>
See full example script...
</summary>
```py
import asyncio
import json
from playwright.async_api import async_playwright
# Example config
CONFIG = {
'window.outerHeight': 1056,
'window.outerWidth': 1920,
'window.innerHeight': 1008,
'window.innerWidth': 1920,
'window.history.length': 4,
'navigator.userAgent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:125.0) Gecko/20100101 Firefox/125.0',
'navigator.appCodeName': 'Mozilla',
'navigator.appName': 'Netscape',
'navigator.appVersion': '5.0 (Windows)',
'navigator.oscpu': 'Windows NT 10.0; Win64; x64',
'navigator.language': 'en-US',
'navigator.languages': ['en-US'],
'navigator.platform': 'Win32',
'navigator.hardwareConcurrency': 12,
'navigator.product': 'Gecko',
'navigator.productSub': '20030107',
'navigator.maxTouchPoints': 10,
}
async def main():
async with async_playwright() as p:
# Create a Firefox instance to the launcher
browser = await p.firefox.launch(
# Pass in the Camoufox launcher and config JSON
executable_path='/path/to/camoufox/launch',
args=['--config', json.dumps(CONFIG)],
# Launch in headful mode
headless=False
)
# Continue as normal
page = await browser.new_page()
await page.goto('https://abrahamjuliot.github.io/creepjs/')
await asyncio.sleep(10)
await browser.close()
if __name__ == "__main__":
asyncio.run(main())
```
</details>
---
## Build System