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/// Events a `Debugger` channel can emit.
62#[derive(Debug, Clone, PartialEq)]
63pub enum DebuggerEvent {
64    /// `Debugger.pausedStateChanged`
65    PausedStateChanged(DebuggerPausedStateChangedEventParams),
66    /// An event this binding does not know (a newer driver).
67    Unknown {
68        /// Event name.
69        method: String,
70        /// Raw event parameters.
71        params: serde_json::Value,
72    },
73}
74
75impl ProtocolEvent for DebuggerEvent {
76    fn parse(method: &str, params: serde_json::Value) -> Result<Self, serde_json::Error> {
77        match method {
78            "pausedStateChanged" => Ok(Self::PausedStateChanged(serde_json::from_value(params)?)),
79            _ => Ok(Self::Unknown { method: method.to_string(), params }),
80        }
81    }
82}
83
84/// Channel for the `Debugger` interface (`playwright.yml`).
85#[derive(Debug, Clone)]
86pub struct Debugger {
87    channel: Channel,
88}
89
90impl ChannelType for Debugger {
91    const INTERFACE: &'static str = "Debugger";
92    type Initializer = DebuggerInitializer;
93    type Event = DebuggerEvent;
94
95    fn accepts(interface: &str) -> bool {
96        matches!(interface, "Debugger")
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 Debugger {
109    /// `Debugger.requestPause` ("Pause on next call").
110    pub async fn request_pause(&self) -> Result<(), ProtocolError> {
111        self.channel.send_no_result("requestPause", &serde_json::json!({})).await
112    }
113
114    /// `Debugger.resume` ("Resume").
115    pub async fn resume(&self) -> Result<(), ProtocolError> {
116        self.channel.send_no_result("resume", &serde_json::json!({})).await
117    }
118
119    /// `Debugger.next` ("Step to next call").
120    pub async fn next(&self) -> Result<(), ProtocolError> {
121        self.channel.send_no_result("next", &serde_json::json!({})).await
122    }
123
124    /// `Debugger.runTo` ("Run to location").
125    pub async fn run_to(&self, params: DebuggerRunToParams) -> Result<(), ProtocolError> {
126        self.channel.send_no_result("runTo", &params).await
127    }
128}