use serde::{Deserialize, Serialize};
use std::collections::HashMap;
pub type RequestId = String;
pub type LoaderId = String;
pub type FrameId = String;
pub type MonotonicTime = f64;
pub type TimeSinceEpoch = f64;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
pub enum ResourceType {
Document,
Stylesheet,
Image,
Media,
Font,
Script,
TextTrack,
XHR,
Fetch,
Prefetch,
EventSource,
WebSocket,
Manifest,
SignedExchange,
Ping,
CSPViolationReport,
Preflight,
#[default]
Other,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Request {
pub url: String,
pub method: String,
pub headers: HashMap<String, String>,
pub post_data: Option<String>,
pub has_post_data: Option<bool>,
pub mixed_content_type: Option<String>,
pub referrer_policy: Option<String>,
pub is_link_preload: Option<bool>,
pub initial_priority: Option<String>,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Response {
pub url: String,
pub status: u32,
pub status_text: String,
pub headers: HashMap<String, String>,
pub headers_text: Option<String>,
pub mime_type: String,
pub request_headers: Option<HashMap<String, String>>,
pub request_headers_text: Option<String>,
pub from_disk_cache: Option<bool>,
pub from_prefetch_cache: Option<bool>,
pub from_service_worker: Option<bool>,
pub encoded_data_length: Option<f64>,
pub protocol: Option<String>,
pub security_state: Option<String>,
pub security_details: Option<SecurityDetails>,
#[serde(rename = "remoteIPAddress")]
pub remote_ip_address: Option<String>,
pub remote_port: Option<i32>,
}
#[derive(Debug, Clone, Serialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct EnableParams {
#[serde(skip_serializing_if = "Option::is_none")]
pub max_total_buffer_size: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub max_resource_buffer_size: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub max_post_data_size: Option<i64>,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RequestWillBeSentEvent {
pub request_id: RequestId,
pub loader_id: LoaderId,
#[serde(default)]
pub document_url: Option<String>,
pub request: Request,
pub timestamp: f64,
pub wall_time: f64,
pub initiator: RequestInitiator,
pub frame_id: Option<FrameId>,
pub has_user_gesture: Option<bool>,
#[serde(rename = "type")]
pub resource_type: Option<String>,
pub redirect_response: Option<Response>,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RequestInitiator {
#[serde(rename = "type")]
pub initiator_type: String,
pub url: Option<String>,
pub line_number: Option<f64>,
pub column_number: Option<f64>,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ResponseReceivedEvent {
pub request_id: RequestId,
pub loader_id: LoaderId,
pub timestamp: f64,
#[serde(rename = "type")]
pub resource_type: String,
pub response: Response,
pub frame_id: Option<FrameId>,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct LoadingFinishedEvent {
pub request_id: RequestId,
pub timestamp: f64,
pub encoded_data_length: f64,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct LoadingFailedEvent {
pub request_id: RequestId,
pub timestamp: f64,
#[serde(rename = "type")]
pub resource_type: String,
pub error_text: String,
pub canceled: Option<bool>,
pub blocked_reason: Option<String>,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RequestServedFromCacheEvent {
pub request_id: RequestId,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ResourceTiming {
pub request_time: f64,
pub proxy_start: f64,
pub proxy_end: f64,
pub dns_start: f64,
pub dns_end: f64,
pub connect_start: f64,
pub connect_end: f64,
pub ssl_start: f64,
pub ssl_end: f64,
pub send_start: f64,
pub send_end: f64,
pub receive_headers_start: Option<f64>,
pub receive_headers_end: Option<f64>,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SecurityDetails {
pub protocol: String,
pub key_exchange: String,
pub key_exchange_group: Option<String>,
pub cipher: String,
pub mac: Option<String>,
pub subject_name: String,
pub san_list: Vec<String>,
pub issuer: String,
pub valid_from: TimeSinceEpoch,
pub valid_to: TimeSinceEpoch,
}
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct GetResponseBodyParams {
pub request_id: RequestId,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct GetResponseBodyResult {
pub body: String,
pub base64_encoded: bool,
}
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SetExtraHTTPHeadersParams {
pub headers: HashMap<String, String>,
}
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SetCacheDisabledParams {
pub cache_disabled: bool,
}
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SetBypassServiceWorkerParams {
pub bypass: bool,
}
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct EmulateNetworkConditionsParams {
pub offline: bool,
pub latency: f64,
pub download_throughput: f64,
pub upload_throughput: f64,
#[serde(skip_serializing_if = "Option::is_none")]
pub connection_type: Option<ConnectionType>,
}
impl EmulateNetworkConditionsParams {
pub fn offline() -> Self {
Self {
offline: true,
latency: 0.0,
download_throughput: -1.0,
upload_throughput: -1.0,
connection_type: None,
}
}
pub fn online() -> Self {
Self {
offline: false,
latency: 0.0,
download_throughput: -1.0,
upload_throughput: -1.0,
connection_type: None,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum ConnectionType {
None,
Cellular2g,
Cellular3g,
Cellular4g,
Bluetooth,
Ethernet,
Wifi,
Wimax,
Other,
}