browser_commander/playwright/protocol/
debug_controller.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 DebugControllerInitializer {}
16
17#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
19pub struct DebugControllerInitializeParams {
20 #[serde(rename = "codegenId")]
21 pub codegen_id: String,
22 #[serde(rename = "sdkLanguage")]
23 pub sdk_language: SDKLanguage,
24}
25
26#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
28pub struct DebugControllerSetReportStateChangedParams {
29 #[serde(rename = "enabled")]
30 pub enabled: bool,
31}
32
33#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
34pub enum DebugControllerSetRecorderModeParamsMode {
35 #[default]
36 #[serde(rename = "inspecting")]
37 Inspecting,
38 #[serde(rename = "recording")]
39 Recording,
40 #[serde(rename = "none")]
41 None,
42}
43
44#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
46pub struct DebugControllerSetRecorderModeParams {
47 #[serde(rename = "mode")]
48 pub mode: DebugControllerSetRecorderModeParamsMode,
49 #[serde(rename = "testIdAttributeName", default, skip_serializing_if = "Option::is_none")]
50 pub test_id_attribute_name: Option<String>,
51 #[serde(rename = "generateAutoExpect", default, skip_serializing_if = "Option::is_none")]
52 pub generate_auto_expect: Option<bool>,
53}
54
55#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
57pub struct DebugControllerHighlightParams {
58 #[serde(rename = "selector", default, skip_serializing_if = "Option::is_none")]
59 pub selector: Option<String>,
60 #[serde(rename = "ariaTemplate", default, skip_serializing_if = "Option::is_none")]
61 pub aria_template: Option<String>,
62}
63
64#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
66pub struct DebugControllerInspectRequestedEventParams {
67 #[serde(rename = "selector")]
68 pub selector: String,
69 #[serde(rename = "locator")]
70 pub locator: String,
71 #[serde(rename = "ariaSnapshot")]
72 pub aria_snapshot: String,
73}
74
75#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
77pub struct DebugControllerSetModeRequestedEventParams {
78 #[serde(rename = "mode")]
79 pub mode: String,
80}
81
82#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
84pub struct DebugControllerStateChangedEventParams {
85 #[serde(rename = "pageCount")]
86 pub page_count: i64,
87}
88
89#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
91pub struct DebugControllerSourceChangedEventParams {
92 #[serde(rename = "text")]
93 pub text: String,
94 #[serde(rename = "header", default, skip_serializing_if = "Option::is_none")]
95 pub header: Option<String>,
96 #[serde(rename = "footer", default, skip_serializing_if = "Option::is_none")]
97 pub footer: Option<String>,
98 #[serde(rename = "actions", default, skip_serializing_if = "Option::is_none")]
99 pub actions: Option<Vec<String>>,
100}
101
102#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
104pub struct DebugControllerPausedEventParams {
105 #[serde(rename = "paused")]
106 pub paused: bool,
107}
108
109#[derive(Debug, Clone, PartialEq)]
111pub enum DebugControllerEvent {
112 InspectRequested(DebugControllerInspectRequestedEventParams),
114 SetModeRequested(DebugControllerSetModeRequestedEventParams),
116 StateChanged(DebugControllerStateChangedEventParams),
118 SourceChanged(DebugControllerSourceChangedEventParams),
120 Paused(DebugControllerPausedEventParams),
122 Unknown {
124 method: String,
126 params: serde_json::Value,
128 },
129}
130
131impl ProtocolEvent for DebugControllerEvent {
132 fn parse(method: &str, params: serde_json::Value) -> Result<Self, serde_json::Error> {
133 match method {
134 "inspectRequested" => Ok(Self::InspectRequested(serde_json::from_value(params)?)),
135 "setModeRequested" => Ok(Self::SetModeRequested(serde_json::from_value(params)?)),
136 "stateChanged" => Ok(Self::StateChanged(serde_json::from_value(params)?)),
137 "sourceChanged" => Ok(Self::SourceChanged(serde_json::from_value(params)?)),
138 "paused" => Ok(Self::Paused(serde_json::from_value(params)?)),
139 _ => Ok(Self::Unknown { method: method.to_string(), params }),
140 }
141 }
142}
143
144#[derive(Debug, Clone)]
146pub struct DebugController {
147 channel: Channel,
148}
149
150impl ChannelType for DebugController {
151 const INTERFACE: &'static str = "DebugController";
152 type Initializer = DebugControllerInitializer;
153 type Event = DebugControllerEvent;
154
155 fn accepts(interface: &str) -> bool {
156 matches!(interface, "DebugController")
157 }
158
159 fn from_channel(channel: Channel) -> Self {
160 Self { channel }
161 }
162
163 fn channel(&self) -> &Channel {
164 &self.channel
165 }
166}
167
168impl DebugController {
169 pub async fn initialize(&self, params: DebugControllerInitializeParams) -> Result<(), ProtocolError> {
171 self.channel.send_no_result("initialize", ¶ms).await
172 }
173
174 pub async fn set_report_state_changed(&self, params: DebugControllerSetReportStateChangedParams) -> Result<(), ProtocolError> {
176 self.channel.send_no_result("setReportStateChanged", ¶ms).await
177 }
178
179 pub async fn set_recorder_mode(&self, params: DebugControllerSetRecorderModeParams) -> Result<(), ProtocolError> {
181 self.channel.send_no_result("setRecorderMode", ¶ms).await
182 }
183
184 pub async fn highlight(&self, params: DebugControllerHighlightParams) -> Result<(), ProtocolError> {
186 self.channel.send_no_result("highlight", ¶ms).await
187 }
188
189 pub async fn hide_highlight(&self) -> Result<(), ProtocolError> {
191 self.channel.send_no_result("hideHighlight", &serde_json::json!({})).await
192 }
193
194 pub async fn resume(&self) -> Result<(), ProtocolError> {
196 self.channel.send_no_result("resume", &serde_json::json!({})).await
197 }
198
199 pub async fn kill(&self) -> Result<(), ProtocolError> {
201 self.channel.send_no_result("kill", &serde_json::json!({})).await
202 }
203}