CommunityCoding & Developmentgithub.com

playwright-stealth

Playwright anti-detection environment configuration (removes webdriver traces): random UA/timezone/language, removes automation flags, simulates Canvas/WebRTC to bypass anti-bot measures. Suitable for scraping and automated testing.

What is playwright-stealth?

Playwright-stealth is a comprehensive browser environment configuration skill for Playwright that makes automated browser sessions appear more like real user sessions, reducing exposure of bot characteristics. It provides randomized yet self-consistent user agent, viewport, language, and timezone configurations, plus injects stealth scripts to hide automation markers like `navigator.webdriver`, simulate browser plugins, Chrome runtime, Canvas/WebRTC fingerprints, and permission states. The skill extracts from production stealth logic and includes a minimal built-in sample of UA/resolution data; for production use, it recommends pairing with a larger fingerprint pool. It supports major platforms like Playwright (Chromium) and is ideal for web scraping, regression testing, or any automation scenario where avoiding detection or maintaining realistic environment profiles is critical. Key APIs include `getRandomBrowserConfig()` for random self-consistent configs by site region, `injectStealthScripts()` for page-level injection, `createStealthContext()` for ready-to-use browser contexts, and startup argument helpers like `STEALTH_ARGS` and `IGNORE_DEFAULT_ARGS`.

Works with~Claude Code~Codex CLI~Cursor
npx skills add shuangying0001-beep/playwright-stealth

Installed? Explore more Coding & Development skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

Ask in your favorite AI

Open a new chat with this agent skill pre-loaded.

Documentation

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.

Related Skills