Skip to content

BrowserCash/DriveCDP

Repository files navigation

DriveCDP

Quiet Chrome automation over CDP.
Connect to a real browser. Keep the protocol small. Keep input trusted.

MIT Python 3.10+ Rust

DriveCDP is a Python client for an existing Chrome or Chromium session. It speaks CDP over an in-process Rust WebSocket actor. There is no Node process, and DriveCDP does not launch the browser for you.

That is useful when Chrome is already running (a remote browser, a local debugging port, a profile you manage yourself) and you want locators and trusted input without the usual CDP noise from bigger frameworks.

Python to PyO3 to Rust WS to CDP to Chrome

Why this instead of Playwright or raw CDP?

Playwright connect_over_cdp Raw CDP (pychrome, etc.) DriveCDP
What it is Full browser framework, can attach Protocol bindings you drive yourself Attach client with locators
Default CDP traffic Higher (tooling domains) Only what you send Low on the default path
Locators / fill / click Yes Build your own Yes
Human-like input No built-in policy No Optional
Quiet check No Do it yourself assert_quiet()
Transport Node / browser driver stack Your WebSocket code Rust, in-process

Use DriveCDP when you already own the browser and care what CDP methods get sent. Use Playwright when you want launch, multi-browser support, and the full ecosystem. Use raw CDP when you want every command hand-written. Fingerprint work belongs in the browser binary or profile, not in this client.

Install

Needs CPython 3.10+ and a Rust toolchain for the first build:

git clone https://github.com/alexander-spring/DriveCDP.git
cd DriveCDP
python -m pip install .

Point CDP_URL at an HTTP discovery URL (http://127.0.0.1:9222) or a browser WebSocket (ws:// / wss://):

chrome --remote-debugging-port=9222
export CDP_URL=http://127.0.0.1:9222

Usage

"""Minimal remote-browser example."""

import os

from drivecdp import connect

with connect(os.environ["CDP_URL"], strict_quiet=True) as browser:
    page = browser.default_page()
    page.goto(os.getenv("TARGET_URL", "https://example.com"))
    print(page.title())
    browser.assert_quiet()

Leaving the context only disconnects DriveCDP. It does not close a browser that someone else owns.

Optional humanized input (same trusted Input.* commands, no fingerprint changes):

"""Opt-in interaction shaping example."""

import os
from urllib.parse import quote

from drivecdp import InteractionPolicy, connect

DOCUMENT = (
    "<title>Humanized input</title><label>Search <input></label><button>Search</button>"
)
policy = InteractionPolicy(typing_wpm=65)

with connect(
    os.environ["CDP_URL"],
    humanize=policy,
    strict_quiet=True,
) as browser:
    page = browser.default_page()
    page.goto(f"data:text/html;charset=utf-8,{quote(DOCUMENT)}")
    page.label("Search").fill("quiet browser automation")
    page.role("button", name="Search").click()
    print(page.title())
    browser.assert_quiet()

Features

  • Connect only: HTTP discovery or ws / wss
  • Default path never sends Runtime.enable, Network.enable, or DOM.enable
  • strict_quiet blocks noisy commands before they hit Chrome
  • assert_quiet() / audit() (method counts and input timing; params not stored)
  • Locators, trusted input, optional InteractionPolicy
  • One-round-trip bulk extraction with locator.evaluate_all(...)
  • Sync API and drivecdp.asyncio
  • Screenshots, PDF, and scoped network/fetch when you ask for them
  • page.cdp() / browser.cdp() when you need raw protocol access

Examples

Development

python -m pip install "maturin==1.14.1"
maturin develop --release --locked
python -m pytest -q
cargo test --locked --all-targets --no-default-features

Compare with Playwright

Run the matched benchmark against fresh instances of the same installed Chrome:

python -m pip install -e ".[bench]"
python validation/compare.py --repeats 5 --headless --concurrency

One Windows 11 run with Chrome 150 and five fresh samples produced:

Median DriveCDP Playwright
Complete workload 1.34 s 2.92 s
Locator text 0.35 ms 1.88 ms
Element screenshot 30.7 ms 64.6 ms
Controller peak RSS 35.9 MiB 190.2 MiB
CDP commands 736 947

Results vary by machine and browser. The report saves raw samples and CDP method counts. Add --fingerprint to observe CreepJS in a separate headed Chrome.

Notes

Chrome and Chromium only. The API is still beta. Keeping CDP quiet does not make a browser undetectable; the binary, IP, and profile still matter. Only automate sites you are allowed to automate.

License

MIT. See LICENSE.

About

Chrome automation over CDP. Connect to browsers with a minimal protocol footprint.

Topics

Resources

License

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors