From fcacf8106d28d4ac75aa69f7d354800150d9d546 Mon Sep 17 00:00:00 2001 From: daijro Date: Fri, 16 Aug 2024 21:43:58 -0500 Subject: [PATCH] README: Add Playwright usage example --- README.md | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/README.md b/README.md index cf53086..89de4c7 100644 --- a/README.md +++ b/README.md @@ -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 +) +``` + +
+ +See full example script... + + +```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()) +``` + +
+ --- ## Build System