Skip to content

About

Agent-native low-trace Chrome/Chromium/Edge automation over CDP without Runtime.enable, with a 6-tool MCP server and zero-token CLI

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

StealthCDP

Agent-native, low-trace Chrome, Chromium, and Edge automation over the Chrome DevTools Protocol (CDP), with zero WebDriver, zero Runtime.enable, zero DOM.getDocument, a clean stealthcdp/raw subpath, a 6-tool Model Context Protocol server (stealthcdp-mcp), and a zero-token stealthcdp CLI.

简体中文

If you like StealthCDP, please give it a ⭐ on GitHub: it helps others find the project and keeps it going.

  • Quiet CDP. Never sends Runtime.enable, Runtime.addBinding, Console.enable, Debugger.enable, or DOM.getDocument on default paths. Resolves main and isolated execution worlds via DOM.describeNode + DOM.resolveNode, scopes Target.setAutoAttach without leaking page-observable inspector agents, and leaves Chrome's sandbox and site isolation on.
  • Frames and Shadow DOM. Same-process and out-of-process iframes (OOPIFs) route through dedicated CDP sessions. CSS (including the >>> shadow-piercing combinator), XPath, text, and native ARIA { role, name } queries pierce open and closed Shadow DOM.
  • Trusted, realistic input. Actions verify visibility, stability, and hit-testing without replaying already-dispatched input. Optional seeded human mode drives Mulberry32 reproducible Fitts/minimum-jerk trajectories, micro-tremor, HTML5 & pointer drags, and grapheme-segmented keyboard typing.
  • Agent-native 6-tool MCP & zero-token CLI. stealthcdp exposes 6 orthogonal MCP tools (browser_navigate, browser_observe, browser_act, browser_evaluate, browser_devtools, browser_handoff), automatically negotiates both MCP 2026-07-28 and 2025-11-25 / 2025-06-18 on stdio, /mcp, and socket, and provides 25 shell subcommands (stealthcdp open|snap|fill|batch|...) plus daemon lifecycle controls for zero-schema-token CLI workflows.

Architecture

flowchart TD
  app["Your code"] --> api["stealthcdp<br/>Browser · Context · Tab · Element · Locator"]
  agent["AI agent"] -->|"6-tool MCP or CLI"| mcp["stealthcdp / stealthcdp-mcp"]
  mcp --> api
  rawApp["Protocol code"] --> raw["stealthcdp/raw<br/>TargetSession · IsolatedWorld · InputScope"]
  api --> input["Input layer<br/>queue · checks · cleanup"]
  api --> conn["CDP connection<br/>sessions · deadlines · drain"]
  input --> conn
  raw --> conn
  conn -->|"Pipe or WebSocket"| chrome["Chrome · Chromium · Edge"]
  chrome --- pages["Pages, OOPIFs, Dedicated/Shared/Service Workers"]
Loading

Requirements

  • Node.js >=24.22.0.
  • Chrome, Chromium, or Microsoft Edge on Windows, macOS, or Linux (auto-detected or configured via CHROME_PATH / executablePath).
  • A display for headed mode, headless: true (--headless) on headless servers, or XvfbSession (--virtual-display) on Linux.

Quick Start

npm install stealthcdp
import { Browser } from 'stealthcdp';

await using browser = await Browser.launch({ headless: true });
const tab = await browser.newTab('https://example.com');
console.log(await (await tab.waitForSelector('h1')).text());
await tab.screenshot({ path: 'page.png', fullPage: true });

Key capabilities across package subpaths:

  • stealthcdp: High-level Browser, BrowserContext, Tab, TabScope, Frame, Element (click, fill, type, select, setChecked, dragTo, readControlValue), Locator, Network, Route, Download, and AES-256-GCM state encryption (encryptState / decryptState). See Core API Guide.
  • stealthcdp/raw: Unmanaged attach: 'none' sessions, TargetSession, IsolatedWorldPool, withClosedShadowRoots, parseDOMSnapshot, hitTestPoint, inspectScrollContext, getNodeEventListeners, InputScope, Composition, and createCommandGuard. See Raw CDP Sessions.
  • stealthcdp/testing: Offline ScriptedChrome harness for deterministic unit tests without launching Chrome. See Core API Guide.

MCP Server & Zero-Token CLI

Configure stealthcdp for any MCP client (2026-07-28, 2025-11-25, or 2025-06-18 are negotiated automatically):

{
  "mcpServers": {
    "browser": {
      "command": "npx",
      "args": ["-y", "--package=stealthcdp", "stealthcdp-mcp"]
    }
  }
}

Or run as a multi-lease authenticated HTTP server or zero-token local CLI daemon:

# Authenticated Streamable HTTP service (serves both modern and legacy MCP clients on /mcp)
export STEALTHCDP_MCP_TOKEN="$(openssl rand -hex 32)"
stealthcdp --http --port 3100 --input-mode human --remote-handoff

# Zero-token local CLI workflow backed by an authenticated local socket daemon
stealthcdp daemon start --input-mode human
stealthcdp open https://example.com --snap
stealthcdp batch '[{"action":"fill","ref":"e3","text":"hello"},{"action":"click","ref":"e5"}]' --snap
stealthcdp daemon stop

The 6 orthogonal MCP tools (BROWSER_MCP_TOOLS):

  1. browser_navigate: open, goto, back, forward, reload, tabs, close_tab, close_browser (with optional snapshot: true).
  2. browser_observe: snapshot (interactive, diff, viewport, full), find (CSS/>>>/XPath/text/ARIA role), wait (selector/ref/closed-shadow text/URL/loadState), screenshot (including marks: 'interactive' | 'all').
  3. browser_act: Single action (click, click_at, hover, drag, fill, type, press_key, select, check, scroll, upload, dialog) or sequential fail-fast steps: [...] batch (stops on error/navigation/dialog without rollback) with post-write control value readback.
  4. browser_evaluate: Runs async JS in world: 'isolated' by default (pass world: 'main' explicitly for page globals), with optional ref bound as el.
  5. browser_devtools: network, console, input_policy, environment, downloads, and storage_state.
  6. browser_handoff: request, wait, cancel (elicit visible window or remote viewer link; registered only when handoff is enabled).

See MCP & CLI Guide.

Protocol Hygiene & Environment Consistency

  • Default launches use transport: 'pipe' (no open TCP debugging port), disable AutomationControlled, and keep Runtime, Console, Debugger, and whole-document DOM domains off.
  • Tab.setEnvironment() preserves native HiDPI devicePixelRatio when deviceScaleFactor is omitted (0) and—together with maskHeadless: true—synchronizes UA, UA-CH, locale, and timezone across pages, OOPIFs, Dedicated Workers, Shared Workers, and Service Workers before script execution.
  • See Environment & Protocol Hygiene and Trusted Input & Pacing.

Development

npm ci
npm run check            # tsc (src + test), browser-runtime AST check, and bilingual docs check
npm test                 # offline unit tests powered by ScriptedChrome
npm run test:integration # real Chrome integration suite (run in CI or non-locked workstations)
npm run test:dist        # package build + smoke & HTTP/raw-session verification
npm run format:check

Documentation

All guides are maintained in English and Simplified Chinese with automated parity checks:

Guide Topics
Core API (中文) Browser, BrowserContext, Tab, TabScope, Frame, >>> & ARIA queries, Element, Locator, Network, ScriptedChrome
Trusted Input (中文) InputPolicy, Mulberry32 human trajectories, Mouse, Keyboard, IME Composition, PresentationLease
Environment & Workers (中文) Protocol hygiene, HiDPI viewport, Dedicated/Shared/Service Worker alignment, ProxyForwarder, XvfbSession, diagnostics
Raw CDP Sessions (中文) stealthcdp/raw, attach: 'none', TargetSession, IsolatedWorldPool, closed Shadow DOM, DOMSnapshot, hitTestPoint
MCP & CLI (中文) 6-tool MCP surface, automatic dual-era /mcp & stdio & socket, zero-token CLI subcommands, security guards
Benchmarks & Audits (中文) bench:mcp, bench:audit, bench:worker-environment, bench:ax-subtree, test:soak

Release history is recorded in CHANGELOG.md.

License

Apache-2.0. See LICENSE.

About

Agent-native low-trace Chrome/Chromium/Edge automation over CDP without Runtime.enable, with a 6-tool MCP server and zero-token CLI

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages