A robust Rust library for controlling Chrome/Chromium browsers via the Chrome DevTools Protocol (CDP).
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(())
}
Add to your Cargo.toml:
[dependencies]
cdp-core = "0.1.0"
tokio = { version = "1", features = ["full"] }
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
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 │
└─────────────────────────────────────┘
This project is licensed under the MIT license.
Contributions welcome! Please see CONTRIBUTING.md for details.