Skip to main content

browser_commander/playwright/protocol/
route.rs

1// @generated by scripts/generate-playwright-protocol.mjs from
2// rust/protocol/playwright/*.yml. Do not edit by hand.
3
4#![allow(clippy::all, missing_docs, unused_imports)]
5
6use serde::{Deserialize, Serialize};
7
8use super::*;
9use crate::playwright::connection::{
10    Binary, Channel, ChannelType, ObjectRef, ProtocolError, ProtocolEvent, Ref,
11};
12
13/// Initializer the driver sends when it creates a `Route`.
14#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
15pub struct RouteInitializer {
16    #[serde(rename = "request")]
17    pub request: Ref<Request>,
18}
19
20/// Parameters of `Route.redirectNavigationRequest`.
21#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
22pub struct RouteRedirectNavigationRequestParams {
23    #[serde(rename = "url")]
24    pub url: String,
25}
26
27/// Parameters of `Route.abort` (Abort request).
28#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
29pub struct RouteAbortParams {
30    #[serde(rename = "errorCode", default, skip_serializing_if = "Option::is_none")]
31    pub error_code: Option<String>,
32}
33
34/// Parameters of `Route.continue` (Continue request).
35#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
36pub struct RouteContinueParams {
37    #[serde(rename = "url", default, skip_serializing_if = "Option::is_none")]
38    pub url: Option<String>,
39    #[serde(rename = "method", default, skip_serializing_if = "Option::is_none")]
40    pub method: Option<String>,
41    #[serde(rename = "headers", default, skip_serializing_if = "Option::is_none")]
42    pub headers: Option<Vec<NameValue>>,
43    #[serde(rename = "postData", default, skip_serializing_if = "Option::is_none")]
44    pub post_data: Option<Binary>,
45    #[serde(rename = "isFallback")]
46    pub is_fallback: bool,
47}
48
49/// Parameters of `Route.fulfill` (Fulfill request).
50#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
51pub struct RouteFulfillParams {
52    #[serde(rename = "status", default, skip_serializing_if = "Option::is_none")]
53    pub status: Option<i64>,
54    #[serde(rename = "headers", default, skip_serializing_if = "Option::is_none")]
55    pub headers: Option<Vec<NameValue>>,
56    #[serde(rename = "body", default, skip_serializing_if = "Option::is_none")]
57    pub body: Option<String>,
58    #[serde(rename = "isBase64", default, skip_serializing_if = "Option::is_none")]
59    pub is_base64: Option<bool>,
60    #[serde(rename = "fetchResponseUid", default, skip_serializing_if = "Option::is_none")]
61    pub fetch_response_uid: Option<String>,
62}
63
64/// Events a `Route` channel can emit.
65#[derive(Debug, Clone, PartialEq)]
66pub enum RouteEvent {
67    /// An event this binding does not know (a newer driver).
68    Unknown {
69        /// Event name.
70        method: String,
71        /// Raw event parameters.
72        params: serde_json::Value,
73    },
74}
75
76impl ProtocolEvent for RouteEvent {
77    fn parse(method: &str, params: serde_json::Value) -> Result<Self, serde_json::Error> {
78        match method {
79            _ => Ok(Self::Unknown { method: method.to_string(), params }),
80        }
81    }
82}
83
84/// Channel for the `Route` interface (`network.yml`).
85#[derive(Debug, Clone)]
86pub struct Route {
87    channel: Channel,
88}
89
90impl ChannelType for Route {
91    const INTERFACE: &'static str = "Route";
92    type Initializer = RouteInitializer;
93    type Event = RouteEvent;
94
95    fn accepts(interface: &str) -> bool {
96        matches!(interface, "Route")
97    }
98
99    fn from_channel(channel: Channel) -> Self {
100        Self { channel }
101    }
102
103    fn channel(&self) -> &Channel {
104        &self.channel
105    }
106}
107
108impl Route {
109    /// `Route.redirectNavigationRequest` (internal).
110    pub async fn redirect_navigation_request(&self, params: RouteRedirectNavigationRequestParams) -> Result<(), ProtocolError> {
111        self.channel.send_no_result("redirectNavigationRequest", &params).await
112    }
113
114    /// `Route.abort` ("Abort request").
115    pub async fn abort(&self, params: RouteAbortParams) -> Result<(), ProtocolError> {
116        self.channel.send_no_result("abort", &params).await
117    }
118
119    /// `Route.continue` ("Continue request").
120    pub async fn r#continue(&self, params: RouteContinueParams) -> Result<(), ProtocolError> {
121        self.channel.send_no_result("continue", &params).await
122    }
123
124    /// `Route.fulfill` ("Fulfill request").
125    pub async fn fulfill(&self, params: RouteFulfillParams) -> Result<(), ProtocolError> {
126        self.channel.send_no_result("fulfill", &params).await
127    }
128}