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)]
25#[derive(Default)]
26pub enum ResourceType {
27 Document,
29 Stylesheet,
31 Image,
33 Media,
35 Font,
37 Script,
39 TextTrack,
41 XHR,
43 Fetch,
45 Prefetch,
47 EventSource,
49 WebSocket,
51 Manifest,
53 SignedExchange,
55 Ping,
57 CSPViolationReport,
59 Preflight,
61 #[default]
63 Other,
64}
65
66
67#[derive(Debug, Clone, Deserialize)]
69#[serde(rename_all = "camelCase")]
70pub struct Request {
71 pub url: String,
73 pub method: String,
75 pub headers: HashMap<String, String>,
77 pub post_data: Option<String>,
79 pub has_post_data: Option<bool>,
81 pub mixed_content_type: Option<String>,
83 pub referrer_policy: Option<String>,
85 pub is_link_preload: Option<bool>,
87 pub initial_priority: Option<String>,
89}
90
91#[derive(Debug, Clone, Deserialize)]
93#[serde(rename_all = "camelCase")]
94pub struct Response {
95 pub url: String,
97 pub status: u32,
99 pub status_text: String,
101 pub headers: HashMap<String, String>,
103 pub headers_text: Option<String>,
105 pub mime_type: String,
107 pub request_headers: Option<HashMap<String, String>>,
109 pub request_headers_text: Option<String>,
111 pub from_disk_cache: Option<bool>,
113 pub from_prefetch_cache: Option<bool>,
115 pub from_service_worker: Option<bool>,
117 pub encoded_data_length: Option<f64>,
119 pub protocol: Option<String>,
121 pub security_state: Option<String>,
123 pub security_details: Option<SecurityDetails>,
125 #[serde(rename = "remoteIPAddress")]
127 pub remote_ip_address: Option<String>,
128 pub remote_port: Option<i32>,
130}
131
132#[derive(Debug, Clone, Serialize, Default)]
134#[serde(rename_all = "camelCase")]
135pub struct EnableParams {
136 #[serde(skip_serializing_if = "Option::is_none")]
138 pub max_total_buffer_size: Option<i64>,
139 #[serde(skip_serializing_if = "Option::is_none")]
141 pub max_resource_buffer_size: Option<i64>,
142 #[serde(skip_serializing_if = "Option::is_none")]
144 pub max_post_data_size: Option<i64>,
145}
146
147#[derive(Debug, Clone, Deserialize)]
149#[serde(rename_all = "camelCase")]
150pub struct RequestWillBeSentEvent {
151 pub request_id: RequestId,
153 pub loader_id: LoaderId,
155 #[serde(default)]
157 pub document_url: Option<String>,
158 pub request: Request,
160 pub timestamp: f64,
162 pub wall_time: f64,
164 pub initiator: RequestInitiator,
166 pub frame_id: Option<FrameId>,
168 pub has_user_gesture: Option<bool>,
170 #[serde(rename = "type")]
172 pub resource_type: Option<String>,
173 pub redirect_response: Option<Response>,
175}
176
177#[derive(Debug, Clone, Deserialize)]
179#[serde(rename_all = "camelCase")]
180pub struct RequestInitiator {
181 #[serde(rename = "type")]
183 pub initiator_type: String,
184 pub url: Option<String>,
186 pub line_number: Option<f64>,
188 pub column_number: Option<f64>,
190}
191
192#[derive(Debug, Clone, Deserialize)]
194#[serde(rename_all = "camelCase")]
195pub struct ResponseReceivedEvent {
196 pub request_id: RequestId,
198 pub loader_id: LoaderId,
200 pub timestamp: f64,
202 #[serde(rename = "type")]
204 pub resource_type: String,
205 pub response: Response,
207 pub frame_id: Option<FrameId>,
209}
210
211#[derive(Debug, Clone, Deserialize)]
213#[serde(rename_all = "camelCase")]
214pub struct LoadingFinishedEvent {
215 pub request_id: RequestId,
217 pub timestamp: f64,
219 pub encoded_data_length: f64,
221}
222
223#[derive(Debug, Clone, Deserialize)]
225#[serde(rename_all = "camelCase")]
226pub struct LoadingFailedEvent {
227 pub request_id: RequestId,
229 pub timestamp: f64,
231 #[serde(rename = "type")]
233 pub resource_type: String,
234 pub error_text: String,
236 pub canceled: Option<bool>,
238 pub blocked_reason: Option<String>,
240}
241
242#[derive(Debug, Clone, Deserialize)]
244#[serde(rename_all = "camelCase")]
245pub struct RequestServedFromCacheEvent {
246 pub request_id: RequestId,
248}
249
250#[derive(Debug, Clone, Deserialize)]
252#[serde(rename_all = "camelCase")]
253pub struct ResourceTiming {
254 pub request_time: f64,
256 pub proxy_start: f64,
258 pub proxy_end: f64,
260 pub dns_start: f64,
262 pub dns_end: f64,
264 pub connect_start: f64,
266 pub connect_end: f64,
268 pub ssl_start: f64,
270 pub ssl_end: f64,
272 pub send_start: f64,
274 pub send_end: f64,
276 pub receive_headers_start: Option<f64>,
278 pub receive_headers_end: Option<f64>,
280}
281
282#[derive(Debug, Clone, Deserialize)]
284#[serde(rename_all = "camelCase")]
285pub struct SecurityDetails {
286 pub protocol: String,
288 pub key_exchange: String,
290 pub key_exchange_group: Option<String>,
292 pub cipher: String,
294 pub mac: Option<String>,
296 pub subject_name: String,
298 pub san_list: Vec<String>,
300 pub issuer: String,
302 pub valid_from: TimeSinceEpoch,
304 pub valid_to: TimeSinceEpoch,
306}
307
308#[derive(Debug, Clone, Serialize)]
310#[serde(rename_all = "camelCase")]
311pub struct GetResponseBodyParams {
312 pub request_id: RequestId,
314}
315
316#[derive(Debug, Clone, Deserialize)]
318#[serde(rename_all = "camelCase")]
319pub struct GetResponseBodyResult {
320 pub body: String,
322 pub base64_encoded: bool,
324}
325
326#[derive(Debug, Clone, Serialize)]
328#[serde(rename_all = "camelCase")]
329pub struct SetExtraHTTPHeadersParams {
330 pub headers: HashMap<String, String>,
332}
333
334#[derive(Debug, Clone, Serialize)]
336#[serde(rename_all = "camelCase")]
337pub struct SetCacheDisabledParams {
338 pub cache_disabled: bool,
340}
341
342#[derive(Debug, Clone, Serialize)]
344#[serde(rename_all = "camelCase")]
345pub struct SetBypassServiceWorkerParams {
346 pub bypass: bool,
348}
349
350#[derive(Debug, Clone, Serialize)]
356#[serde(rename_all = "camelCase")]
357pub struct EmulateNetworkConditionsParams {
358 pub offline: bool,
360 pub latency: f64,
362 pub download_throughput: f64,
364 pub upload_throughput: f64,
366 #[serde(skip_serializing_if = "Option::is_none")]
368 pub connection_type: Option<ConnectionType>,
369}
370
371impl EmulateNetworkConditionsParams {
372 pub fn offline() -> Self {
374 Self {
375 offline: true,
376 latency: 0.0,
377 download_throughput: -1.0,
378 upload_throughput: -1.0,
379 connection_type: None,
380 }
381 }
382
383 pub fn online() -> Self {
385 Self {
386 offline: false,
387 latency: 0.0,
388 download_throughput: -1.0,
389 upload_throughput: -1.0,
390 connection_type: None,
391 }
392 }
393}
394
395#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
397#[serde(rename_all = "lowercase")]
398pub enum ConnectionType {
399 None,
401 Cellular2g,
403 Cellular3g,
405 Cellular4g,
407 Bluetooth,
409 Ethernet,
411 Wifi,
413 Wimax,
415 Other,
417}