Python client for ModCDP.
Project description
ModCDP
ModCDP is a small Chrome DevTools Protocol client and extension bridge. It connects to Chrome over CDP, discovers or injects the ModCDP extension service worker, and routes normal CDP commands, custom commands, and custom events through the same client API.
This package contains the Python client. It mirrors the JavaScript and Go clients so SDKs can use the same option names and behavior across languages.
Install
pip install modcdp
Basic Usage
from modcdp import ModCDPClient
cdp = ModCDPClient().connect()
version = cdp.send("Browser.getVersion")
print(version)
cdp.close()
When no cdp_url is provided, the client can launch a local browser and load the bundled ModCDP extension. The package includes the extension zip used for automatic injection.
Options
The Python constructor mirrors the JavaScript and Go clients:
cdp_url: upstream CDP HTTP or websocket URL.extension_path: extension directory or zip. Defaults to the bundled extension zip.routes: client-side route map such as{ "Mod.*": "service_worker", "*.*": "direct_cdp" }.server: service-worker server config, includingloopback_cdp_urlandroutes.custom_commands: custom commands registered during connect.custom_events: custom events registered during connect.custom_middlewares: custom request/response/event middleware registered during connect.service_worker_url_includesandservice_worker_url_suffixes: service-worker discovery filters.scan_for_existing_localhost_9222: attach to localhost Chrome before launching a new browser.mirror_upstream_events: mirror upstream CDP events through the ModCDP service worker.*_timeout_msand*_interval_ms: override CDP send, websocket connect, service-worker probe, event wait, and polling timings.
Custom Commands And Events
from modcdp import ModCDPClient
cdp = ModCDPClient(
custom_commands=[
{
"name": "Custom.echo",
"expression": "(params) => ({ value: params.value })",
}
],
custom_events=[
{
"name": "Custom.ready",
}
],
).connect()
print(cdp.send("Custom.echo", {"value": "hello"}))
cdp.close()
Repository
Source, examples, JavaScript client, Go client, and extension implementation live at:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file modcdp-0.0.4.tar.gz.
File metadata
- Download URL: modcdp-0.0.4.tar.gz
- Upload date:
- Size: 52.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
12a05cd27e1f0e51d37b7366225c9225ade0ece07154e4378af6b860411919aa
|
|
| MD5 |
6877f1240ef6fb77542430c1cc4aa0c5
|
|
| BLAKE2b-256 |
ec458ab42651c1a7932931c977abb6e7f69b9a683e019043d72299942ccc892a
|
File details
Details for the file modcdp-0.0.4-py3-none-any.whl.
File metadata
- Download URL: modcdp-0.0.4-py3-none-any.whl
- Upload date:
- Size: 44.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d3a62f64a0c2907349d21281c33be9145f4665dba95a674bfa8805ca6627ba29
|
|
| MD5 |
7f10082bff08d69a82f0874caee6cf37
|
|
| BLAKE2b-256 |
281bd0d28388f58ea8662933d96970b97c0accdf9cdb229b86872544fe51739b
|