cdp_driver/types.rs
1//! Plain data types returned by CDP commands and events.
2
3use serde::{Deserialize, Serialize};
4use serde_json::Value;
5
6/// Response body of `GET /json/version`.
7#[derive(Debug, Clone, Deserialize, Serialize)]
8pub struct BrowserVersion {
9 /// Browser name and version, e.g. `"HeadlessChrome/120.0.0.0"`.
10 #[serde(rename = "Browser")]
11 pub browser: String,
12 /// The CDP protocol version Chrome speaks.
13 #[serde(rename = "Protocol-Version")]
14 pub protocol_version: String,
15 /// WebSocket URL for the browser-level debugger, if exposed.
16 #[serde(rename = "webSocketDebuggerUrl")]
17 pub web_socket_debugger_url: Option<String>,
18}
19
20/// A debuggable target (tab, worker, etc.) as reported by `GET /json/list`.
21#[derive(Debug, Clone, Deserialize, Serialize)]
22pub struct Target {
23 /// Chrome's opaque target id.
24 pub id: String,
25 /// Target kind, e.g. `"page"`. [`CdpClient::connect_to_page`](crate::client::CdpClient::connect_to_page)
26 /// only connects to targets of this type.
27 #[serde(rename = "type")]
28 pub target_type: String,
29 /// Current page/tab title.
30 pub title: String,
31 /// Current page/tab URL.
32 pub url: String,
33 /// WebSocket URL to open a CDP session against this target, if debuggable.
34 #[serde(rename = "webSocketDebuggerUrl")]
35 pub web_socket_debugger_url: Option<String>,
36}
37
38/// Result of `Page.navigate`.
39#[derive(Debug, Clone, Deserialize, Serialize)]
40pub struct NavigationResult {
41 /// The frame that started navigating.
42 #[serde(rename = "frameId")]
43 pub frame_id: String,
44 /// The loader driving this navigation, if one has been assigned yet.
45 #[serde(rename = "loaderId")]
46 pub loader_id: Option<String>,
47}
48
49/// A JS value as CDP's `Runtime` domain represents it.
50#[derive(Debug, Clone, Deserialize)]
51pub struct RemoteObject {
52 /// JS `typeof` of the value, e.g. `"string"`, `"object"`.
53 #[serde(rename = "type")]
54 pub object_type: String,
55 /// The value itself, present when `returnByValue: true` was requested.
56 pub value: Option<Value>,
57 /// Human-readable description Chrome generates for the value.
58 pub description: Option<String>,
59}
60
61/// Result of `Runtime.evaluate`.
62#[derive(Debug, Clone, Deserialize)]
63pub struct EvaluateResult {
64 /// The evaluated expression's value.
65 pub result: RemoteObject,
66 /// Present when the expression threw; contains Chrome's exception details.
67 #[serde(rename = "exceptionDetails")]
68 pub exception_details: Option<Value>,
69}
70
71/// A DOM node as returned by `DOM.getDocument`.
72#[derive(Debug, Clone, Deserialize, Serialize)]
73pub struct DocumentNode {
74 /// CDP node id, used by other `DOM.*` commands.
75 #[serde(rename = "nodeId")]
76 pub node_id: i64,
77 /// Node tag/name, e.g. `"HTML"` for the document element.
78 #[serde(rename = "nodeName")]
79 pub node_name: String,
80 /// Number of direct children, if known.
81 #[serde(rename = "childNodeCount")]
82 pub child_node_count: Option<i64>,
83}
84
85/// A browser cookie as returned by `Network.getCookies`.
86#[derive(Debug, Clone, Deserialize, Serialize)]
87pub struct Cookie {
88 /// Cookie name.
89 pub name: String,
90 /// Cookie value.
91 pub value: String,
92 /// Domain the cookie applies to.
93 pub domain: String,
94 /// Path the cookie applies to.
95 pub path: String,
96}
97
98/// A single metric from `Performance.getMetrics`.
99#[derive(Debug, Clone, Deserialize)]
100pub struct PerformanceMetric {
101 /// Metric name, e.g. `"JSHeapUsedSize"`.
102 pub name: String,
103 /// Metric value.
104 pub value: f64,
105}
106
107/// A `console.*` call captured via [`BrowserAgent::capture_console`](crate::agent::BrowserAgent::capture_console).
108#[derive(Debug, Clone)]
109pub struct ConsoleMessage {
110 /// Console method used, e.g. `"log"`, `"warn"`, `"error"`.
111 pub level: String,
112 /// First stringified argument passed to the console call.
113 pub text: String,
114 /// Source file the call originated from, if available.
115 pub url: Option<String>,
116 /// Source line the call originated from, if available.
117 pub line: Option<u64>,
118}