playwright-bot-bypass

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Playwright Bot Bypass

Playwright 机器人检测绕过方案

Bypass bot detection systems using rebrowser-playwright with stealth techniques. This approach successfully passes bot detection tests like bot.sannysoft.com and enables automation on sites with aggressive bot protection (Google, Cloudflare, etc.).
使用rebrowser-playwright结合隐身技术绕过机器人检测系统。该方案可成功通过bot.sannysoft.com等机器人检测测试,还能在带有严格机器人防护的网站(如Google、Cloudflare等)上实现自动化操作。

Why Standard Playwright Gets Detected

为什么标准Playwright会被检测到

Standard Playwright/Puppeteer exposes several automation signatures:
Detection PointStandard PlaywrightThis Solution
WebDriver property
navigator.webdriver = true
Removed
WebGL RendererSwiftShader (software)Real GPU (Apple M2, etc.)
User AgentContains "HeadlessChrome"Clean Chrome UA
Chrome runtimeMissing propertiesComplete chrome.runtime
标准Playwright/Puppeteer会暴露多个自动化特征:
检测点标准Playwright本解决方案
WebDriver属性
navigator.webdriver = true
已移除
WebGL渲染器SwiftShader(软件渲染)真实GPU(如Apple M2等)
用户代理(User Agent)包含"HeadlessChrome"纯净Chrome UA
Chrome运行时缺少属性完整chrome.runtime

Quick Start

快速开始

1. Install Dependencies

1. 安装依赖

bash
npm install rebrowser-playwright
bash
npm install rebrowser-playwright

2. Basic Stealth Script

2. 基础隐身脚本

javascript
import { chromium } from 'rebrowser-playwright';

const browser = await chromium.launch({
  headless: false,
  channel: 'chrome'  // Use real Chrome browser
});

const context = await browser.newContext();

// Remove WebDriver property
await context.addInitScript(() => {
  delete Object.getPrototypeOf(navigator).webdriver;
});

const page = await context.newPage();
await page.goto('https://example.com');
javascript
import { chromium } from 'rebrowser-playwright';

const browser = await chromium.launch({
  headless: false,
  channel: 'chrome'  // 使用真实Chrome浏览器
});

const context = await browser.newContext();

// 移除WebDriver属性
await context.addInitScript(() => {
  delete Object.getPrototypeOf(navigator).webdriver;
});

const page = await context.newPage();
await page.goto('https://example.com');

Key Components

核心组件

rebrowser-playwright

rebrowser-playwright

Drop-in replacement for playwright that patches automation detection:
  • Uses real GPU instead of SwiftShader
  • Removes HeadlessChrome from User Agent
  • Patches various fingerprinting vectors
可直接替代playwright的工具,用于修补自动化检测相关问题:
  • 使用真实GPU而非SwiftShader
  • 从用户代理中移除HeadlessChrome标识
  • 修补多种指纹识别向量

addInitScript for WebDriver

用于WebDriver的addInitScript

The
navigator.webdriver
property is the most common detection method:
javascript
await context.addInitScript(() => {
  delete Object.getPrototypeOf(navigator).webdriver;
});
navigator.webdriver
属性是最常见的检测手段:
javascript
await context.addInitScript(() => {
  delete Object.getPrototypeOf(navigator).webdriver;
});

Real Chrome Browser

真实Chrome浏览器

Always use
channel: 'chrome'
to launch the user's installed Chrome:
javascript
chromium.launch({
  headless: false,
  channel: 'chrome'
});
务必设置
channel: 'chrome'
以启动用户已安装的Chrome:
javascript
chromium.launch({
  headless: false,
  channel: 'chrome'
});

Complete Example

完整示例

See
examples/stealth-google-search.mjs
for a complete working example that:
  1. Bypasses bot detection
  2. Performs Google search
  3. Captures results
查看
examples/stealth-google-search.mjs
获取完整可运行示例,该示例可:
  1. 绕过机器人检测
  2. 执行Google搜索
  3. 捕获搜索结果

Testing Bot Detection

机器人检测测试

Verify bypass effectiveness at https://bot.sannysoft.com:
bash
node scripts/bot-detection-test.mjs
All items should show green (passed).
bash
node scripts/bot-detection-test.mjs
所有项目均应显示绿色(通过)。

Scripts

脚本说明

  • scripts/bot-detection-test.mjs
    - Test bot detection status
  • scripts/stealth-template.mjs
    - Reusable stealth browser template
  • scripts/bot-detection-test.mjs
    - 测试机器人检测状态
  • scripts/stealth-template.mjs
    - 可复用的隐身浏览器模板

Examples

示例列表

  • examples/stealth-google-search.mjs
    - Google search without CAPTCHA
  • examples/ab-test.mjs
    - Compare detected vs stealth side-by-side
  • examples/stealth-google-search.mjs
    - 无CAPTCHA的Google搜索
  • examples/ab-test.mjs
    - 对比被检测与隐身模式的差异

Limitations

局限性

  • Requires
    headless: false
    (headed mode)
  • Needs real Chrome installed (
    channel: 'chrome'
    )
  • Some sites may still detect based on behavior patterns
  • Does not bypass CAPTCHAs, only prevents triggering them
  • 要求使用
    headless: false
    (有头模式)
  • 需要安装真实Chrome浏览器(设置
    channel: 'chrome'
  • 部分网站仍可能通过行为模式检测到
  • 无法绕过CAPTCHA,仅能避免触发CAPTCHA

Python Support

Python支持

playwright-stealth (Limited)

playwright-stealth(功能有限)

Python
playwright-stealth
cannot fully bypass bot detection.
Environmentbot.sannysoft.comGoogle Search
Node.js rebrowser-playwright✅ Pass✅ Works
Python playwright-stealth✅ Pass❌ CAPTCHA
Why?
  • rebrowser-playwright
    : Chromium binary-level patch → uses real GPU
  • playwright-stealth
    : JavaScript-level patch only → SwiftShader exposed
Python版
playwright-stealth
无法完全绕过机器人检测。
环境bot.sannysoft.comGoogle搜索
Node.js rebrowser-playwright✅ 通过✅ 可用
Python playwright-stealth✅ 通过❌ 触发CAPTCHA
原因?
  • rebrowser-playwright
    :Chromium二进制层面补丁 → 使用真实GPU
  • playwright-stealth
    :仅JavaScript层面补丁 → 暴露SwiftShader

undetected-chromedriver (Recommended for Python)

undetected-chromedriver(Python推荐方案)

undetected-chromedriver
fully bypasses bot detection in Python!
Librarybot.sannysoft.comGoogle Search
playwright-stealth✅ Pass❌ CAPTCHA
undetected-chromedriver✅ PassWorks!
undetected-chromedriver
可在Python中完全绕过机器人检测!
bot.sannysoft.comGoogle搜索
playwright-stealth✅ 通过❌ 触发CAPTCHA
undetected-chromedriver✅ 通过可用!

Installation

安装

bash
pip install undetected-chromedriver
bash
pip install undetected-chromedriver

Usage

使用示例

python
import undetected_chromedriver as uc
python
import undetected_chromedriver as uc

Specify your Chrome version

指定你的Chrome版本

driver = uc.Chrome(version_main=144)
driver.get("https://www.google.com") search_box = driver.find_element("name", "q") search_box.send_keys("your search query") search_box.submit()
undefined
driver = uc.Chrome(version_main=144)
driver.get("https://www.google.com") search_box = driver.find_element("name", "q") search_box.send_keys("your search query") search_box.submit()
undefined

Key Points

核心要点

  • Uses Selenium WebDriver API (not Playwright)
  • Automatically patches ChromeDriver to avoid detection
  • Requires specifying
    version_main
    matching your Chrome version
  • Check Chrome version:
    chrome://version
  • 使用Selenium WebDriver API(非Playwright)
  • 自动修补ChromeDriver以避免被检测
  • 需要指定与你的Chrome版本匹配的
    version_main
  • 查看Chrome版本:
    chrome://version

Alternative: Subprocess

替代方案:子进程调用

For Electron/Node.js apps, call Node.js script from Python:
python
import subprocess
result = subprocess.run(['node', 'stealth-script.mjs', query], capture_output=True)
对于Electron/Node.js应用,可从Python中调用Node.js脚本:
python
import subprocess
result = subprocess.run(['node', 'stealth-script.mjs', query], capture_output=True)

Troubleshooting

故障排查

Still Getting Detected?

仍被检测到?

  1. Ensure using
    rebrowser-playwright
    , not
    playwright
  2. Verify
    channel: 'chrome'
    is set
  3. Check
    addInitScript
    runs before navigation
  4. Try adding delays between actions (human-like behavior)
  1. 确保使用的是
    rebrowser-playwright
    而非
    playwright
  2. 确认已设置
    channel: 'chrome'
  3. 检查
    addInitScript
    是否在导航前运行
  4. 尝试在操作之间添加延迟(模拟人类行为)

Browser Not Opening?

浏览器无法打开?

bash
undefined
bash
undefined

Verify Chrome is installed

验证Chrome是否已安装

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --version
undefined
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --version
undefined

WebGL Still Shows SwiftShader?

WebGL仍显示SwiftShader?

This happens with regular playwright. Confirm import is from
rebrowser-playwright
:
javascript
// Correct
import { chromium } from 'rebrowser-playwright';

// Wrong - will be detected
import { chromium } from 'playwright';
这种情况会在使用常规playwright时发生。确认导入的是
rebrowser-playwright
javascript
// 正确
import { chromium } from 'rebrowser-playwright';

// 错误 - 会被检测到
import { chromium } from 'playwright';