1use serde::{Deserialize, Serialize};
6use std::collections::HashMap;
7
8pub type RequestId = String;
10
11pub type LoaderId = String;
13
14pub type FrameId = String;
16
17pub type MonotonicTime = f64;
19
20pub type TimeSinceEpoch = f64;
22
23#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
25pub enum ResourceType {
26 Document,
28 Stylesheet,
30 Image,
32 Media,
34 Font,
36 Script,
38 TextTrack,
40 XHR,
42 Fetch,
44 Prefetch,
46 EventSource,
48 WebSocket,
50 Manifest,
52 SignedExchange,
54 Ping,
56 CSPViolationReport,
58 Preflight,
60 #[default]
62 Other,
63}
64
65#[derive(Debug, Clone, Deserialize)]
67#[serde(rename_all = "camelCase")]
68pub struct Request {
69 pub url: String,
71 pub method: String,
73 pub headers: HashMap<String, String>,
75 pub post_data: Option<String>,
77 pub has_post_data: Option<bool>,
79 pub mixed_content_type: Option<String>,
81 pub referrer_policy: Option<String>,
83 pub is_link_preload: Option<bool>,
85 pub initial_priority: Option<String>,
87}
88
89#[derive(Debug, Clone, Deserialize)]
91#[serde(rename_all = "camelCase")]
92pub struct Response {
93 pub url: String,
95 pub status: u32,
97 pub status_text: String,
99 pub headers: HashMap<String, String>,
101 pub headers_text: Option<String>,
103 pub mime_type: String,
105 pub request_headers: Option<HashMap<String, String>>,
107 pub request_headers_text: Option<String>,
109 pub from_disk_cache: Option<bool>,
111 pub from_prefetch_cache: Option<bool>,
113 pub from_service_worker: Option<bool>,
115 pub encoded_data_length: Option<f64>,
117 pub protocol: Option<String>,
119 pub security_state: Option<String>,
121 pub security_details: Option<SecurityDetails>,
123 #[serde(rename = "remoteIPAddress")]
125 pub remote_ip_address: Option<String>,
126 pub remote_port: Option<i32>,
128}
129
130#[derive(Debug, Clone, Serialize, Default)]
132#[serde(rename_all = "camelCase")]
133pub struct EnableParams {
134 #[serde(skip_serializing_if = "Option::is_none")]
136 pub max_total_buffer_size: Option<i64>,
137 #[serde(skip_serializing_if = "Option::is_none")]
139 pub max_resource_buffer_size: Option<i64>,
140 #[serde(skip_serializing_if = "Option::is_none")]
142 pub max_post_data_size: Option<i64>,
143}
144
145#[derive(Debug, Clone, Deserialize)]
147#[serde(rename_all = "camelCase")]
148pub struct RequestWillBeSentEvent {
149 pub request_id: RequestId,
151 pub loader_id: LoaderId,
153 #[serde(default)]
155 pub document_url: Option<String>,
156 pub request: Request,
158 pub timestamp: f64,
160 pub wall_time: f64,
162 pub initiator: RequestInitiator,
164 pub frame_id: Option<FrameId>,
166 pub has_user_gesture: Option<bool>,
168 #[serde(rename = "type")]
170 pub resource_type: Option<String>,
171 pub redirect_response: Option<Response>,
173}
174
175#[derive(Debug, Clone, Deserialize)]
177#[serde(rename_all = "camelCase")]
178pub struct RequestInitiator {
179 #[serde(rename = "type")]
181 pub initiator_type: String,
182 pub url: Option<String>,
184 pub line_number: Option<f64>,
186 pub column_number: Option<f64>,
188}
189
190#[derive(Debug, Clone, Deserialize)]
192#[serde(rename_all = "camelCase")]
193pub struct ResponseReceivedEvent {
194 pub request_id: RequestId,
196 pub loader_id: LoaderId,
198 pub timestamp: f64,
200 #[serde(rename = "type")]
202 pub resource_type: String,
203 pub response: Response,
205 pub frame_id: Option<FrameId>,
207}
208
209#[derive(Debug, Clone, Deserialize)]
211#[serde(rename_all = "camelCase")]
212pub struct LoadingFinishedEvent {
213 pub request_id: RequestId,
215 pub timestamp: f64,
217 pub encoded_data_length: f64,
219}
220
221#[derive(Debug, Clone, Deserialize)]
223#[serde(rename_all = "camelCase")]
224pub struct LoadingFailedEvent {
225 pub request_id: RequestId,
227 pub timestamp: f64,
229 #[serde(rename = "type")]
231 pub resource_type: String,
232 pub error_text: String,
234 pub canceled: Option<bool>,
236 pub blocked_reason: Option<String>,
238}
239
240#[derive(Debug, Clone, Deserialize)]
242#[serde(rename_all = "camelCase")]
243pub struct RequestServedFromCacheEvent {
244 pub request_id: RequestId,
246}
247
248#[derive(Debug, Clone, Deserialize)]
250#[serde(rename_all = "camelCase")]
251pub struct ResourceTiming {
252 pub request_time: f64,
254 pub proxy_start: f64,
256 pub proxy_end: f64,
258 pub dns_start: f64,
260 pub dns_end: f64,
262 pub connect_start: f64,
264 pub connect_end: f64,
266 pub ssl_start: f64,
268 pub ssl_end: f64,
270 pub send_start: f64,
272 pub send_end: f64,
274 pub receive_headers_start: Option<f64>,
276 pub receive_headers_end: Option<f64>,
278}
279
280#[derive(Debug, Clone, Deserialize)]
282#[serde(rename_all = "camelCase")]
283pub struct SecurityDetails {
284 pub protocol: String,
286 pub key_exchange: String,
288 pub key_exchange_group: Option<String>,
290 pub cipher: String,
292 pub mac: Option<String>,
294 pub subject_name: String,
296 pub san_list: Vec<String>,
298 pub issuer: String,
300 pub valid_from: TimeSinceEpoch,
302 pub valid_to: TimeSinceEpoch,
304}
305
306#[derive(Debug, Clone, Serialize)]
308#[serde(rename_all = "camelCase")]
309pub struct GetResponseBodyParams {
310 pub request_id: RequestId,
312}
313
314#[derive(Debug, Clone, Deserialize)]
316#[serde(rename_all = "camelCase")]
317pub struct GetResponseBodyResult {
318 pub body: String,
320 pub base64_encoded: bool,
322}
323
324#[derive(Debug, Clone, Serialize)]
326#[serde(rename_all = "camelCase")]
327pub struct SetExtraHTTPHeadersParams {
328 pub headers: HashMap<String, String>,
330}
331
332#[derive(Debug, Clone, Serialize)]
334#[serde(rename_all = "camelCase")]
335pub struct SetCacheDisabledParams {
336 pub cache_disabled: bool,
338}
339
340#[derive(Debug, Clone, Serialize)]
342#[serde(rename_all = "camelCase")]
343pub struct SetBypassServiceWorkerParams {
344 pub bypass: bool,
346}
347
348#[derive(Debug, Clone, Serialize)]
354#[serde(rename_all = "camelCase")]
355pub struct EmulateNetworkConditionsParams {
356 pub offline: bool,
358 pub latency: f64,
360 pub download_throughput: f64,
362 pub upload_throughput: f64,
364 #[serde(skip_serializing_if = "Option::is_none")]
366 pub connection_type: Option<ConnectionType>,
367}
368
369impl EmulateNetworkConditionsParams {
370 pub fn offline() -> Self {
372 Self {
373 offline: true,
374 latency: 0.0,
375 download_throughput: -1.0,
376 upload_throughput: -1.0,
377 connection_type: None,
378 }
379 }
380
381 pub fn online() -> Self {
383 Self {
384 offline: false,
385 latency: 0.0,
386 download_throughput: -1.0,
387 upload_throughput: -1.0,
388 connection_type: None,
389 }
390 }
391}
392
393#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
395#[serde(rename_all = "lowercase")]
396pub enum ConnectionType {
397 None,
399 Cellular2g,
401 Cellular3g,
403 Cellular4g,
405 Bluetooth,
407 Ethernet,
409 Wifi,
411 Wimax,
413 Other,
415}