1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
//! # Viewpoint CDP - Chrome DevTools Protocol Client
//!
//! Low-level Chrome DevTools Protocol (CDP) implementation over WebSocket,
//! providing the foundational transport layer for Viewpoint browser automation.
//!
//! This crate handles:
//! - WebSocket connection management to Chrome/Chromium browsers
//! - CDP message serialization and deserialization
//! - Command/response handling with async/await
//! - Event subscription and streaming
//! - Session management for multiple targets (pages, workers)
//!
//! ## Features
//!
//! - **Async WebSocket**: Non-blocking WebSocket communication with Chromium
//! - **Type-safe Protocol**: Strongly-typed CDP domains (Page, Runtime, Network, etc.)
//! - **Event Streaming**: Subscribe to CDP events with async streams
//! - **Session Multiplexing**: Handle multiple page sessions over a single connection
//! - **Error Handling**: Comprehensive error types for CDP and transport errors
//!
//! ## Quick Start
//!
//! ```no_run
//! use viewpoint_cdp::{CdpConnection, protocol::target_domain::GetTargetsParams};
//!
//! # async fn example() -> Result<(), viewpoint_cdp::CdpError> {
//! // Connect to a running Chrome instance
//! let conn = CdpConnection::connect("ws://localhost:9222/devtools/browser/...").await?;
//!
//! // Send a CDP command
//! let result: viewpoint_cdp::protocol::target_domain::GetTargetsResult =
//! conn.send_command("Target.getTargets", Some(GetTargetsParams::default()), None).await?;
//!
//! for target in result.target_infos {
//! println!("Target: {} - {}", target.target_type, target.url);
//! }
//! # Ok(())
//! # }
//! ```
//!
//! ## Discovering Chrome WebSocket URL
//!
//! Chrome exposes a JSON API for discovering the WebSocket URL:
//!
//! ```no_run
//! use viewpoint_cdp::{discover_websocket_url, CdpConnectionOptions};
//!
//! # async fn example() -> Result<(), viewpoint_cdp::CdpError> {
//! // Get WebSocket URL from HTTP endpoint
//! let options = CdpConnectionOptions::default();
//! let ws_url = discover_websocket_url("http://localhost:9222", &options).await?;
//! println!("WebSocket URL: {}", ws_url);
//! # Ok(())
//! # }
//! ```
//!
//! ## Sending Commands
//!
//! Commands are sent with optional session IDs for page-specific operations:
//!
//! ```no_run
//! use viewpoint_cdp::CdpConnection;
//! use viewpoint_cdp::protocol::page::NavigateParams;
//!
//! # async fn example(conn: &CdpConnection, session_id: &str) -> Result<(), viewpoint_cdp::CdpError> {
//! // Browser-level command (no session)
//! let version: viewpoint_cdp::BrowserVersion = conn.send_command(
//! "Browser.getVersion",
//! None::<()>,
//! None // No session ID for browser-level commands
//! ).await?;
//!
//! // Page-level command (with session)
//! let result: viewpoint_cdp::protocol::page::NavigateResult = conn.send_command(
//! "Page.navigate",
//! Some(NavigateParams {
//! url: "https://example.com".to_string(),
//! referrer: None,
//! transition_type: None,
//! frame_id: None,
//! }),
//! Some(session_id) // Target a specific page
//! ).await?;
//! # Ok(())
//! # }
//! ```
//!
//! ## Subscribing to Events
//!
//! Subscribe to CDP events using the event channel:
//!
//! ```no_run
//! use viewpoint_cdp::{CdpConnection, CdpEvent};
//!
//! # async fn example(conn: &CdpConnection) -> Result<(), viewpoint_cdp::CdpError> {
//! let mut events = conn.subscribe_events();
//!
//! // Process events in a loop
//! while let Ok(event) = events.recv().await {
//! match &event.method[..] {
//! "Page.loadEventFired" => {
//! println!("Page loaded!");
//! }
//! "Network.requestWillBeSent" => {
//! println!("Network request: {:?}", event.params);
//! }
//! _ => {}
//! }
//! }
//! # Ok(())
//! # }
//! ```
//!
//! ## Connection Options
//!
//! Configure connection behavior with options:
//!
//! ```no_run
//! use viewpoint_cdp::{CdpConnection, CdpConnectionOptions};
//! use std::time::Duration;
//!
//! # async fn example() -> Result<(), viewpoint_cdp::CdpError> {
//! let options = CdpConnectionOptions::new()
//! .timeout(Duration::from_secs(30));
//!
//! let conn = CdpConnection::connect_with_options(
//! "ws://localhost:9222/devtools/browser/...",
//! &options
//! ).await?;
//! # Ok(())
//! # }
//! ```
//!
//! ## Protocol Domains
//!
//! The [`protocol`] module contains typed definitions for CDP domains:
//!
//! - `target_domain` - Target management (pages, workers, service workers)
//! - `page` - Page navigation and lifecycle
//! - `runtime` - JavaScript execution
//! - `network` - Network monitoring and interception
//! - `fetch` - Network request interception
//! - `dom` - DOM inspection and manipulation
//! - `input` - Input device simulation
//! - `emulation` - Device and media emulation
//! - And many more...
//!
//! ## Error Handling
//!
//! The [`CdpError`] type covers all possible errors:
//!
//! ```no_run
//! use viewpoint_cdp::{CdpConnection, CdpError};
//!
//! # async fn example() -> Result<(), CdpError> {
//! let result = CdpConnection::connect("ws://invalid:9999/...").await;
//!
//! match result {
//! Ok(conn) => println!("Connected!"),
//! Err(CdpError::ConnectionFailed(e)) => println!("Connection error: {}", e),
//! Err(CdpError::Protocol { code, message }) => {
//! println!("CDP error {}: {}", code, message);
//! }
//! Err(e) => println!("Other error: {}", e),
//! }
//! # Ok(())
//! # }
//! ```
//!
//! ## Module Organization
//!
//! - [`connection`] - WebSocket connection management
//! - [`transport`] - Message types and serialization
//! - [`protocol`] - CDP domain type definitions
//! - [`error`] - Error types
pub use ;
pub use CdpError;
pub use ;