Skip to content

patchright with headless chromium lacks basic anti-detection efforts? #46

Description

@Haskely

When I used patchright along with headless chromium on Ubuntu, I found that it hardly made any efforts to bypass detection...

The code I used is as follows:

from patchright.async_api import async_playwright

async with async_playwright() as p:
    browser = await p.chromium.launch(
        headless=True,
    )
    page = await browser.new_page()
    await page.goto("https://bot.sannysoft.com/")
    await page.wait_for_load_state()
    await page.screenshot(path="screenshot.png")

The result:

Image

In fact, just the "Headless" keyword in the User Agent is enough to make google.com trigger the BOT detection (and I easily bypassed it by simply replacing it), which makes it almost impossible to use in the scenario of running browser user agents in batches on a server without UI infrastructure.

Image

Even if I configure it according to the best practice mentioned in the README, there is still one item that is red:

from patchright.async_api import async_playwright

async with async_playwright() as p:
    browser = await p.chromium.launch_persistent_context(
        headless=False,
        channel="chrome",
        user_data_dir="./user_data",
        no_viewport=True,
        proxy=PROXY,
    )
    ...

Image

In contrast, when simply using https://github.com/Mattwmaster58/playwright_stealth along with headless chromium, all results are green:

# pip install git+https://github.com/Mattwmaster58/playwright_stealth@rc4
from playwright.async_api import async_playwright
from playwright_stealth import Stealth

async with Stealth().use_async(async_playwright()) as p:
    browser = await p.chromium.launch(
        headless=True,
    )
   ...

Image

And there is no need to use xvfb run to start it.

I don't understand why patchright doesn't perform some simple replacements of the uv and other string attributes for headless chromium to bypass some of the most basic detections. This brings some inconvenience to out-of-the-box usage.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions