Type safe generator/client library for CDP
Maintained. Last release 9 months ago, commits in 2 of the last 26 weeks. Weaker on commit activity and issue handling.
pip install cdp-useCDP Use
A type-safe Python client generator for the Chrome DevTools Protocol (CDP). This library automatically generates Python bindings with full TypeScript-like type safety from the official CDP protocol specifications.
🚀 Features
- 🔒 Type Safety: Full type hints with
TypedDictclasses for all CDP commands, parameters, and return types - 🎯 Event Registration: Typesafe event handlers with full IDE support
- 🏗️ Auto-Generated: Code generated directly from official Chrome DevTools Protocol specifications
- 🎯 IntelliSense Support: Perfect IDE autocompletion and type checking
- 📦 Domain Separation: Clean organization with separate modules for each CDP domain
- 🔄 Always Up-to-Date: Easy regeneration from latest protocol specs
🛠️ Installation & Setup
- Clone and install dependencies:
git clone https://github.com/browser-use/cdp-use
cd cdp-use
uv sync # or pip install -r requirements.txt
- Generate the CDP client library:
python -m cdp_use.generator
This automatically downloads the latest protocol specifications and generates all type-safe bindings.
📖 Usage Examples
Basic Usage
import asyncio
from cdp_use.client import CDPClient
async def main():
# Connect to Chrome DevTools
async with CDPClient("ws://localhost:9222/devtools/browser/...") as cdp:
# Get all browser targets with full type safety
targets = await cdp.send.Target.getTargets()
print(f"Found {len(targets['targetInfos'])} targets")
# Navigate to a page
await cdp.send.Page.navigate({"url": "https://example.com"})
asyncio.run(main())
Type Safety in Action
# ✅ Fully typed parameters
await cdp.send.Runtime.evaluate(params={
"expression": "document.title",
"returnByValue": True
})
# ✅ Return types are fully typed
result = await cdp.send.DOM.getDocument(params={"depth": 1})
node_id: int = result["root"]["nodeId"] # Full IntelliSense support
# ❌ Type errors caught at development time
await cdp.send.DOM.getDocument(params={"invalid": "param"}) # Type error!
🎧 Event Registration
The library provides typesafe event registration with full IDE support: