Community编程与开发github.com

shuangying0001-beep/playwright-stealth

Playwright 反检测环境配置(去 webdriver 痕迹):随机 UA/时区/语言、去自动化标志、模拟 Canvas/WebRTC 绕开反爬。适合爬虫、自动化测试。

playwright-stealth 是什么?

playwright-stealth is a Claude Code agent skill that playwright 反检测环境配置(去 webdriver 痕迹):随机 UA/时区/语言、去自动化标志、模拟 Canvas/WebRTC 绕开反爬。适合爬虫、自动化测试。.

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add shuangying0001-beep/playwright-stealth

Installed? Explore more 编程与开发 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

playwright-stealth —— Configure Playwright's Automated Browser Environment

Make Playwright automation session environments look more like real users, reducing exposure of machine characteristics. Extracted from caijiqi-kaifa/electron/collector/stealth.ts. Requires Playwright runtime (browser-side injection depends on page object). Includes a minimal built-in sample of UA/resolution; for production, pair with browser-fingerprint-pool (88+ UA / 87 resolutions).

Compliance Notes

This skill is solely intended to make automated browsers appear closer to real user environments, which is a general browser environment configuration capability. Always comply with the target site's terms of service and applicable laws and regulations. Only use this for compliant automation and testing scenarios.

Use Cases

  • When using Playwright for web automation, scraping, or regression testing and you want a more realistic, stable environment
  • When you need to randomize UA, viewport, language, timezone and keep those features self-consistent (e.g., resolution matches viewport)
  • When you need to fill in Canvas, WebGL, AudioContext, Plugins, Permissions and other browser features to avoid exposing empty or missing characteristics

Usage

import { getRandomBrowserConfig, STEALTH_ARGS, IGNORE_DEFAULT_ARGS,
         injectStealthScripts, createStealthContext }
  from './scripts/stealth.mjs';
import { chromium } from 'playwright';

const browser = await chromium.launch({ args: STEALTH_ARGS, ignoreDefaultArgs: IGNORE_DEFAULT_ARGS });

// Option 1: Directly get a random self-consistent configuration
const cfg = getRandomBrowserConfig('US');
// => { userAgent, viewport:{width,height}, locale, languages, timezoneId }

// Option 2: Create an injected context (recommended)
const { context, config } = await createStealthContext(browser, 'DE');
const page = await context.newPage();
await page.goto('https://example.com');

Core API

  • getRandomBrowserConfig(site): Returns a random self-consistent configuration (UA, viewport, language, timezone) for the given site region (supports US/UK/DE/FR/IT/ES/JP/CA/AU/IN/MX, defaults to US)
  • STEALTH_ARGS: Chromium launch arguments (removes automation related flags, disables background throttling, etc.)
  • IGNORE_DEFAULT_ARGS: Default arguments to ignore (e.g., --enable-automation)
  • injectStealthScripts(page): Injects environment simulation scripts into the page (hides webdriver, simulates plugins/Chrome/Canvas/Audio/WebRTC/Permissions/resolution consistency). Must run inside the browser
  • createStealthContext(browser, site, proxy?): Creates a browser context with environment simulation already injected

Important Notes

  • injectStealthScripts / createStealthContext must be executed within the Playwright browser runtime; purely in Node they cannot be unit tested. You can use getRandomBrowserConfig / STEALTH_ARGS to verify the pure logic.
  • The built-in UA / resolution data is only a minimal sample. For a larger sample, replace the data in RANDOM_UAS / RANDOM_RESOLUTIONS with data from browser-fingerprint-pool.

相关技能