cdp-core

Crates.iocdp-core
lib.rscdp-core
version0.2.0
created_at2025-12-02 17:14:34.383723+00
updated_at2025-12-13 06:04:36.172525+00
descriptionImplementation of chrome devtools protocol
homepagehttps://github.com/oh0123/cdp-rs
repositoryhttps://github.com/oh0123/cdp-rs
max_upload_size
id1962214
size561,894
OneHow (oh0123)

documentation

README

cdp-rs

A robust Rust library for controlling Chrome/Chromium browsers via the Chrome DevTools Protocol (CDP).

Features

  • 🌐 Browser Control - Launch, connect, and manage browser instances
  • 🔍 Element Interaction - Find, click, type, and manipulate DOM elements. Features seamless Cross-iframe querying and Shadow Root (open/closed) support
  • 📸 Screenshots - Capture element and full-page screenshots
  • 🌐 Network Control - Intercept, monitor, and modify network requests
  • ⌨️ Input Simulation - Realistic keyboard and mouse input
  • 💾 Storage Management - Control cookies, localStorage, and sessionStorage
  • Smart Waiting - Wait for selectors, navigation, network idle, custom conditions
  • 🎭 Emulation - Device emulation, geolocation, user agents
  • Accessibility - Inspect accessibility tree
  • 📊 Performance Tracing - Capture performance traces

Quick Start

use cdp_core::{Browser, Page};
use std::sync::Arc;

#[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?;
    
    Ok(())
}

Installation

Add to your Cargo.toml:

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

Documentation

Examples

Check out the examples directory for runnable code:

# Run basic example
cargo run --example basic

# Run comprehensive test
cargo run --example comprehensive_test

# Run web scraping example
cargo run --example web_scraping

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

  • Chrome or Chromium browser
  • Rust 1.70 or later
  • Tokio async runtime

License

This project is licensed under the MIT license.

Contributing

Contributions welcome! Please see CONTRIBUTING.md for details.

Commit count: 0

cargo fmt