browser_commander/playwright/protocol/
route.rs1#![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#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
15pub struct RouteInitializer {
16 #[serde(rename = "request")]
17 pub request: Ref<Request>,
18}
19
20#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
22pub struct RouteRedirectNavigationRequestParams {
23 #[serde(rename = "url")]
24 pub url: String,
25}
26
27#[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#[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#[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#[derive(Debug, Clone, PartialEq)]
66pub enum RouteEvent {
67 Unknown {
69 method: String,
71 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#[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 pub async fn redirect_navigation_request(&self, params: RouteRedirectNavigationRequestParams) -> Result<(), ProtocolError> {
111 self.channel.send_no_result("redirectNavigationRequest", ¶ms).await
112 }
113
114 pub async fn abort(&self, params: RouteAbortParams) -> Result<(), ProtocolError> {
116 self.channel.send_no_result("abort", ¶ms).await
117 }
118
119 pub async fn r#continue(&self, params: RouteContinueParams) -> Result<(), ProtocolError> {
121 self.channel.send_no_result("continue", ¶ms).await
122 }
123
124 pub async fn fulfill(&self, params: RouteFulfillParams) -> Result<(), ProtocolError> {
126 self.channel.send_no_result("fulfill", ¶ms).await
127 }
128}