cdp_lite/lib.rs
1//! # cdp-lite
2//!
3//! A lightweight and low-overhead Rust client for the Chrome DevTools Protocol.
4//!
5//! ## Examples
6//! ### 1. Basic Navigation
7//! This example shows how to connect to a browser and navigate to a specific URL.
8//!
9//! ```rust
10//! use cdp_lite::client::CdpClient;
11//! use cdp_lite::protocol::NoParams;
12//! use cdp_lite::error::CdpResult;
13//! use std::time::Duration;
14//! use serde_json::json;
15//!
16//! # async fn doc_example() -> CdpResult<()> {
17//! let client = CdpClient::new("127.0.0.1:9222", Duration::from_secs(5)).await?;
18//! client.send_raw_command("Page.enable", NoParams).await?;
19//! client.send_raw_command("Page.navigate", json!({"url": "https://www.rust-lang.org"})).await?;
20//! # Ok(())
21//! # }
22//! ```
23//!
24//! ### 2. Listening to Events
25//! This example demonstrates how to subscribe to specific domains (like "Network" and "Page") and process incoming events.
26//!
27//! ```rust
28//! use cdp_lite::client::CdpClient;
29//! use cdp_lite::protocol::NoParams;
30//! use cdp_lite::error::CdpResult;
31//! use std::time::Duration;
32//! use serde_json::json;
33//! use tokio_stream::StreamExt;
34//!
35//! # async fn doc_example() -> CdpResult<()>{
36//! let client = CdpClient::new("127.0.0.1:9222", Duration::from_secs(5)).await?;
37//! let network = client.on_domain("Network");
38//! let page = client.on_domain("Page");
39//! let mut activity = StreamExt::merge(network, page);
40//! tokio::spawn(async move {
41//! while let Some(Ok(event)) = activity.next().await {
42//! println!("📢 Activity: {}", event.method.unwrap());
43//! }
44//! });
45//! client.send_raw_command("Page.navigate", json!({"url": "https://www.rust-lang.org"})).await?;
46//! # Ok(())
47//! # }
48//! ```
49
50pub mod client;
51pub mod error;
52pub mod event_filter;
53pub mod protocol;
54mod rest_client;