playwright-with-fingerprints

repository·master·Indexed 43 days ago

https://github.com/bablosoft/playwright-with-fingerprints

A Windows-only plugin for the Playwright framework that integrates with the FingerprintSwitcher service to enhance browser anonymity by replacing hardware and software fingerprints. Version 2.3.5 supports engine version 146.0.7680.80 and provides methods to fetch, apply, and manage fingerprints, proxies, and browser profiles to improve stealth and bypass anti-bot systems.

Tokens
6.8K
Snippets
23
Records
32
Agent score
55%

What's inside playwright-with-fingerprints

  1. Limitations of playwright-with-fingerprints

    master

    When using this plugin, be aware of the following restrictions:

    • Operating System: Only Windows is supported.
    • Browser Engine: Only the bundled Chrome browser can be used. You cannot change the executable path or use other engines.
    • Concurrency: Parallel browser launches are synchronized between calls.
    • Workers: If using Playwright workers, you must specify a separate working folder for each worker to avoid conflicts.
  2. Configure browser fingerprint, proxy, and profile

    master

    To change the browser's fingerprint, proxy, or profile, use the following dedicated methods. These methods must be called before using the launch or spawn methods, as they only affect the next browser launch and cannot be changed once the browser is running.

    • useProxy(proxy, options): Configures the proxy settings.
    • useProfile(path, options): Configures the browser profile path and loading behavior.
    • useFingerprint(fingerprint, options): Configures the browser fingerprint.

    These methods return the current plugin instance, allowing you to chain calls.

    const { plugin } = require('playwright-with-fingerprints');
    
    plugin.setServiceKey('');
    const fingerprint = await plugin.fetch({
      tags: ['Microsoft Windows', 'Chrome'],
    });
    
    // Chaining configuration methods before launch
    plugin.useProxy('127.0.0.1:8080').useFingerprint(fingerprint);
    
    await plugin.launch();
  3. How the fingerprint substitution architecture works

    master

    The playwright-with-fingerprints plugin uses the FingerprintSwitcher service to retrieve fingerprints collected from real devices. These fingerprints are applied to the browser using custom configuration files and a custom-patched browser.

    Key Architectural Details:

    • Custom Browser: To ensure correct fingerprint substitution, the plugin uses a custom-patched Chrome browser. This browser is downloaded and installed automatically the first time API methods are called.
    • Engine Limitation: You cannot use standard engines or other browsers (like Chromium or Firefox). The plugin is locked to the bundled Chrome executable.
    • OS Requirement: This package only works on Windows. It relies on Windows-only dependencies and will error on other platforms.
    • Fingerprint Source: Fingerprints are downloaded from a service rather than being generated locally, which improves anonymity and property substitution quality.
  4. Explore usage examples for playwright-with-fingerprints

    master

    The repository provides several example files demonstrating different use cases for the plugin:

    • Profiles: See profiles.js for using profiles in conjunction with the plugin.
    • Proxies: See proxy.js for launching a browser with a proxy and additional settings to obtain an external IP.
    • Multithreading: See multithreading.js for running multiple browsers simultaneously to extract data.
    • Stealth/Anti-bot: See stealth.js to verify fingerprint replacement on sites with anti-bot systems and capture screenshots.
    • Sequential Browsers: See multiple.js for launching multiple browsers sequentially with different fingerprints to collect header and viewport data.
  5. Install playwright-with-fingerprints

    master

    To use this plugin, install it via your preferred package manager. You must also have either playwright or playwright-core installed in your project.

    Important Requirements:

    • Operating System: This plugin only works on Windows. It cannot be used on Linux, macOS, or other systems.
    • Compatibility: The plugin works with the default playwright library. Unofficial wrappers are not tested and may cause errors.
    • Engine Version: The current supported engine version is 146.0.7680.80.
    npm i playwright-with-fingerprints
    # or
    pnpm i playwright-with-fingerprints
    # or
    yarn add playwright-with-fingerprints
    
    # Ensure playwright is also installed
    npm i playwright
  6. Migrate an existing Playwright project to use fingerprints

    master

    To migrate an existing Playwright project to use fingerprints, perform the following modifications:

    1. Change the import: Replace require('playwright') or require('playwright-core') with const { plugin } = require('playwright-with-fingerprints');.
    2. Configure the service: Call plugin.setServiceKey('') to set your API key.
    3. Fetch and apply identity: Before launching the browser, call await plugin.fetch({ tags: [...] }) to get a fingerprint and then call plugin.useFingerprint(fingerprint).
    4. Update the launch call: Replace your existing browser launch call (e.g., await chromium.launch()) with await plugin.launch().

    The rest of your automation logic (creating pages, navigating, interacting with elements) remains unchanged as plugin.launch() returns a standard Playwright Browser object.

    /* Before: Standard Playwright */
    const { chromium } = require('playwright');
    const browser = await chromium.launch();
    
    /* After: With Fingerprints */
    const { plugin } = require('playwright-with-fingerprints');
    plugin.setServiceKey('');
    
    (async () => {
      const fingerprint = await plugin.fetch({
        tags: ['Microsoft Windows', 'Chrome'],
      });
      plugin.useFingerprint(fingerprint);
      
      // Replace chromium.launch() with plugin.launch()
      const browser = await plugin.launch();
    
      const page = await browser.newPage();
      await page.goto('https://example.com');
      await browser.close();
    })();
  7. Fetch and use fingerprints with fetch

    master

    To obtain a fingerprint, use the fetch method. This requires a service key (set via setServiceKey).

    Free Version Limitations:

    • You can only use default tags.
    • You cannot use certain filters like minBrowserVersion or maxBrowserVersion.
    • PerfectCanvas technology is unavailable.
    • Request limits apply.

    Fetch Options:

    • tags: Array of strings (e.g., ['Microsoft Windows', 'Chrome']). Custom tags require a premium key.
    • minBrowserVersion: Minimum version number.
    • maxBrowserVersion: Maximum version number.
    • timeLimit: Filter by how recently the fingerprint was collected (e.g., '15 days').
    • current: A special value to filter fingerprints by the version currently installed in the plugin.

    Fingerprint Reuse: You can save a fingerprint to a file or database and reload it later using useFingerprint to avoid repeated API calls.

    const { readFile, writeFile } = require('fs/promises');
    const { plugin } = require('playwright-with-fingerprints');
    
    plugin.setServiceKey('');
    
    // 1. Fetch and Save
    const fingerprint = await plugin.fetch({
      tags: ['Microsoft Windows', 'Chrome'],
      minBrowserVersion: 130,
      maxBrowserVersion: 132,
      timeLimit: '15 days',
    });
    await writeFile('fingerprint.json', fingerprint);
    
    // 2. Load and Use
    const savedFingerprint = await readFile('fingerprint.json', 'utf8');
    plugin.useFingerprint(savedFingerprint);
    
    await plugin.launch();
  8. Create a new project with fingerprints

    master

    To start a new project using fingerprints, follow these steps:

    1. Import plugin from playwright-with-fingerprints.
    2. Set your service key using plugin.setServiceKey('') (use an empty string for the free version).
    3. Fetch a fingerprint from the server using plugin.fetch({ tags: [...] }).
    4. Apply the fingerprint using plugin.useFingerprint(fingerprint).
    5. Launch the browser using plugin.launch().

    Note: The plugin.launch() method accepts the same parameters as the standard Playwright browserType.launch() method and returns a standard Playwright Browser instance.

    const { plugin } = require('playwright-with-fingerprints');
    
    // Set the service key (empty string for free version)
    plugin.setServiceKey('');
    
    (async () => {
      // 1. Get a fingerprint from the server
      const fingerprint = await plugin.fetch({
        tags: ['Microsoft Windows', 'Chrome'],
      });
    
      // 2. Apply fingerprint
      plugin.useFingerprint(fingerprint);
    
      // 3. Launch the browser instance
      const browser = await plugin.launch();
    
      // 4. Use standard Playwright API
      const page = await browser.newPage();
      await page.goto('https://example.com');
    
      await browser.close();
    })();
  9. Configure fingerprint service key and proxy via environment variables

    master

    You can configure the fingerprint service key and proxy settings using environment variables. This is useful for keeping credentials out of your source code. You can set these variables directly in your shell or within a .env file.

    Supported environment variables:

    • FINGERPRINT_KEY: Your fingerprint service key.
    • FINGERPRINT_PROXY: The proxy URL (e.g., using the socks5:// protocol).
    FINGERPRINT_KEY="SERVICE_KEY"
    FINGERPRINT_PROXY="socks5://127.0.0.1:9762"
  10. Configure global plugin settings

    master

    You can configure global settings for the plugin instance. These settings affect all plugin methods and all instances of the plugin.

    Available configuration methods:

    • setServiceKey(key): Sets the fingerprint service key. An empty string (default) uses the free version of the service.
    • setWorkingFolder(path): Sets the directory where the plugin engine is installed. Defaults to ./data.
    • setRequestTimeout(ms): Sets the timeout for requests to the engine (e.g., fetching fingerprints). Defaults to 300000 ms.
    • setEngineTimeout(ms): Sets the timeout for installing or downloading the engine.
    // Set the fingerprint service key for all plugin methods that require it.
    plugin.setServiceKey('SERVICE_KEY');
    
    // Set the folder where the plugin engine will be installed:
    plugin.setWorkingFolder('./engine');
    
    // Set the timeout used when fetching fingerprints and so on:
    plugin.setRequestTimeout(5 * 60000);
    
    // Set the timeout used when installing/downloading engine:
    plugin.setEngineTimeout(10 * 60000);
  11. Configure fingerprint storage and timeout via environment variables

    master

    You can customize the behavior of the fingerprint engine using environment variables. These variables are read from .env files by default using the dotenv library.

    • FINGERPRINT_CWD: Specifies the directory where the engine will be stored. Use this to change the default storage location.
    • FINGERPRINT_TIMEOUT: Sets the timeout (in milliseconds) for executing engine methods, such as applying or fetching a fingerprint. This is useful if fingerprint operations are taking longer than the default allowed time.
    # Example configuration in a .env file
    FINGERPRINT_CWD="../plugin-engine"
    FINGERPRINT_TIMEOUT=300000