### Install BrowserForge Source: https://context7.com/daijro/browserforge/llms.txt Install the library using pip. ```bash pip install browserforge[all] ``` -------------------------------- ### Fingerprint Response Example Source: https://github.com/daijro/browserforge/blob/main/README.md An example of the structure returned by the generate method. ```text Fingerprint(screen=ScreenFingerprint(availHeight=784, availWidth=1440, availTop=25, availLeft=0, colorDepth=30, height=900, pixelDepth=30, width=1440, devicePixelRatio=2, pageXOffset=0, pageYOffset=0, innerHeight=0, outerHeight=718, outerWidth=1440, innerWidth=0, screenX=0, clientWidth=0, clientHeight=19, hasHDR=True), navigator=NavigatorFingerprint(userAgent='Mozilla/5.0 (Macintosh; ' 'Intel Mac OS X 10_15_7) ' 'AppleWebKit/537.36 ' '(KHTML, like Gecko) ' 'Chrome/121.0.0.0 ' 'Safari/537.36', userAgentData={'architecture': 'arm', 'bitness': '64', 'brands': [{'brand': 'Not ' 'A(Brand', 'version': '99'}, {'brand': 'Google ' 'Chrome', 'version': '121'}, {'brand': 'Chromium', 'version': '121'}], 'fullVersionList': [{'brand': 'Not ' 'A(Brand', 'version': '99.0.0.0'}, {'brand': 'Google ' 'Chrome', 'version': '121.0.6167.160'}, {'brand': 'Chromium', 'version': '121.0.6167.160'}], 'mobile': False, 'model': '', 'platform': 'macOS', ``` -------------------------------- ### Initialize FingerprintGenerator Source: https://github.com/daijro/browserforge/blob/main/README.md Basic setup to instantiate the generator and produce a fingerprint. ```py from browserforge.fingerprints import FingerprintGenerator fingerprints = FingerprintGenerator() fingerprints.generate() ``` -------------------------------- ### Synchronous Browser Usage Example Source: https://context7.com/daijro/browserforge/llms.txt Demonstrates how to launch a browser, create a new context with a generated fingerprint, navigate to a URL, and close the browser using the synchronous API. ```python def sync_example(): from undetected_playwright.sync_api import sync_playwright fingerprint = FingerprintGenerator().generate() with sync_playwright() as playwright: browser = playwright.chromium.launch() context = NewContext(browser, fingerprint=fingerprint) page = context.new_page() page.goto('https://example.com') browser.close() asyncio.run(async_example()) ``` -------------------------------- ### Generate Browser Headers Source: https://github.com/daijro/browserforge/blob/main/README.md Instantiate HeaderGenerator and call generate() to get a dictionary of realistic browser headers. This is useful for mimicking browser requests. ```python >>> from browserforge.headers import HeaderGenerator >>> headers = HeaderGenerator() >>> headers.generate() {'sec-ch-ua': '"Chromium";v="142", "Google Chrome";v="142", "Not_A Brand";v="99"', 'sec-ch-ua-mobile': '?0', 'sec-ch-ua-platform': '"Windows"', 'Upgrade-Insecure-Requests': '1', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8', 'Sec-Fetch-Site': '?1', 'Sec-Fetch-Mode': 'same-site', 'Sec-Fetch-User': 'document', 'Sec-Fetch-Dest': 'navigate', 'Accept-Encoding': 'gzip, deflate, br, zstd', 'Accept-Language': 'en-US;q=1.0, en;q=0.9, de;q=0.8'} ``` -------------------------------- ### Initialize HeaderGenerator with Multiple Constraints Source: https://github.com/daijro/browserforge/blob/main/README.md Initializes the HeaderGenerator with multiple constraints to select from, based on real-world frequency. ```python headers = HeaderGenerator( browser=('chrome', 'firefox', 'safari', 'edge'), os=('windows', 'macos', 'linux', 'android', 'ios'), device=('desktop', 'mobile'), locale=('en-US', 'en', 'de'), http_version=2 ) ``` -------------------------------- ### Define Browser Constraints Source: https://context7.com/daijro/browserforge/llms.txt Shows how to define browser constraints including name, minimum/maximum versions, and HTTP version. These constraints are used to generate realistic browser headers and fingerprints. ```python from browserforge.headers import Browser, HeaderGenerator # Single browser with version range chrome = Browser( name='chrome', min_version=120, max_version=145, http_version=2 ) # Multiple browsers with different constraints browsers = [ Browser(name='chrome', min_version=140), Browser(name='firefox', min_version=120, max_version=144), Browser(name='edge', http_version=1), Browser(name='safari', min_version=16) ] headers = HeaderGenerator(browser=browsers) result = headers.generate( browser=[Browser(name='chrome', min_version=142)] ) ``` -------------------------------- ### Generate Headers from User-Agent String Source: https://github.com/daijro/browserforge/blob/main/README.md Generates headers based on a single provided User-Agent string. ```python >>> headers.generate(user_agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36') ``` -------------------------------- ### FingerprintGenerator Parameters Source: https://github.com/daijro/browserforge/blob/main/README.md Configuration options available during the initialization of the FingerprintGenerator. ```text Parameters: screen (Screen, optional): Screen constraints for the generated fingerprint. strict (bool, optional): Whether to raise an exception if the constraints are too strict. Default is False. mock_webrtc (bool, optional): Whether to mock WebRTC when injecting the fingerprint. Default is False. slim (bool, optional): Disables performance-heavy evasions when injecting the fingerprint. Default is False. **header_kwargs: Header generation options for HeaderGenerator ``` -------------------------------- ### Generate Headers from Multiple User-Agent Strings Source: https://github.com/daijro/browserforge/blob/main/README.md Generates headers by selecting from a list of User-Agent strings based on their frequency. ```python >>> headers.generate(user_agent=( 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:144.0) Gecko/20100101 Firefox/144.0', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36' )) ``` -------------------------------- ### Initialize HeaderGenerator with Single Constraint Source: https://github.com/daijro/browserforge/blob/main/README.md Initializes the HeaderGenerator with a single constraint for browser, OS, device, locale, and HTTP version. ```python headers = HeaderGenerator( browser='chrome', os='windows', device='desktop', locale='en-US', http_version=2 ) ``` -------------------------------- ### Generate Browser Fingerprints with FingerprintGenerator Source: https://context7.com/daijro/browserforge/llms.txt Create comprehensive browser fingerprints including navigator details, screen properties, and hardware info. ```python from browserforge.fingerprints import FingerprintGenerator, Screen # Basic fingerprint generation fingerprints = FingerprintGenerator() fp = fingerprints.generate() # Access fingerprint properties print(fp.navigator.userAgent) # User agent string print(fp.screen.width) # Screen width print(fp.screen.height) # Screen height print(fp.headers) # Generated HTTP headers print(fp.videoCard.renderer) # GPU renderer info print(fp.fonts) # Available fonts list # Constrain screen dimensions screen = Screen( min_width=100, max_width=1280, min_height=400, max_height=720, ) fingerprints = FingerprintGenerator(screen=screen) fp = fingerprints.generate() # Combine with browser constraints fingerprints = FingerprintGenerator( browser='chrome', os='windows', screen=Screen(min_width=1920, min_height=1080), strict=True, # Raise error if constraints too restrictive mock_webrtc=True, # Mock WebRTC when injecting slim=False # Enable all evasions ) fp = fingerprints.generate() # Override options at generation time fp = fingerprints.generate( browser='firefox', os='macos', screen=Screen(max_width=1440) ) # Serialize fingerprint to JSON json_str = fp.dumps() ``` -------------------------------- ### Define Screen Dimension Constraints Source: https://context7.com/daijro/browserforge/llms.txt Illustrates how to constrain screen dimensions (width and height) for generated fingerprints. This is useful for simulating different devices like desktops or mobiles. ```python from browserforge.fingerprints import FingerprintGenerator, Screen # Constrain to desktop-sized screens desktop_screen = Screen( min_width=1280, max_width=2560, min_height=720, max_height=1440 ) # Constrain to mobile-sized screens mobile_screen = Screen( min_width=320, max_width=428, min_height=568, max_height=926 ) # 4K screen constraints screen_4k = Screen( min_width=3840, min_height=2160 ) # Use in generator fingerprints = FingerprintGenerator(screen=desktop_screen) fingerprint_instance = fingerprints.generate() print(f"Screen: {fingerprint_instance.screen.width}x{fingerprint_instance.screen.height}") # Override at generation time fp = fingerprints.generate(screen=mobile_screen) ``` -------------------------------- ### FingerprintGenerator Initialization Source: https://github.com/daijro/browserforge/blob/main/README.md Initialize the FingerprintGenerator with optional parameters to customize fingerprint generation. ```APIDOC ## Initialize FingerprintGenerator ### Description Initializes the FingerprintGenerator class. You can provide constraints for screen properties and control various generation behaviors. ### Method `FingerprintGenerator(screen=None, strict=False, mock_webrtc=False, slim=False, **header_kwargs)` ### Parameters #### Constructor Parameters - **screen** (Screen, optional) - Screen constraints for the generated fingerprint. - **strict** (bool, optional) - Whether to raise an exception if the constraints are too strict. Defaults to `False`. - **mock_webrtc** (bool, optional) - Whether to mock WebRTC when injecting the fingerprint. Defaults to `False`. - **slim** (bool, optional) - Disables performance-heavy evasions when injecting the fingerprint. Defaults to `False`. - **header_kwargs** - Additional keyword arguments passed to `HeaderGenerator` for header generation options. ### Request Example ```python from browserforge.fingerprints import FingerprintGenerator # Initialize with default settings fingerprints = FingerprintGenerator() # Initialize with custom screen constraints # from browserforge.fingerprints import Screen # screen_constraints = Screen(width=1920, height=1080) # fingerprints = FingerprintGenerator(screen=screen_constraints, strict=True) ``` ### Response This method returns an instance of `FingerprintGenerator`. ``` -------------------------------- ### Access Fingerprint Data Structure Source: https://context7.com/daijro/browserforge/llms.txt Demonstrates how to generate a fingerprint and access its various properties, including screen, navigator, headers, codecs, and hardware information. The `dumps()` method serializes the fingerprint to JSON. ```python from browserforge.fingerprints import FingerprintGenerator fingerprints = FingerprintGenerator() fp = fingerprints.generate() # Screen properties print(fp.screen.width) print(fp.screen.height) print(fp.screen.devicePixelRatio) print(fp.screen.colorDepth) print(fp.screen.availWidth) print(fp.screen.availHeight) # Navigator properties print(fp.navigator.userAgent) print(fp.navigator.platform) print(fp.navigator.language) print(fp.navigator.languages) print(fp.navigator.hardwareConcurrency) print(fp.navigator.deviceMemory) print(fp.navigator.maxTouchPoints) print(fp.navigator.webdriver) # Headers (properly ordered for browser) print(fp.headers['User-Agent']) print(fp.headers['Accept-Language']) # Media codecs print(fp.videoCodecs) print(fp.audioCodecs) # Hardware info print(fp.videoCard.vendor) print(fp.videoCard.renderer) # Other properties print(fp.fonts) print(fp.battery) print(fp.multimediaDevices) print(fp.pluginsData) # Serialize to JSON json_string = fp.dumps() ``` -------------------------------- ### Initialize HeaderGenerator with Specific Browser Specifications Source: https://github.com/daijro/browserforge/blob/main/README.md Initializes the HeaderGenerator with specific browser versions and HTTP versions using the Browser class. ```python from browserforge.headers import Browser browsers = [ Browser(name='chrome', min_version=140, max_version=145), Browser(name='firefox', min_version=144), Browser(name='edge', max_version=140, http_version=1), ] headers = HeaderGenerator(browser=browsers) ``` -------------------------------- ### Constrain Screen Dimensions with Screen Source: https://github.com/daijro/browserforge/blob/main/README.md Use the Screen class to define minimum and maximum values for screen width and height when generating fingerprints. Not all bounds need to be specified. ```python from browserforge.fingerprints import Screen screen = Screen( min_width=100, max_width=1280, min_height=400, max_height=720, ) fingerprints = FingerprintGenerator(screen=screen) ``` -------------------------------- ### Generate Fingerprint with Browser and OS Constraints Source: https://github.com/daijro/browserforge/blob/main/README.md Generate a fingerprint by specifying browser and operating system constraints. This leverages parameters inherited from HeaderGenerator. ```python fingerprint.generate(browser='chrome', os='windows') ``` -------------------------------- ### Integrate Headers with Requests Session Source: https://github.com/daijro/browserforge/blob/main/README.md Demonstrates how to add generated headers to a requests.Session object for subsequent HTTP requests. ```python import requests session = requests.Session() ``` -------------------------------- ### Uninstall Browserforge Source: https://github.com/daijro/browserforge/blob/main/README.md Command to uninstall the browserforge package using pip. ```bash pip uninstall browserforge ``` -------------------------------- ### HeaderGenerator Constructor Source: https://github.com/daijro/browserforge/blob/main/README.md Initializes the HeaderGenerator with specific constraints for browser, OS, device, locale, and HTTP version. ```APIDOC ## HeaderGenerator Constructor ### Description Initializes the generator with constraints that define the pool of headers to be generated. ### Parameters #### Request Body - **browser** (ListOrString/Iterable[Browser]) - Optional - Browser(s) or Browser object(s). - **os** (ListOrString) - Optional - Operating system(s) to generate headers for. - **device** (ListOrString) - Optional - Device(s) to generate the headers for. - **locale** (ListOrString) - Optional - List of at most 10 languages for the Accept-Language header. - **http_version** (Literal[1, 2]) - Optional - Http version to be used. - **strict** (bool) - Optional - Throws an error if it cannot generate headers based on the input. ``` -------------------------------- ### Generate HTTP Headers with HeaderGenerator Source: https://context7.com/daijro/browserforge/llms.txt Create browser-appropriate HTTP headers with support for constraints on browser, OS, device, locale, and HTTP version. ```python from browserforge.headers import HeaderGenerator, Browser # Basic usage - generate headers with default settings headers = HeaderGenerator() result = headers.generate() # Output: {'sec-ch-ua': '"Chromium";v="142"...', 'User-Agent': 'Mozilla/5.0...', ...} # Constrain to specific browser and OS headers = HeaderGenerator( browser='chrome', os='windows', device='desktop', locale='en-US', http_version=2 ) result = headers.generate() # Multiple constraints - options selected based on real-world frequency headers = HeaderGenerator( browser=('chrome', 'firefox', 'safari', 'edge'), os=('windows', 'macos', 'linux', 'android', 'ios'), device=('desktop', 'mobile'), locale=('en-US', 'en', 'de'), http_version=2 ) result = headers.generate() # Browser version specifications browsers = [ Browser(name='chrome', min_version=140, max_version=145), Browser(name='firefox', min_version=144), Browser(name='edge', max_version=140, http_version=1), ] headers = HeaderGenerator(browser=browsers) result = headers.generate() # Generate headers for a specific User-Agent result = headers.generate( user_agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36' ) # Use with requests library import requests session = requests.Session() session.headers = headers.generate() response = session.get('https://example.com') ``` -------------------------------- ### Set Session Headers Source: https://github.com/daijro/browserforge/blob/main/README.md Sets the session headers by generating them using the headers.generate() method. ```python session.headers = headers.generate() ``` -------------------------------- ### Inject Fingerprint into Playwright Async Context Source: https://github.com/daijro/browserforge/blob/main/README.md Replace `await browser.new_context` with `await AsyncNewContext` to create an asynchronous Playwright context with an injected fingerprint. The fingerprint can be provided directly or generated using options. ```python # Import the AsyncNewContext injector from browserforge.injectors.playwright import AsyncNewContext async def main(): async with async_playwright() as playwright: browser = await playwright.chromium.launch() # Create a new async context with the injected fingerprint context = await AsyncNewContext(browser, fingerprint=fingerprint) page = await context.new_page() ... ``` -------------------------------- ### FingerprintGenerator.generate() Source: https://github.com/daijro/browserforge/blob/main/README.md Generates a fingerprint and a matching set of ordered headers. ```APIDOC ## FingerprintGenerator.generate() ### Description Generates a fingerprint and a matching set of ordered headers using a combination of the default options specified in the constructor and their possible overrides provided here. ### Method `generate(screen=None, strict=False, mock_webrtc=False, slim=False, **header_kwargs)` ### Parameters #### Method Parameters - **screen** (Screen, optional) - Screen constraints for the generated fingerprint. - **strict** (bool, optional) - Whether to raise an exception if the constraints are too strict. - **mock_webrtc** (bool, optional) - Whether to mock WebRTC when injecting the fingerprint. Defaults to `False`. - **slim** (bool, optional) - Disables performance-heavy evasions when injecting the fingerprint. Defaults to `False`. - **header_kwargs** - Additional header generation options for `HeaderGenerator.generate`. ### Request Example ```python from browserforge.fingerprints import FingerprintGenerator fingerprints = FingerprintGenerator() generated_data = fingerprints.generate() # You can also override parameters during generation # from browserforge.fingerprints import Screen # screen_constraints = Screen(width=800, height=600) # generated_data = fingerprints.generate(screen=screen_constraints, slim=True) ``` ### Response #### Success Response (200) Returns a `Fingerprint` object containing detailed browser fingerprint information, including screen, navigator, and other properties. It also includes a list of generated headers. #### Response Example ```json { "screen": { "availHeight": 784, "availWidth": 1440, "availTop": 25, "availLeft": 0, "colorDepth": 30, "height": 900, "pixelDepth": 30, "width": 1440, "devicePixelRatio": 2, "pageXOffset": 0, "pageYOffset": 0, "innerHeight": 0, "outerHeight": 718, "outerWidth": 1440, "innerWidth": 0, "screenX": 0, "clientWidth": 0, "clientHeight": 19, "hasHDR": true }, "navigator": { "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36", "userAgentData": { "architecture": "arm", "bitness": "64", "brands": [ {"brand": "Not A(Brand", "version": "99"}, {"brand": "Google Chrome", "version": "121"}, {"brand": "Chromium", "version": "121"} ], "fullVersionList": [ {"brand": "Not A(Brand", "version": "99.0.0.0"}, {"brand": "Google Chrome", "version": "121.0.6167.160"}, {"brand": "Chromium", "version": "121.0.6167.160"} ], "mobile": false, "model": "", "platform": "macOS" } } // ... other fingerprint properties and headers } ``` ``` -------------------------------- ### Create New Pyppeteer Page with Fingerprint Source: https://github.com/daijro/browserforge/blob/main/README.md Use NewPage to create a Pyppeteer browser page with an injected fingerprint. Replace browser.newPage with NewPage in your existing Pyppeteer code. ```python from browserforge.injectors.pyppeteer import NewPage from pyppeteer import launch async def test(): browser = await launch() # Create a new page with the injected fingerprint page = await NewPage(browser, fingerprint=fingerprint) ... ``` -------------------------------- ### Create New Playwright Context with Fingerprint Source: https://github.com/daijro/browserforge/blob/main/README.md Use NewContext to create a Playwright browser context with an injected fingerprint. Replace browser.new_context with NewContext in your existing Playwright code. ```python from browserforge.injectors.playwright import NewContext def main(): with sync_playwright() as playwright: browser = playwright.chromium.launch() # Create a new context with the injected fingerprint context = NewContext(browser, fingerprint=fingerprint) page = context.new_page() ... ``` -------------------------------- ### FingerprintGenerator.generate Parameters Source: https://github.com/daijro/browserforge/blob/main/README.md Configuration options available when calling the generate method to override default settings. ```text Generates a fingerprint and a matching set of ordered headers using a combination of the default options specified in the constructor and their possible overrides provided here. Parameters: screen (Screen, optional): Screen constraints for the generated fingerprint. strict (bool, optional): Whether to raise an exception if the constraints are too strict. mock_webrtc (bool, optional): Whether to mock WebRTC when injecting the fingerprint. Default is False. slim (bool, optional): Disables performance-heavy evasions when injecting the fingerprint. Default is False. **header_kwargs: Additional header generation options for HeaderGenerator.generate ``` -------------------------------- ### Undetected-Playwright Injection Source: https://context7.com/daijro/browserforge/llms.txt Supports fingerprint injection for Undetected-Playwright using both sync and async context creation. ```python import asyncio from undetected_playwright.async_api import async_playwright from browserforge.injectors.undetected_playwright import AsyncNewContext, NewContext from browserforge.fingerprints import FingerprintGenerator # Async usage async def async_example(): fingerprint = FingerprintGenerator().generate() async with async_playwright() as playwright: browser = await playwright.chromium.launch() context = await AsyncNewContext(browser, fingerprint=fingerprint) page = await context.new_page() await page.goto('https://example.com') await browser.close() ``` -------------------------------- ### Inject Fingerprints into Playwright Source: https://context7.com/daijro/browserforge/llms.txt Configure a Playwright browser context with an injected fingerprint using the synchronous API. ```python from playwright.sync_api import sync_playwright from browserforge.injectors.playwright import NewContext from browserforge.fingerprints import FingerprintGenerator ``` -------------------------------- ### HeaderGenerator.generate Source: https://github.com/daijro/browserforge/blob/main/README.md Generates a set of HTTP headers based on the initial configuration or provided overrides. ```APIDOC ## HeaderGenerator.generate ### Description Generates headers using the default options set in the constructor, with optional runtime overrides. ### Parameters #### Request Body - **browser** (Iterable[Union[str, Browser]]) - Optional - Browser(s) to generate the headers for. - **os** (ListOrString) - Optional - Operating system(s) to generate the headers for. - **device** (ListOrString) - Optional - Device(s) to generate the headers for. - **locale** (ListOrString) - Optional - Language(s) to include in the Accept-Language header. - **http_version** (Literal[1, 2]) - Optional - HTTP version to be used. - **user_agent** (ListOrString) - Optional - User-Agent(s) to use. - **request_dependent_headers** (Dict[str, str]) - Optional - Known values of request-dependent headers. - **strict** (bool) - Optional - If true, throws an error if it cannot generate headers. ``` -------------------------------- ### Playwright Sync Injection Source: https://context7.com/daijro/browserforge/llms.txt Injects fingerprints into standard Playwright browser contexts using the NewContext function. ```python # Generate a fingerprint first (optional - auto-generated if not provided) fingerprint = FingerprintGenerator().generate() def main(): with sync_playwright() as playwright: browser = playwright.chromium.launch(headless=False) # Create context with injected fingerprint context = NewContext(browser, fingerprint=fingerprint) # Or auto-generate with options context = NewContext( browser, fingerprint_options={'browser': 'chrome', 'os': 'windows'} ) # Pass additional Playwright context options context = NewContext( browser, fingerprint=fingerprint, viewport={'width': 1920, 'height': 1080}, locale='en-US', timezone_id='America/New_York' ) page = context.new_page() page.goto('https://example.com') # Fingerprint is automatically injected user_agent = page.evaluate('navigator.userAgent') screen_width = page.evaluate('screen.width') browser.close() main() ``` -------------------------------- ### Pyppeteer Injection Source: https://context7.com/daijro/browserforge/llms.txt Injects fingerprints into Pyppeteer pages using the NewPage function to configure browser properties. ```python import asyncio from pyppeteer import launch from browserforge.injectors.pyppeteer import NewPage from browserforge.fingerprints import FingerprintGenerator async def main(): fingerprint = FingerprintGenerator().generate() browser = await launch(headless=False) # Create page with injected fingerprint page = await NewPage(browser, fingerprint=fingerprint) # Or auto-generate fingerprint with options page = await NewPage( browser, fingerprint_options={ 'browser': 'chrome', 'os': 'windows', 'device': 'desktop' } ) await page.goto('https://example.com') # Verify fingerprint properties user_agent = await page.evaluate('navigator.userAgent') screen_width = await page.evaluate('screen.width') hardware_concurrency = await page.evaluate('navigator.hardwareConcurrency') print(f"User-Agent: {user_agent}") print(f"Screen Width: {screen_width}") print(f"Hardware Concurrency: {hardware_concurrency}") await browser.close() asyncio.run(main()) ``` -------------------------------- ### Playwright Async Injection Source: https://context7.com/daijro/browserforge/llms.txt Uses AsyncNewContext for fingerprint injection within asynchronous Playwright workflows. ```python import asyncio from playwright.async_api import async_playwright from browserforge.injectors.playwright import AsyncNewContext from browserforge.fingerprints import FingerprintGenerator async def main(): fingerprint = FingerprintGenerator().generate() async with async_playwright() as playwright: browser = await playwright.chromium.launch(headless=False) # Create async context with injected fingerprint context = await AsyncNewContext(browser, fingerprint=fingerprint) # Auto-generate fingerprint with constraints context = await AsyncNewContext( browser, fingerprint_options={ 'browser': 'chrome', 'os': 'macos', 'device': 'desktop' } ) page = await context.new_page() await page.goto('https://example.com') # Verify fingerprint injection ua = await page.evaluate('navigator.userAgent') webdriver = await page.evaluate('navigator.webdriver') print(f"User-Agent: {ua}") print(f"Webdriver: {webdriver}") # Should be False await browser.close() asyncio.run(main()) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.