cdpkit
Type-safe Rust Chrome DevTools Protocol (CDP) client with async/await support.
Features
- 🔒 Type-safe - All CDP commands and events are strongly typed with compile-time validation
- 🚀 Async-first - Built on tokio with full async/await support
- 📡 Stream-based events - Handle CDP events using Rust streams with multiplexing and filtering
- 🎯 Pure protocol client - Direct CDP access without abstraction layers, full control
- 🔄 Auto-generated bindings - Generated from official CDP specification, always up-to-date
- 🪶 Lightweight - Minimal dependencies, focused on protocol communication
- 🔌 Flexible connection - Connect to running browser instances without process management
Quick Start
use ;
use StreamExt;
async
Installation
[]
= "0.2"
= { = "1", = ["full"] }
= "0.3"
Documentation
- Examples - Working code examples
Code Generation
cdpkit uses auto-generated bindings from the official Chrome DevTools Protocol specification. The cdpkit_codegen tool handles this process.
Regenerate CDP Bindings
To update CDP bindings to the latest protocol version:
# Run the code generator
# The generated code will be written to cdpkit/src/protocol.rs
How It Works
- Fetch Protocol - Downloads the latest CDP protocol JSON from Chrome's repository
- Parse Specification - Parses the protocol definition into Rust data structures
- Generate Code - Generates type-safe Rust code for all CDP domains, commands, and events
- Output - Writes the generated code to
cdpkit/src/protocol.rs
The generated code includes:
- All CDP domains (Page, Network, Runtime, etc.)
- Strongly-typed command structures with builder patterns in
methodssubmodule - Response types in
responsessubmodule for method return values - Event types in
eventssubmodule for subscription - Type definitions in
typessubmodule for parameters and shared types
When to Regenerate
- When Chrome releases a new CDP version
- When you need experimental CDP features
- When contributing updates to the protocol bindings
Note: The generated protocol.rs file is checked into version control, so users don't need to run the generator unless they want to update the protocol version.
Why cdpkit?
Direct Protocol Access
cdpkit provides direct access to CDP, giving you full control over browser behavior:
// Send CDP commands directly with all parameters
new
.with_referrer
.with_transition_type
.send
.await?;
// Parse enum values from strings using FromStr
let transition: TransitionType = "link".parse
.expect;
// Convert enum values back to strings using AsRef<str>
let s: &str = Link.as_ref; // "link"
// Access complete return data
let result = new
.with_return_by_value
.send
.await?;
Powerful Event Handling
Stream-based event system with composition, filtering, and multiplexing:
use StreamExt;
// Subscribe to multiple events
let mut load_events = subscribe;
let mut nav_events = subscribe;
// Use stream combinators
let mut combined = select;
// Filter and process
while let Some = combined.next.await
Compile-Time Type Safety
All CDP operations are type-checked, catching errors at compile time:
// ✅ Type-checked: required parameters
let cmd = new;
// ✅ Type-checked: return values
let result = cmd.send.await?;
let frame_id: String = result.frame_id; // Type is known
// ❌ Compile error: missing parameter
let cmd = new; // Error: missing url
// ❌ Compile error: type mismatch
let cmd = new; // Error: expected String
Use Cases
cdpkit is ideal for:
- Automated testing - Precise control over browser behavior
- Web scraping - Monitor network requests and responses
- Performance analysis - Access detailed performance metrics
- Debugging tools - Build custom developer tools
- Browser extensions - Low-level CDP access
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.