DEV Community

Cover image for How Playwright Gets Detected (and How to Bypass It)
SURFSKY
SURFSKY

Posted on Edited on

How Playwright Gets Detected (and How to Bypass It)

Detecting Playwright Bots and __playwright_mark_target__ Event

A practical experiment to understand one of the browser automation signals that stealth patches can miss

If you're using Playwright for web scraping or browser automation, you probably already know about:

  • navigator.webdriver
  • Headless Chromium detection
  • Browser fingerprinting
  • WebDriver-related signals

But there's another signal worth investigating:

__playwright_mark_target__

It's a custom event dispatched by Playwright's injected scripts when certain elements are marked before interactions and reads.

A page can listen for it.

Let's reproduce it.

1. Create an event listener

The easiest way to observe the event is to register a listener before Playwright interacts with the page.

Run this JavaScript in a test page:

document.addEventListener(
  "__playwright_mark_target__",
  (event) => {
    console.log(
      "Playwright marked:",
      event.target.tagName
    );
  },
  true
);
Enter fullscreen mode Exit fullscreen mode

The third argument enables capture mode.

Now perform a few standard Playwright operations.

2. Test common Playwright methods

We reproduced the behavior using Playwright Python 1.56 and headless Chromium 141, with tracing disabled.

These four operations all triggered the marker event:

await page.locator(".price").inner_text()

await page.locator("#next").click()

await page.locator("#search").fill("hello world")

await page.locator(".price").text_content()
Enter fullscreen mode Exit fullscreen mode

The results:

Method Event fired
inner_text() Yes
click() Yes
fill() Yes
text_content() Yes

You can observe the event target through the JavaScript listener.

For example, reading .price marks a paragraph element, while clicking #next marks a button.

Important: These are our reproduction results, not a guarantee that every Playwright version, browser configuration, or website will behave identically.

3. Why does this matter for web scraping?

Imagine a scraper with the following workflow:

  1. Open a product page.
  2. Read the price using inner_text().
  3. Click the next product.
  4. Repeat.

The page may be able to observe automation-related behavior before the scraper has even finished collecting its data.

In one real-world case we investigated, a scraping session opened the first product page successfully but received a HUMAN "press and hold" challenge on the next page.

The same browser and proxy worked when we operated the browser without Playwright.

Investigating the site's anti-bot script led us to the marker event.

4. Why don't common stealth patches necessarily remove it?

Consider two different detection surfaces:

Browser properties

  • navigator.webdriver
  • User-Agent
  • Browser fingerprint

Automation behavior

  • Injected scripts
  • Custom events
  • Input behavior
  • Automation-specific page interactions

A stealth plugin can modify browser properties without eliminating signals produced by the automation driver itself.

In our test with playwright-stealth 2.0.3, navigator.webdriver became false, but inner_text() still triggered the marker event.

We also inspected Patchright's implementation at its October 25, 2026 commit. The marker event was still present in the code we reviewed.

This is an important distinction: hiding one fingerprint doesn't automatically remove every automation signal.

5. What about CDP and remote browsers?

Moving Playwright to a remote or cloud browser doesn't automatically remove the event.

We tested Playwright connecting to a remote browser over CDP, and inner_text() still triggered the marker event.

The reason is straightforward: the signal comes from Playwright's injected scripts, not simply from where Chromium is running.

A different infrastructure provider alone isn't necessarily a solution.

6. An alternative: browser-native automation

After repeatedly patching individual Playwright detection signals, we decided to build a different approach at Surfsky.

Our Python and TypeScript SDKs communicate directly with the browser over CDP without installing Playwright's injected helper scripts.

They also provide:

  • Proxy configuration
  • Browser fingerprint management
  • Human-like cursor movement and typing
  • Browser lifecycle management
  • Parallel execution

The Python API looks familiar:

async with AsyncSurfsky() as client:
    async with client.browser(
        proxy=PremiumProxy(country="us")
    ) as browser:
        await browser.goto(
            "https://example.com/product/1"
        )

        price = await browser.inner_text(".price")

        await browser.click("a.next-product")

        print(price)
Enter fullscreen mode Exit fullscreen mode

This eliminates the specific Playwright helper-script signals discussed in this tutorial. It is not a promise of universal bypass against every anti-bot system.

7. When should you reconsider your Playwright setup?

I'd investigate another automation architecture when:

  • Sessions get challenged despite stable proxies.
  • Your stealth configuration keeps growing.
  • Browser updates repeatedly break custom patches.
  • You need production scraping across multiple sites.
  • You want browser control, proxy configuration, and human-like input in one stack.

For ordinary browser testing, Playwright is still a great choice.

But when automation detection becomes the bottleneck, it's worth examining the driver itself.

Further reading

We documented the complete investigation, including the event reproduction, other detection signals, stealth plugin tests, and our alternative SDK architecture:

Read full article and test your browser stack with $5 in credit:

We Got Tired of Patching Playwright, So We Wrote Our Own SDK

You can also explore the Surfsky SDK:

What other Playwright detection signals have you encountered in production?

Top comments (0)