cdp-rs

A Rust workspace for Chrome DevTools Protocol automation.

The repository currently contains:

Features

Quick Start

use cdp_core::Browser;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    // Launch browser
    let browser = Browser::launcher().launch().await?;

    // Create a new page
    let page = browser.new_page().await?;

    // Navigate to a website
    page.navigate("https://example.com").await?;

    // Find and interact with elements
    if let Some(button) = page.query_selector("#button").await? {
        button.click().await?;
    }

    // Take a screenshot
    page.screenshot(true, Some("screenshot.png".into())).await?;

    // Explicitly release page and connection resources when done
    page.cleanup().await?;
    browser.disconnect().await?;

    Ok(())
}

Installation

Add to your Cargo.toml:

[dependencies]
cdp-core = "0.3.4"
tokio = { version = "1", features = ["full"] }

Use cdp-protocol = "0.3.1" only if you need low-level generated protocol types directly.

Lifecycle Management

For short-lived or exclusive browser connections, explicitly clean up the page and disconnect the browser when work is complete.

When reusing a shared Browser, keep page.cleanup() and context.close() at request boundaries, and call browser.disconnect() only during process shutdown or after the shared connection is known to be unhealthy.

Documentation

Examples

From the workspace root, run examples from crates/cdp-core/examples/:

# Run basic example
cargo run -p cdp-core --example basic

# Run comprehensive example
cargo run -p cdp-core --example comprehensive

# Run network example
cargo run -p cdp-core --example network

Architecture

cdp-core provides a high-level, async Rust API over the Chrome DevTools Protocol:

┌─────────────────────────────────────┐
│         Your Application            │
└─────────────────┬───────────────────┘
                  │
┌─────────────────▼───────────────────┐
│          cdp-core API               │
│  (Browser, Page, Element, Network)  │
└─────────────────┬───────────────────┘
                  │
┌─────────────────▼───────────────────┐
│    Chrome DevTools Protocol (CDP)   │
└─────────────────┬───────────────────┘
                  │
┌─────────────────▼───────────────────┐
│      Chrome/Chromium Browser        │
└─────────────────────────────────────┘

Requirements

License

This project is licensed under the MIT license.

Contributing

Contributions welcome! Please see CONTRIBUTING.md for details.