Skip to main content

Chrome DevTools Protocol automation toolkit

Project description

CDP Toolkit

PyPI Tests Dependencies License Python

Chrome DevTools Protocol automation without external dependencies. No Playwright, no Selenium, no Puppeteer. Pure Python stdlib.

Install

pip install cdp-toolkit

Why CDP Toolkit?

Feature Playwright Selenium cdp-toolkit
Dependencies 50+ packages 20+ packages 0
Install size ~300MB ~150MB ~15KB
Browser download Yes (~200MB) Yes (~100MB) No
Learning curve Medium High Low
Speed Fast Slow Fastest
Cloud-native Yes Partial Yes

CDP Toolkit talks directly to Chrome's DevTools Protocol via HTTP and WebSocket. You bring your own Chrome instance (local, Docker, or cloud), and CDP Toolkit handles the rest.

Quick Start

from cdp_toolkit import CDPClient

# Connect to a Chrome instance with --remote-debugging-port=9222
client = CDPClient("127.0.0.1", 9222)

# List open tabs
tabs = client.list_targets()
for tab in tabs:
    print(f"{tab['id'][:8]} | {tab['url'][:60]}")

# Create a new tab
new_tab = client.create_target("https://example.com")

# Navigate
client.navigate(new_tab['id'], "https://httpbin.org/forms/post")

# Execute JavaScript
title = client.evaluate(new_tab['id'], "document.title")
print(f"Page title: {title}")

React/Vue Form Filling

The most common CDP use case: filling forms on React/Vue/Angular sites where standard input.value = "x" does not trigger reactivity.

from cdp_toolkit import CDPInput

# Generate native setter JavaScript for React
js_code = CDPInput.native_setter_js(
    selector="#email",
    value="user@example.com"
)
# Execute via CDP — triggers React's onChange handler

# For Vue.js
js_code = CDPInput.vue_setter_js(
    selector="input[name='phone']",
    value="+1234567890"
)

# Key-by-key typing simulation
js_code = CDPInput.simulate_typing(
    selector="#search",
    text="hello world",
    delay_ms=50
)

Mouse Events

from cdp_toolkit import CDPMouseEvents

# Click at coordinates
params = CDPMouseEvents.click(x=200, y=300)

# Right-click
params = CDPMouseEvents.click(x=200, y=300, button="right")

# Double-click
params = CDPMouseEvents.double_click(x=200, y=300)

# Drag and drop
params = CDPMouseEvents.drag(
    start_x=100, start_y=200,
    end_x=400, end_y=300
)

Navigation and Screenshots

from cdp_toolkit import CDPNavigation

# Navigate and wait for load
client.navigate_and_wait(tab_id, "https://example.com")

# Take screenshot
screenshot_b64 = client.screenshot(tab_id)

# Scroll to element
js = CDPNavigation.scroll_to_element("#footer")
client.evaluate(tab_id, js)

# Wait for selector
js = CDPNavigation.wait_for_selector(".result-card", timeout_ms=5000)

Anti-Detection

CDP Toolkit includes JavaScript snippets to make automation less detectable:

from cdp_toolkit import stealth

# Remove webdriver flag
client.evaluate(tab_id, stealth.remove_webdriver_flag())

# Override navigator properties
client.evaluate(tab_id, stealth.override_navigator())

# Add realistic timing jitter
CDPInput.set_typing_delay(min_ms=30, max_ms=120)

Docker Integration

Run Chrome in Docker and control it with CDP Toolkit:

# Dockerfile
FROM chrome/headless
EXPOSE 9222
CMD ["chrome", "--remote-debugging-port=9222", "--no-sandbox"]
# Connect to Docker Chrome
client = CDPClient("chrome-container", 9222)

Testing

python -m pytest tests/ -v --tb=short

38 tests covering all modules. Zero external dependencies in tests.

API Reference

CDPClient

Method Description
list_targets() List all open tabs/pages
create_target(url) Open a new tab
close_target(id) Close a tab
activate_target(id) Focus a tab
navigate(id, url) Navigate to URL
evaluate(id, js) Execute JavaScript
screenshot(id) Capture page screenshot

CDPInput

Method Description
native_setter_js(sel, val) React-compatible value setter
vue_setter_js(sel, val) Vue.js-compatible value setter
simulate_typing(sel, text, delay) Human-like typing simulation
key_event(key) Send keyboard event

CDPMouseEvents

Method Description
click(x, y, button) Mouse click
double_click(x, y) Double click
drag(sx, sy, ex, ey) Drag and drop
hover(x, y) Mouse hover

License

MIT — see LICENSE

Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cdp_toolkit-1.2.1.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cdp_toolkit-1.2.1-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file cdp_toolkit-1.2.1.tar.gz.

File metadata

  • Download URL: cdp_toolkit-1.2.1.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for cdp_toolkit-1.2.1.tar.gz
Algorithm Hash digest
SHA256 92a5ba359715e1ed6d9ef53b2c1f36a512411866312cbe4a4d037d4009734125
MD5 f5dfc8fb1f0833fb40836cd2b4ee5a9b
BLAKE2b-256 6833ec28548273fbd6863764240a4249ba53bfcbe97c90a1a9f7a57c1e8784ad

See more details on using hashes here.

File details

Details for the file cdp_toolkit-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: cdp_toolkit-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for cdp_toolkit-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 42b453f2c5749d1c154efea09e0cae06a85618f8033e8750791b8041bcfee418
MD5 a43bbad26cf22ac14a7a01d9f3551559
BLAKE2b-256 99777a02ac5e0f4e870f5c6af455445a1d546f96a531c4c82760f9d5540f2b8d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page