playwright-bot-bypass
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePlaywright 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 Point | Standard Playwright | This Solution |
|---|---|---|
| WebDriver property | | Removed |
| WebGL Renderer | SwiftShader (software) | Real GPU (Apple M2, etc.) |
| User Agent | Contains "HeadlessChrome" | Clean Chrome UA |
| Chrome runtime | Missing properties | Complete chrome.runtime |
标准Playwright/Puppeteer会暴露多个自动化特征:
| 检测点 | 标准Playwright | 本解决方案 |
|---|---|---|
| WebDriver属性 | | 已移除 |
| WebGL渲染器 | SwiftShader(软件渲染) | 真实GPU(如Apple M2等) |
| 用户代理(User Agent) | 包含"HeadlessChrome" | 纯净Chrome UA |
| Chrome运行时 | 缺少属性 | 完整chrome.runtime |
Quick Start
快速开始
1. Install Dependencies
1. 安装依赖
bash
npm install rebrowser-playwrightbash
npm install rebrowser-playwright2. 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 property is the most common detection method:
navigator.webdriverjavascript
await context.addInitScript(() => {
delete Object.getPrototypeOf(navigator).webdriver;
});navigator.webdriverjavascript
await context.addInitScript(() => {
delete Object.getPrototypeOf(navigator).webdriver;
});Real Chrome Browser
真实Chrome浏览器
Always use to launch the user's installed Chrome:
channel: 'chrome'javascript
chromium.launch({
headless: false,
channel: 'chrome'
});务必设置以启动用户已安装的Chrome:
channel: 'chrome'javascript
chromium.launch({
headless: false,
channel: 'chrome'
});Complete Example
完整示例
See for a complete working example that:
examples/stealth-google-search.mjs- Bypasses bot detection
- Performs Google search
- Captures results
查看获取完整可运行示例,该示例可:
examples/stealth-google-search.mjs- 绕过机器人检测
- 执行Google搜索
- 捕获搜索结果
Testing Bot Detection
机器人检测测试
Verify bypass effectiveness at https://bot.sannysoft.com:
bash
node scripts/bot-detection-test.mjsAll items should show green (passed).
Scripts
脚本说明
- - Test bot detection status
scripts/bot-detection-test.mjs - - Reusable stealth browser template
scripts/stealth-template.mjs
- - 测试机器人检测状态
scripts/bot-detection-test.mjs - - 可复用的隐身浏览器模板
scripts/stealth-template.mjs
Examples
示例列表
- - Google search without CAPTCHA
examples/stealth-google-search.mjs - - Compare detected vs stealth side-by-side
examples/ab-test.mjs
- - 无CAPTCHA的Google搜索
examples/stealth-google-search.mjs - - 对比被检测与隐身模式的差异
examples/ab-test.mjs
Limitations
局限性
- Requires (headed mode)
headless: false - 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 cannot fully bypass bot detection.
playwright-stealth| Environment | bot.sannysoft.com | Google Search |
|---|---|---|
| Node.js rebrowser-playwright | ✅ Pass | ✅ Works |
| Python playwright-stealth | ✅ Pass | ❌ CAPTCHA |
Why?
- : Chromium binary-level patch → uses real GPU
rebrowser-playwright - : JavaScript-level patch only → SwiftShader exposed
playwright-stealth
Python版无法完全绕过机器人检测。
playwright-stealth| 环境 | bot.sannysoft.com | Google搜索 |
|---|---|---|
| Node.js rebrowser-playwright | ✅ 通过 | ✅ 可用 |
| Python playwright-stealth | ✅ 通过 | ❌ 触发CAPTCHA |
原因?
- :Chromium二进制层面补丁 → 使用真实GPU
rebrowser-playwright - :仅JavaScript层面补丁 → 暴露SwiftShader
playwright-stealth
undetected-chromedriver (Recommended for Python)
undetected-chromedriver(Python推荐方案)
undetected-chromedriver| Library | bot.sannysoft.com | Google Search |
|---|---|---|
| playwright-stealth | ✅ Pass | ❌ CAPTCHA |
| undetected-chromedriver | ✅ Pass | ✅ Works! |
undetected-chromedriver| 库 | bot.sannysoft.com | Google搜索 |
|---|---|---|
| playwright-stealth | ✅ 通过 | ❌ 触发CAPTCHA |
| undetected-chromedriver | ✅ 通过 | ✅ 可用! |
Installation
安装
bash
pip install undetected-chromedriverbash
pip install undetected-chromedriverUsage
使用示例
python
import undetected_chromedriver as ucpython
import undetected_chromedriver as ucSpecify 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()
undefineddriver = 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()
undefinedKey Points
核心要点
- Uses Selenium WebDriver API (not Playwright)
- Automatically patches ChromeDriver to avoid detection
- Requires specifying matching your Chrome version
version_main - 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?
仍被检测到?
- Ensure using , not
rebrowser-playwrightplaywright - Verify is set
channel: 'chrome' - Check runs before navigation
addInitScript - Try adding delays between actions (human-like behavior)
- 确保使用的是而非
rebrowser-playwrightplaywright - 确认已设置
channel: 'chrome' - 检查是否在导航前运行
addInitScript - 尝试在操作之间添加延迟(模拟人类行为)
Browser Not Opening?
浏览器无法打开?
bash
undefinedbash
undefinedVerify Chrome is installed
验证Chrome是否已安装
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --version
undefined/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --version
undefinedWebGL Still Shows SwiftShader?
WebGL仍显示SwiftShader?
This happens with regular playwright. Confirm import is from :
rebrowser-playwrightjavascript
// Correct
import { chromium } from 'rebrowser-playwright';
// Wrong - will be detected
import { chromium } from 'playwright';这种情况会在使用常规playwright时发生。确认导入的是:
rebrowser-playwrightjavascript
// 正确
import { chromium } from 'rebrowser-playwright';
// 错误 - 会被检测到
import { chromium } from 'playwright';