Skip to main content

browser_commander/playwright/protocol/
debugger.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 `Debugger`.
14#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
15pub struct DebuggerInitializer {}
16
17#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
18pub struct DebuggerRunToParamsLocation {
19    #[serde(rename = "file")]
20    pub file: String,
21    #[serde(rename = "line", default, skip_serializing_if = "Option::is_none")]
22    pub line: Option<i64>,
23    #[serde(rename = "column", default, skip_serializing_if = "Option::is_none")]
24    pub column: Option<i64>,
25}
26
27/// Parameters of `Debugger.runTo` (Run to location).
28#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
29pub struct DebuggerRunToParams {
30    #[serde(rename = "location")]
31    pub location: DebuggerRunToParamsLocation,
32}
33
34#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
35pub struct DebuggerPausedStateChangedEventParamsPausedDetailsLocation {
36    #[serde(rename = "file")]
37    pub file: String,
38    #[serde(rename = "line", default, skip_serializing_if = "Option::is_none")]
39    pub line: Option<i64>,
40    #[serde(rename = "column", default, skip_serializing_if = "Option::is_none")]
41    pub column: Option<i64>,
42}
43
44#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
45pub struct DebuggerPausedStateChangedEventParamsPausedDetails {
46    #[serde(rename = "location")]
47    pub location: DebuggerPausedStateChangedEventParamsPausedDetailsLocation,
48    #[serde(rename = "title")]
49    pub title: String,
50    #[serde(rename = "stack", default, skip_serializing_if = "Option::is_none")]
51    pub stack: Option<String>,
52}
53
54/// Payload of the `Debugger.pausedStateChanged` event.
55#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
56pub struct DebuggerPausedStateChangedEventParams {
57    #[serde(rename = "pausedDetails", default, skip_serializing_if = "Option::is_none")]
58    pub paused_details: Option<DebuggerPausedStateChangedEventParamsPausedDetails>,
59}
60
61#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
62pub struct DebuggerApiCallsUpdatedEventParamsApiCallsLocation {
63    #[serde(rename = "file")]
64    pub file: String,
65    #[serde(rename = "line", default, skip_serializing_if = "Option::is_none")]
66    pub line: Option<i64>,
67    #[serde(rename = "column", default, skip_serializing_if = "Option::is_none")]
68    pub column: Option<i64>,
69}
70
71#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
72pub enum DebuggerApiCallsUpdatedEventParamsApiCallsStatus {
73    #[default]
74    #[serde(rename = "running")]
75    Running,
76    #[serde(rename = "success")]
77    Success,
78    #[serde(rename = "error")]
79    Error,
80}
81
82#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
83pub struct DebuggerApiCallsUpdatedEventParamsApiCalls {
84    #[serde(rename = "id")]
85    pub id: String,
86    #[serde(rename = "title")]
87    pub title: String,
88    #[serde(rename = "location", default, skip_serializing_if = "Option::is_none")]
89    pub location: Option<DebuggerApiCallsUpdatedEventParamsApiCallsLocation>,
90    #[serde(rename = "newLogEntries")]
91    pub new_log_entries: Vec<String>,
92    #[serde(rename = "actionPoint", default, skip_serializing_if = "Option::is_none")]
93    pub action_point: Option<Point>,
94    #[serde(rename = "status")]
95    pub status: DebuggerApiCallsUpdatedEventParamsApiCallsStatus,
96    #[serde(rename = "error", default, skip_serializing_if = "Option::is_none")]
97    pub error: Option<String>,
98}
99
100/// Payload of the `Debugger.apiCallsUpdated` event.
101#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
102pub struct DebuggerApiCallsUpdatedEventParams {
103    #[serde(rename = "apiCalls")]
104    pub api_calls: Vec<DebuggerApiCallsUpdatedEventParamsApiCalls>,
105}
106
107/// Events a `Debugger` channel can emit.
108#[derive(Debug, Clone, PartialEq)]
109pub enum DebuggerEvent {
110    /// `Debugger.pausedStateChanged`
111    PausedStateChanged(DebuggerPausedStateChangedEventParams),
112    /// `Debugger.apiCallsUpdated`
113    ApiCallsUpdated(DebuggerApiCallsUpdatedEventParams),
114    /// An event this binding does not know (a newer driver).
115    Unknown {
116        /// Event name.
117        method: String,
118        /// Raw event parameters.
119        params: serde_json::Value,
120    },
121}
122
123impl ProtocolEvent for DebuggerEvent {
124    fn parse(method: &str, params: serde_json::Value) -> Result<Self, serde_json::Error> {
125        match method {
126            "pausedStateChanged" => Ok(Self::PausedStateChanged(serde_json::from_value(params)?)),
127            "apiCallsUpdated" => Ok(Self::ApiCallsUpdated(serde_json::from_value(params)?)),
128            _ => Ok(Self::Unknown { method: method.to_string(), params }),
129        }
130    }
131}
132
133/// Channel for the `Debugger` interface (`playwright.yml`).
134#[derive(Debug, Clone)]
135pub struct Debugger {
136    channel: Channel,
137}
138
139impl ChannelType for Debugger {
140    const INTERFACE: &'static str = "Debugger";
141    type Initializer = DebuggerInitializer;
142    type Event = DebuggerEvent;
143
144    fn accepts(interface: &str) -> bool {
145        matches!(interface, "Debugger")
146    }
147
148    fn from_channel(channel: Channel) -> Self {
149        Self { channel }
150    }
151
152    fn channel(&self) -> &Channel {
153        &self.channel
154    }
155}
156
157impl Debugger {
158    /// `Debugger.requestPause` ("Pause on next call").
159    pub async fn request_pause(&self) -> Result<(), ProtocolError> {
160        self.channel.send_no_result("requestPause", &serde_json::json!({})).await
161    }
162
163    /// `Debugger.resume` ("Resume").
164    pub async fn resume(&self) -> Result<(), ProtocolError> {
165        self.channel.send_no_result("resume", &serde_json::json!({})).await
166    }
167
168    /// `Debugger.next` ("Step to next call").
169    pub async fn next(&self) -> Result<(), ProtocolError> {
170        self.channel.send_no_result("next", &serde_json::json!({})).await
171    }
172
173    /// `Debugger.runTo` ("Run to location").
174    pub async fn run_to(&self, params: DebuggerRunToParams) -> Result<(), ProtocolError> {
175        self.channel.send_no_result("runTo", &params).await
176    }
177
178    /// `Debugger.enable` (internal).
179    pub async fn enable(&self) -> Result<(), ProtocolError> {
180        self.channel.send_no_result("enable", &serde_json::json!({})).await
181    }
182}