Install & Compatibility
Where this runs
tested against v1.4.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.638s · 20.5MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 1.7s · import 0.582s · 21MB
19MB installed
● package 19MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
browser
✓ from mycdp import browser
✗ from mycdp import cdp
page
✓ from mycdp import page
✗ from mycdp import cdp
runtime
✓ from mycdp import runtime
✗ from mycdp import cdp
This example launches a headless Chrome instance, connects to it via MyCDP, navigates to 'example.com', retrieves its title, and lists its cookies. It demonstrates connecting to a browser, enabling a CDP domain, and executing basic page and runtime commands. Ensure you have a Chrome/Chromium executable in your system's PATH (e.g., 'google-chrome', 'chromium').
import subprocess
import time
import os
from mycdp import cdp
# --- This quickstart requires a Chrome/Chromium browser executable in your PATH ---
# Start Chrome in headless mode with remote debugging enabled on port 9222
# Adjust 'google-chrome' to 'chromium', 'chrome', or the full path to your browser
chrome_executable = os.environ.get('CHROME_EXECUTABLE', 'google-chrome')
remote_debugging_port = os.environ.get('REMOTE_DEBUGGING_PORT', '9222')
chrome_process = None
ws_url = f"ws://localhost:{remote_debugging_port}"
session = None
try:
print(f"Launching {chrome_executable} with remote debugging on port {remote_debugging_port}...")
# Note: stderr/stdout are redirected to PIPE to avoid polluting the console
chrome_process = subprocess.Popen(
[chrome_executable, '--headless=new', f'--remote-debugging-port={remote_debugging_port}'],
stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True
)
time.sleep(3) # Give Chrome a moment to start and open the debugging port
# Connect to the running Chrome instance
print(f"Connecting to Chrome at {ws_url}...")
session = cdp.browser.connect(ws_url)
print("Successfully connected to Chrome.")
# Enable the Page domain to receive events and navigate
cdp.page.enable(session)
# Navigate to a URL
target_url = "https://www.example.com"
print(f"Navigating to {target_url}...")
cdp.page.navigate(session, url=target_url)
# Wait for the page to finish loading (load event)
cdp.page.wait_for_load_event(session)
print(f"Successfully navigated to {target_url}")
# Execute a JavaScript expression to get the page title
title_response = cdp.runtime.evaluate(session, expression="document.title")
if title_response and title_response.result:
print(f"Page title: {title_response.result.value}")
# Example: Get all cookies
cookies_response = cdp.storage.get_cookies(session)
if cookies_response and cookies_response.cookies:
print(f"Found {len(cookies_response.cookies)} cookies.")
# for cookie in cookies_response.cookies:
# print(f" - {cookie.name}: {cookie.value}")
except Exception as e:
print(f"An error occurred: {e}")
# Print stderr if Chrome process is available and has output
if chrome_process:
try:
_, stderr_output = chrome_process.communicate(timeout=1)
if stderr_output:
print("Chrome stderr:", stderr_output)
except subprocess.TimeoutExpired:
chrome_process.kill()
print("Chrome stderr: Process timed out during communicate, killed.")
finally:
# Always close the CDP session and terminate the Chrome process
if session:
print("Closing CDP session...")
cdp.browser.close(session)
if chrome_process and chrome_process.poll() is None:
print("Terminating Chrome process...")
chrome_process.terminate()
try:
chrome_process.wait(timeout=5)
except subprocess.TimeoutExpired:
chrome_process.kill()
print("Chrome process did not terminate gracefully, killed.")
print("Quickstart finished.")
Upgrade
Version history
1.4.0latest on PyPI · released Jun 13, 2026
Audit
Dependencies
No dependency data recorded yet.