browser_commander/playwright/protocol/
debugger.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 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#[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#[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, PartialEq)]
63pub enum DebuggerEvent {
64 PausedStateChanged(DebuggerPausedStateChangedEventParams),
66 Unknown {
68 method: String,
70 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#[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 pub async fn request_pause(&self) -> Result<(), ProtocolError> {
111 self.channel.send_no_result("requestPause", &serde_json::json!({})).await
112 }
113
114 pub async fn resume(&self) -> Result<(), ProtocolError> {
116 self.channel.send_no_result("resume", &serde_json::json!({})).await
117 }
118
119 pub async fn next(&self) -> Result<(), ProtocolError> {
121 self.channel.send_no_result("next", &serde_json::json!({})).await
122 }
123
124 pub async fn run_to(&self, params: DebuggerRunToParams) -> Result<(), ProtocolError> {
126 self.channel.send_no_result("runTo", ¶ms).await
127 }
128}