Skip to main content

browser_protocol/domdebugger/
mod.rs

1//! DOM debugging allows setting breakpoints on particular DOM operations and events. JavaScript
2//! execution will stop on these operations as if there was a regular breakpoint set.
3use serde::{Serialize, Deserialize};
4use serde_json::Value as JsonValue;
5
6/// DOM breakpoint type.
7
8#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
9pub enum DOMBreakpointType {
10    #[default]
11    SubtreeModified,
12    AttributeModified,
13    NodeRemoved,
14}
15
16/// CSP Violation type.
17
18#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
19pub enum CSPViolationType {
20    #[default]
21    TrustedtypeSinkViolation,
22    TrustedtypePolicyViolation,
23}
24
25/// Object event listener.
26
27#[derive(Debug, Clone, Serialize, Deserialize, Default)]
28#[serde(rename_all = "camelCase")]
29pub struct EventListener {
30    /// 'EventListener''s type.
31
32    #[serde(rename = "type")]
33    pub type_: String,
34    /// 'EventListener''s useCapture.
35
36    pub useCapture: bool,
37    /// 'EventListener''s passive flag.
38
39    pub passive: bool,
40    /// 'EventListener''s once flag.
41
42    pub once: bool,
43    /// Script id of the handler code.
44
45    pub scriptId: crate::runtime::ScriptId,
46    /// Line number in the script (0-based).
47
48    pub lineNumber: i64,
49    /// Column number in the script (0-based).
50
51    pub columnNumber: i64,
52    /// Event handler function value.
53
54    #[serde(skip_serializing_if = "Option::is_none")]
55    pub handler: Option<crate::runtime::RemoteObject>,
56    /// Event original handler function value.
57
58    #[serde(skip_serializing_if = "Option::is_none")]
59    pub originalHandler: Option<crate::runtime::RemoteObject>,
60    /// Node the listener is added to (if any).
61
62    #[serde(skip_serializing_if = "Option::is_none")]
63    pub backendNodeId: Option<crate::dom::BackendNodeId>,
64}
65
66/// Returns event listeners of the given object.
67
68#[derive(Debug, Clone, Serialize, Deserialize, Default)]
69#[serde(rename_all = "camelCase")]
70pub struct GetEventListenersParams {
71    /// Identifier of the object to return listeners for.
72
73    pub objectId: crate::runtime::RemoteObjectId,
74    /// The maximum depth at which Node children should be retrieved, defaults to 1. Use -1 for the
75    /// entire subtree or provide an integer larger than 0.
76
77    #[serde(skip_serializing_if = "Option::is_none")]
78    pub depth: Option<i64>,
79    /// Whether or not iframes and shadow roots should be traversed when returning the subtree
80    /// (default is false). Reports listeners for all contexts if pierce is enabled.
81
82    #[serde(skip_serializing_if = "Option::is_none")]
83    pub pierce: Option<bool>,
84}
85
86/// Returns event listeners of the given object.
87
88#[derive(Debug, Clone, Serialize, Deserialize, Default)]
89#[serde(rename_all = "camelCase")]
90pub struct GetEventListenersReturns {
91    /// Array of relevant listeners.
92
93    pub listeners: Vec<EventListener>,
94}
95
96impl GetEventListenersParams { pub const METHOD: &'static str = "DOMDebugger.getEventListeners"; }
97
98impl crate::CdpCommand for GetEventListenersParams {
99    const METHOD: &'static str = "DOMDebugger.getEventListeners";
100    type Response = GetEventListenersReturns;
101}
102
103/// Removes DOM breakpoint that was set using 'setDOMBreakpoint'.
104
105#[derive(Debug, Clone, Serialize, Deserialize, Default)]
106#[serde(rename_all = "camelCase")]
107pub struct RemoveDOMBreakpointParams {
108    /// Identifier of the node to remove breakpoint from.
109
110    pub nodeId: crate::dom::NodeId,
111    /// Type of the breakpoint to remove.
112
113    #[serde(rename = "type")]
114    pub type_: DOMBreakpointType,
115}
116
117impl RemoveDOMBreakpointParams { pub const METHOD: &'static str = "DOMDebugger.removeDOMBreakpoint"; }
118
119impl crate::CdpCommand for RemoveDOMBreakpointParams {
120    const METHOD: &'static str = "DOMDebugger.removeDOMBreakpoint";
121    type Response = crate::EmptyReturns;
122}
123
124/// Removes breakpoint on particular DOM event.
125
126#[derive(Debug, Clone, Serialize, Deserialize, Default)]
127#[serde(rename_all = "camelCase")]
128pub struct RemoveEventListenerBreakpointParams {
129    /// Event name.
130
131    pub eventName: String,
132    /// EventTarget interface name.
133
134    #[serde(skip_serializing_if = "Option::is_none")]
135    pub targetName: Option<String>,
136}
137
138impl RemoveEventListenerBreakpointParams { pub const METHOD: &'static str = "DOMDebugger.removeEventListenerBreakpoint"; }
139
140impl crate::CdpCommand for RemoveEventListenerBreakpointParams {
141    const METHOD: &'static str = "DOMDebugger.removeEventListenerBreakpoint";
142    type Response = crate::EmptyReturns;
143}
144
145/// Removes breakpoint on particular native event.
146
147#[derive(Debug, Clone, Serialize, Deserialize, Default)]
148#[serde(rename_all = "camelCase")]
149pub struct RemoveInstrumentationBreakpointParams {
150    /// Instrumentation name to stop on.
151
152    pub eventName: String,
153}
154
155impl RemoveInstrumentationBreakpointParams { pub const METHOD: &'static str = "DOMDebugger.removeInstrumentationBreakpoint"; }
156
157impl crate::CdpCommand for RemoveInstrumentationBreakpointParams {
158    const METHOD: &'static str = "DOMDebugger.removeInstrumentationBreakpoint";
159    type Response = crate::EmptyReturns;
160}
161
162/// Removes breakpoint from XMLHttpRequest.
163
164#[derive(Debug, Clone, Serialize, Deserialize, Default)]
165#[serde(rename_all = "camelCase")]
166pub struct RemoveXHRBreakpointParams {
167    /// Resource URL substring.
168
169    pub url: String,
170}
171
172impl RemoveXHRBreakpointParams { pub const METHOD: &'static str = "DOMDebugger.removeXHRBreakpoint"; }
173
174impl crate::CdpCommand for RemoveXHRBreakpointParams {
175    const METHOD: &'static str = "DOMDebugger.removeXHRBreakpoint";
176    type Response = crate::EmptyReturns;
177}
178
179/// Sets breakpoint on particular CSP violations.
180
181#[derive(Debug, Clone, Serialize, Deserialize, Default)]
182#[serde(rename_all = "camelCase")]
183pub struct SetBreakOnCSPViolationParams {
184    /// CSP Violations to stop upon.
185
186    pub violationTypes: Vec<CSPViolationType>,
187}
188
189impl SetBreakOnCSPViolationParams { pub const METHOD: &'static str = "DOMDebugger.setBreakOnCSPViolation"; }
190
191impl crate::CdpCommand for SetBreakOnCSPViolationParams {
192    const METHOD: &'static str = "DOMDebugger.setBreakOnCSPViolation";
193    type Response = crate::EmptyReturns;
194}
195
196/// Sets breakpoint on particular operation with DOM.
197
198#[derive(Debug, Clone, Serialize, Deserialize, Default)]
199#[serde(rename_all = "camelCase")]
200pub struct SetDOMBreakpointParams {
201    /// Identifier of the node to set breakpoint on.
202
203    pub nodeId: crate::dom::NodeId,
204    /// Type of the operation to stop upon.
205
206    #[serde(rename = "type")]
207    pub type_: DOMBreakpointType,
208}
209
210impl SetDOMBreakpointParams { pub const METHOD: &'static str = "DOMDebugger.setDOMBreakpoint"; }
211
212impl crate::CdpCommand for SetDOMBreakpointParams {
213    const METHOD: &'static str = "DOMDebugger.setDOMBreakpoint";
214    type Response = crate::EmptyReturns;
215}
216
217/// Sets breakpoint on particular DOM event.
218
219#[derive(Debug, Clone, Serialize, Deserialize, Default)]
220#[serde(rename_all = "camelCase")]
221pub struct SetEventListenerBreakpointParams {
222    /// DOM Event name to stop on (any DOM event will do).
223
224    pub eventName: String,
225    /// EventTarget interface name to stop on. If equal to '"*"' or not provided, will stop on any
226    /// EventTarget.
227
228    #[serde(skip_serializing_if = "Option::is_none")]
229    pub targetName: Option<String>,
230}
231
232impl SetEventListenerBreakpointParams { pub const METHOD: &'static str = "DOMDebugger.setEventListenerBreakpoint"; }
233
234impl crate::CdpCommand for SetEventListenerBreakpointParams {
235    const METHOD: &'static str = "DOMDebugger.setEventListenerBreakpoint";
236    type Response = crate::EmptyReturns;
237}
238
239/// Sets breakpoint on particular native event.
240
241#[derive(Debug, Clone, Serialize, Deserialize, Default)]
242#[serde(rename_all = "camelCase")]
243pub struct SetInstrumentationBreakpointParams {
244    /// Instrumentation name to stop on.
245
246    pub eventName: String,
247}
248
249impl SetInstrumentationBreakpointParams { pub const METHOD: &'static str = "DOMDebugger.setInstrumentationBreakpoint"; }
250
251impl crate::CdpCommand for SetInstrumentationBreakpointParams {
252    const METHOD: &'static str = "DOMDebugger.setInstrumentationBreakpoint";
253    type Response = crate::EmptyReturns;
254}
255
256/// Sets breakpoint on XMLHttpRequest.
257
258#[derive(Debug, Clone, Serialize, Deserialize, Default)]
259#[serde(rename_all = "camelCase")]
260pub struct SetXHRBreakpointParams {
261    /// Resource URL substring. All XHRs having this substring in the URL will get stopped upon.
262
263    pub url: String,
264}
265
266impl SetXHRBreakpointParams { pub const METHOD: &'static str = "DOMDebugger.setXHRBreakpoint"; }
267
268impl crate::CdpCommand for SetXHRBreakpointParams {
269    const METHOD: &'static str = "DOMDebugger.setXHRBreakpoint";
270    type Response = crate::EmptyReturns;
271}