Patchright NodeJS

repository·main·Indexed 20 days ago

https://github.com/kaliiiiiiiiii-vinyzu/patchright-nodejs

A patched, undetected version of the Playwright framework designed as a drop-in replacement for Chromium-based browsers. It aims to bypass anti-bot protections like Cloudflare, Akamai, and DataDome by modifying command flags, disabling the Console API, and introducing an isolatedContext option for evaluate methods to prevent detection leaks.

Tokens
942
Snippets
5
Records
6
Agent score
23%

What's inside patchright-nodejs

  1. How Patchright handles detection leaks

    main

    Patchright implements several patches to avoid common automation detection methods used by websites:

    • Runtime.enable Leak: Patchright avoids using Runtime.enable by executing JavaScript in (isolated) ExecutionContexts.
    • Console.enable Leak: The Console API is disabled entirely to prevent detection. Note that this means standard console functionality will not work in Patchright.
    • Command Flags Leaks: Patchright modifies Playwright's default arguments. It adds --disable-blink-features=AutomationControlled and removes --enable-automation to prevent navigator.webdriver detection. It also removes flags like --disable-component-update and --disable-extensions to avoid being flagged as a stealth driver.
    • Closed Shadow Roots: Patchright allows you to interact with elements inside Closed Shadow Roots using standard locators and XPaths.
  2. Best Practice: Use Chrome without Fingerprint Injection for maximum stealth

    main

    To achieve the highest level of undetectability, it is recommended to use Google Chrome (instead of Chromium) and avoid adding custom browser headers or userAgent.

    You can install Google Chrome using npx patchright install chrome and then launch it using the channel: 'chrome' option.

    chromium.launchPersistentContext("...", {
        channel: "chrome",
        headless: false,
        viewport: null,
        // do NOT add custom browser headers or userAgent
    });
  3. Use Patchright as a drop-in replacement for Playwright

    main

    Patchright is designed to be a drop-in replacement for Playwright. You can use it by importing chromium from patchright instead of playwright.

    Note: Patchright only supports Chromium-based browsers. Firefox and Webkit are not supported.

    // patchright here!
    const { chromium } = require('patchright');
    
    (async () => {
      const browser = await chromium.launch();
      const page = await browser.newPage();
      await page.goto('http://example.com');
      // other actions...
      await browser.close();
    })();
  4. Extended Patchright API: isolatedContext in evaluate methods

    main

    Patchright extends the standard Playwright evaluate family of methods by adding an isolatedContext option. This allows you to choose whether the JavaScript executes in the Main context or an Isolated context to avoid Runtime.enable detection leaks.

    Supported methods:

    • evaluate (on Frame, Page, Locator, Worker, JSHandle)
    • evaluateHandle (on Frame, Page, Locator, Worker, JSHandle)
    • evaluateAll (on Locator)
    // Example for evaluate
    // object.evaluate(pageFunction, arg, ..., isolatedContext: boolean = true)
    
    // Example for evaluateHandle
    // object.evaluateHandle(pageFunction, arg, ..., isolatedContext: boolean = true)
    
    // Example for evaluateAll
    // Locator.evaluateAll(pageFunction, arg, ..., isolatedContext: boolean = true)