browser_protocol/domsnapshot/mod.rs
1//! This domain facilitates obtaining document snapshots with DOM, layout, and style information.
2use serde::{Serialize, Deserialize};
3use serde_json::Value as JsonValue;
4
5/// A Node in the DOM tree.
6
7#[derive(Debug, Clone, Serialize, Deserialize, Default)]
8#[serde(rename_all = "camelCase")]
9pub struct DOMNode {
10 /// 'Node''s nodeType.
11
12 pub nodeType: i64,
13 /// 'Node''s nodeName.
14
15 pub nodeName: String,
16 /// 'Node''s nodeValue.
17
18 pub nodeValue: String,
19 /// Only set for textarea elements, contains the text value.
20
21 #[serde(skip_serializing_if = "Option::is_none")]
22 pub textValue: Option<String>,
23 /// Only set for input elements, contains the input's associated text value.
24
25 #[serde(skip_serializing_if = "Option::is_none")]
26 pub inputValue: Option<String>,
27 /// Only set for radio and checkbox input elements, indicates if the element has been checked
28
29 #[serde(skip_serializing_if = "Option::is_none")]
30 pub inputChecked: Option<bool>,
31 /// Only set for option elements, indicates if the element has been selected
32
33 #[serde(skip_serializing_if = "Option::is_none")]
34 pub optionSelected: Option<bool>,
35 /// 'Node''s id, corresponds to DOM.Node.backendNodeId.
36
37 pub backendNodeId: crate::dom::BackendNodeId,
38 /// The indexes of the node's child nodes in the 'domNodes' array returned by 'getSnapshot', if
39 /// any.
40
41 #[serde(skip_serializing_if = "Option::is_none")]
42 pub childNodeIndexes: Option<Vec<i64>>,
43 /// Attributes of an 'Element' node.
44
45 #[serde(skip_serializing_if = "Option::is_none")]
46 pub attributes: Option<Vec<NameValue>>,
47 /// Indexes of pseudo elements associated with this node in the 'domNodes' array returned by
48 /// 'getSnapshot', if any.
49
50 #[serde(skip_serializing_if = "Option::is_none")]
51 pub pseudoElementIndexes: Option<Vec<i64>>,
52 /// The index of the node's related layout tree node in the 'layoutTreeNodes' array returned by
53 /// 'getSnapshot', if any.
54
55 #[serde(skip_serializing_if = "Option::is_none")]
56 pub layoutNodeIndex: Option<u64>,
57 /// Document URL that 'Document' or 'FrameOwner' node points to.
58
59 #[serde(skip_serializing_if = "Option::is_none")]
60 pub documentURL: Option<String>,
61 /// Base URL that 'Document' or 'FrameOwner' node uses for URL completion.
62
63 #[serde(skip_serializing_if = "Option::is_none")]
64 pub baseURL: Option<String>,
65 /// Only set for documents, contains the document's content language.
66
67 #[serde(skip_serializing_if = "Option::is_none")]
68 pub contentLanguage: Option<String>,
69 /// Only set for documents, contains the document's character set encoding.
70
71 #[serde(skip_serializing_if = "Option::is_none")]
72 pub documentEncoding: Option<String>,
73 /// 'DocumentType' node's publicId.
74
75 #[serde(skip_serializing_if = "Option::is_none")]
76 pub publicId: Option<String>,
77 /// 'DocumentType' node's systemId.
78
79 #[serde(skip_serializing_if = "Option::is_none")]
80 pub systemId: Option<String>,
81 /// Frame ID for frame owner elements and also for the document node.
82
83 #[serde(skip_serializing_if = "Option::is_none")]
84 pub frameId: Option<crate::page::FrameId>,
85 /// The index of a frame owner element's content document in the 'domNodes' array returned by
86 /// 'getSnapshot', if any.
87
88 #[serde(skip_serializing_if = "Option::is_none")]
89 pub contentDocumentIndex: Option<u64>,
90 /// Type of a pseudo element node.
91
92 #[serde(skip_serializing_if = "Option::is_none")]
93 pub pseudoType: Option<crate::dom::PseudoType>,
94 /// Shadow root type.
95
96 #[serde(skip_serializing_if = "Option::is_none")]
97 pub shadowRootType: Option<crate::dom::ShadowRootType>,
98 /// Whether this DOM node responds to mouse clicks. This includes nodes that have had click
99 /// event listeners attached via JavaScript as well as anchor tags that naturally navigate when
100 /// clicked.
101
102 #[serde(skip_serializing_if = "Option::is_none")]
103 pub isClickable: Option<bool>,
104 /// Details of the node's event listeners, if any.
105
106 #[serde(skip_serializing_if = "Option::is_none")]
107 pub eventListeners: Option<Vec<crate::domdebugger::EventListener>>,
108 /// The selected url for nodes with a srcset attribute.
109
110 #[serde(skip_serializing_if = "Option::is_none")]
111 pub currentSourceURL: Option<String>,
112 /// The url of the script (if any) that generates this node.
113
114 #[serde(skip_serializing_if = "Option::is_none")]
115 pub originURL: Option<String>,
116 /// Scroll offsets, set when this node is a Document.
117
118 #[serde(skip_serializing_if = "Option::is_none")]
119 pub scrollOffsetX: Option<f64>,
120
121 #[serde(skip_serializing_if = "Option::is_none")]
122 pub scrollOffsetY: Option<f64>,
123}
124
125/// Details of post layout rendered text positions. The exact layout should not be regarded as
126/// stable and may change between versions.
127
128#[derive(Debug, Clone, Serialize, Deserialize, Default)]
129#[serde(rename_all = "camelCase")]
130pub struct InlineTextBox {
131 /// The bounding box in document coordinates. Note that scroll offset of the document is ignored.
132
133 pub boundingBox: crate::dom::Rect,
134 /// The starting index in characters, for this post layout textbox substring. Characters that
135 /// would be represented as a surrogate pair in UTF-16 have length 2.
136
137 pub startCharacterIndex: u64,
138 /// The number of characters in this post layout textbox substring. Characters that would be
139 /// represented as a surrogate pair in UTF-16 have length 2.
140
141 pub numCharacters: i64,
142}
143
144/// Details of an element in the DOM tree with a LayoutObject.
145
146#[derive(Debug, Clone, Serialize, Deserialize, Default)]
147#[serde(rename_all = "camelCase")]
148pub struct LayoutTreeNode {
149 /// The index of the related DOM node in the 'domNodes' array returned by 'getSnapshot'.
150
151 pub domNodeIndex: u64,
152 /// The bounding box in document coordinates. Note that scroll offset of the document is ignored.
153
154 pub boundingBox: crate::dom::Rect,
155 /// Contents of the LayoutText, if any.
156
157 #[serde(skip_serializing_if = "Option::is_none")]
158 pub layoutText: Option<String>,
159 /// The post-layout inline text nodes, if any.
160
161 #[serde(skip_serializing_if = "Option::is_none")]
162 pub inlineTextNodes: Option<Vec<InlineTextBox>>,
163 /// Index into the 'computedStyles' array returned by 'getSnapshot'.
164
165 #[serde(skip_serializing_if = "Option::is_none")]
166 pub styleIndex: Option<u64>,
167 /// Global paint order index, which is determined by the stacking order of the nodes. Nodes
168 /// that are painted together will have the same index. Only provided if includePaintOrder in
169 /// getSnapshot was true.
170
171 #[serde(skip_serializing_if = "Option::is_none")]
172 pub paintOrder: Option<i64>,
173 /// Set to true to indicate the element begins a new stacking context.
174
175 #[serde(skip_serializing_if = "Option::is_none")]
176 pub isStackingContext: Option<bool>,
177}
178
179/// A subset of the full ComputedStyle as defined by the request whitelist.
180
181#[derive(Debug, Clone, Serialize, Deserialize, Default)]
182#[serde(rename_all = "camelCase")]
183pub struct ComputedStyle {
184 /// Name/value pairs of computed style properties.
185
186 pub properties: Vec<NameValue>,
187}
188
189/// A name/value pair.
190
191#[derive(Debug, Clone, Serialize, Deserialize, Default)]
192#[serde(rename_all = "camelCase")]
193pub struct NameValue {
194 /// Attribute/property name.
195
196 pub name: String,
197 /// Attribute/property value.
198
199 pub value: String,
200}
201
202/// Index of the string in the strings table.
203
204pub type StringIndex = i64;
205
206/// Index of the string in the strings table.
207
208pub type ArrayOfStrings = Vec<StringIndex>;
209
210/// Data that is only present on rare nodes.
211
212#[derive(Debug, Clone, Serialize, Deserialize, Default)]
213#[serde(rename_all = "camelCase")]
214pub struct RareStringData {
215
216 pub index: Vec<i64>,
217
218 pub value: Vec<StringIndex>,
219}
220
221
222#[derive(Debug, Clone, Serialize, Deserialize, Default)]
223#[serde(rename_all = "camelCase")]
224pub struct RareBooleanData {
225
226 pub index: Vec<i64>,
227}
228
229
230#[derive(Debug, Clone, Serialize, Deserialize, Default)]
231#[serde(rename_all = "camelCase")]
232pub struct RareIntegerData {
233
234 pub index: Vec<i64>,
235
236 pub value: Vec<i64>,
237}
238
239
240pub type Rectangle = Vec<f64>;
241
242/// Document snapshot.
243
244#[derive(Debug, Clone, Serialize, Deserialize, Default)]
245#[serde(rename_all = "camelCase")]
246pub struct DocumentSnapshot {
247 /// Document URL that 'Document' or 'FrameOwner' node points to.
248
249 pub documentURL: StringIndex,
250 /// Document title.
251
252 pub title: StringIndex,
253 /// Base URL that 'Document' or 'FrameOwner' node uses for URL completion.
254
255 pub baseURL: StringIndex,
256 /// Contains the document's content language.
257
258 pub contentLanguage: StringIndex,
259 /// Contains the document's character set encoding.
260
261 pub encodingName: StringIndex,
262 /// 'DocumentType' node's publicId.
263
264 pub publicId: StringIndex,
265 /// 'DocumentType' node's systemId.
266
267 pub systemId: StringIndex,
268 /// Frame ID for frame owner elements and also for the document node.
269
270 pub frameId: StringIndex,
271 /// A table with dom nodes.
272
273 pub nodes: NodeTreeSnapshot,
274 /// The nodes in the layout tree.
275
276 pub layout: LayoutTreeSnapshot,
277 /// The post-layout inline text nodes.
278
279 pub textBoxes: TextBoxSnapshot,
280 /// Horizontal scroll offset.
281
282 #[serde(skip_serializing_if = "Option::is_none")]
283 pub scrollOffsetX: Option<f64>,
284 /// Vertical scroll offset.
285
286 #[serde(skip_serializing_if = "Option::is_none")]
287 pub scrollOffsetY: Option<f64>,
288 /// Document content width.
289
290 #[serde(skip_serializing_if = "Option::is_none")]
291 pub contentWidth: Option<f64>,
292 /// Document content height.
293
294 #[serde(skip_serializing_if = "Option::is_none")]
295 pub contentHeight: Option<f64>,
296}
297
298/// Table containing nodes.
299
300#[derive(Debug, Clone, Serialize, Deserialize, Default)]
301#[serde(rename_all = "camelCase")]
302pub struct NodeTreeSnapshot {
303 /// Parent node index.
304
305 #[serde(skip_serializing_if = "Option::is_none")]
306 pub parentIndex: Option<Vec<i64>>,
307 /// 'Node''s nodeType.
308
309 #[serde(skip_serializing_if = "Option::is_none")]
310 pub nodeType: Option<Vec<i64>>,
311 /// Type of the shadow root the 'Node' is in. String values are equal to the 'ShadowRootType' enum.
312
313 #[serde(skip_serializing_if = "Option::is_none")]
314 pub shadowRootType: Option<RareStringData>,
315 /// 'Node''s nodeName.
316
317 #[serde(skip_serializing_if = "Option::is_none")]
318 pub nodeName: Option<Vec<StringIndex>>,
319 /// 'Node''s nodeValue.
320
321 #[serde(skip_serializing_if = "Option::is_none")]
322 pub nodeValue: Option<Vec<StringIndex>>,
323 /// 'Node''s id, corresponds to DOM.Node.backendNodeId.
324
325 #[serde(skip_serializing_if = "Option::is_none")]
326 pub backendNodeId: Option<Vec<crate::dom::BackendNodeId>>,
327 /// Attributes of an 'Element' node. Flatten name, value pairs.
328
329 #[serde(skip_serializing_if = "Option::is_none")]
330 pub attributes: Option<Vec<ArrayOfStrings>>,
331 /// Only set for textarea elements, contains the text value.
332
333 #[serde(skip_serializing_if = "Option::is_none")]
334 pub textValue: Option<RareStringData>,
335 /// Only set for input elements, contains the input's associated text value.
336
337 #[serde(skip_serializing_if = "Option::is_none")]
338 pub inputValue: Option<RareStringData>,
339 /// Only set for radio and checkbox input elements, indicates if the element has been checked
340
341 #[serde(skip_serializing_if = "Option::is_none")]
342 pub inputChecked: Option<RareBooleanData>,
343 /// Only set for option elements, indicates if the element has been selected
344
345 #[serde(skip_serializing_if = "Option::is_none")]
346 pub optionSelected: Option<RareBooleanData>,
347 /// The index of the document in the list of the snapshot documents.
348
349 #[serde(skip_serializing_if = "Option::is_none")]
350 pub contentDocumentIndex: Option<RareIntegerData>,
351 /// Type of a pseudo element node.
352
353 #[serde(skip_serializing_if = "Option::is_none")]
354 pub pseudoType: Option<RareStringData>,
355 /// Pseudo element identifier for this node. Only present if there is a
356 /// valid pseudoType.
357
358 #[serde(skip_serializing_if = "Option::is_none")]
359 pub pseudoIdentifier: Option<RareStringData>,
360 /// Whether this DOM node responds to mouse clicks. This includes nodes that have had click
361 /// event listeners attached via JavaScript as well as anchor tags that naturally navigate when
362 /// clicked.
363
364 #[serde(skip_serializing_if = "Option::is_none")]
365 pub isClickable: Option<RareBooleanData>,
366 /// The selected url for nodes with a srcset attribute.
367
368 #[serde(skip_serializing_if = "Option::is_none")]
369 pub currentSourceURL: Option<RareStringData>,
370 /// The url of the script (if any) that generates this node.
371
372 #[serde(skip_serializing_if = "Option::is_none")]
373 pub originURL: Option<RareStringData>,
374}
375
376/// Table of details of an element in the DOM tree with a LayoutObject.
377
378#[derive(Debug, Clone, Serialize, Deserialize, Default)]
379#[serde(rename_all = "camelCase")]
380pub struct LayoutTreeSnapshot {
381 /// Index of the corresponding node in the 'NodeTreeSnapshot' array returned by 'captureSnapshot'.
382
383 pub nodeIndex: Vec<i64>,
384 /// Array of indexes specifying computed style strings, filtered according to the 'computedStyles' parameter passed to 'captureSnapshot'.
385
386 pub styles: Vec<ArrayOfStrings>,
387 /// The absolute position bounding box.
388
389 pub bounds: Vec<Rectangle>,
390 /// Contents of the LayoutText, if any.
391
392 pub text: Vec<StringIndex>,
393 /// Stacking context information.
394
395 pub stackingContexts: RareBooleanData,
396 /// Global paint order index, which is determined by the stacking order of the nodes. Nodes
397 /// that are painted together will have the same index. Only provided if includePaintOrder in
398 /// captureSnapshot was true.
399
400 #[serde(skip_serializing_if = "Option::is_none")]
401 pub paintOrders: Option<Vec<i64>>,
402 /// The offset rect of nodes. Only available when includeDOMRects is set to true
403
404 #[serde(skip_serializing_if = "Option::is_none")]
405 pub offsetRects: Option<Vec<Rectangle>>,
406 /// The scroll rect of nodes. Only available when includeDOMRects is set to true
407
408 #[serde(skip_serializing_if = "Option::is_none")]
409 pub scrollRects: Option<Vec<Rectangle>>,
410 /// The client rect of nodes. Only available when includeDOMRects is set to true
411
412 #[serde(skip_serializing_if = "Option::is_none")]
413 pub clientRects: Option<Vec<Rectangle>>,
414 /// The list of background colors that are blended with colors of overlapping elements.
415
416 #[serde(skip_serializing_if = "Option::is_none")]
417 pub blendedBackgroundColors: Option<Vec<StringIndex>>,
418 /// The list of computed text opacities.
419
420 #[serde(skip_serializing_if = "Option::is_none")]
421 pub textColorOpacities: Option<Vec<f64>>,
422}
423
424/// Table of details of the post layout rendered text positions. The exact layout should not be regarded as
425/// stable and may change between versions.
426
427#[derive(Debug, Clone, Serialize, Deserialize, Default)]
428#[serde(rename_all = "camelCase")]
429pub struct TextBoxSnapshot {
430 /// Index of the layout tree node that owns this box collection.
431
432 pub layoutIndex: Vec<i64>,
433 /// The absolute position bounding box.
434
435 pub bounds: Vec<Rectangle>,
436 /// The starting index in characters, for this post layout textbox substring. Characters that
437 /// would be represented as a surrogate pair in UTF-16 have length 2.
438
439 pub start: Vec<i64>,
440 /// The number of characters in this post layout textbox substring. Characters that would be
441 /// represented as a surrogate pair in UTF-16 have length 2.
442
443 pub length: Vec<i64>,
444}
445
446#[derive(Debug, Clone, Serialize, Deserialize, Default)]
447pub struct DisableParams {}
448
449impl DisableParams { pub const METHOD: &'static str = "DOMSnapshot.disable"; }
450
451impl crate::CdpCommand for DisableParams {
452 const METHOD: &'static str = "DOMSnapshot.disable";
453 type Response = crate::EmptyReturns;
454}
455
456#[derive(Debug, Clone, Serialize, Deserialize, Default)]
457pub struct EnableParams {}
458
459impl EnableParams { pub const METHOD: &'static str = "DOMSnapshot.enable"; }
460
461impl crate::CdpCommand for EnableParams {
462 const METHOD: &'static str = "DOMSnapshot.enable";
463 type Response = crate::EmptyReturns;
464}
465
466/// Returns a document snapshot, including the full DOM tree of the root node (including iframes,
467/// template contents, and imported documents) in a flattened array, as well as layout and
468/// white-listed computed style information for the nodes. Shadow DOM in the returned DOM tree is
469/// flattened.
470
471#[derive(Debug, Clone, Serialize, Deserialize, Default)]
472#[serde(rename_all = "camelCase")]
473pub struct GetSnapshotParams {
474 /// Whitelist of computed styles to return.
475
476 pub computedStyleWhitelist: Vec<String>,
477 /// Whether or not to retrieve details of DOM listeners (default false).
478
479 #[serde(skip_serializing_if = "Option::is_none")]
480 pub includeEventListeners: Option<bool>,
481 /// Whether to determine and include the paint order index of LayoutTreeNodes (default false).
482
483 #[serde(skip_serializing_if = "Option::is_none")]
484 pub includePaintOrder: Option<bool>,
485 /// Whether to include UA shadow tree in the snapshot (default false).
486
487 #[serde(skip_serializing_if = "Option::is_none")]
488 pub includeUserAgentShadowTree: Option<bool>,
489}
490
491/// Returns a document snapshot, including the full DOM tree of the root node (including iframes,
492/// template contents, and imported documents) in a flattened array, as well as layout and
493/// white-listed computed style information for the nodes. Shadow DOM in the returned DOM tree is
494/// flattened.
495
496#[derive(Debug, Clone, Serialize, Deserialize, Default)]
497#[serde(rename_all = "camelCase")]
498pub struct GetSnapshotReturns {
499 /// The nodes in the DOM tree. The DOMNode at index 0 corresponds to the root document.
500
501 pub domNodes: Vec<DOMNode>,
502 /// The nodes in the layout tree.
503
504 pub layoutTreeNodes: Vec<LayoutTreeNode>,
505 /// Whitelisted ComputedStyle properties for each node in the layout tree.
506
507 pub computedStyles: Vec<ComputedStyle>,
508}
509
510impl GetSnapshotParams { pub const METHOD: &'static str = "DOMSnapshot.getSnapshot"; }
511
512impl crate::CdpCommand for GetSnapshotParams {
513 const METHOD: &'static str = "DOMSnapshot.getSnapshot";
514 type Response = GetSnapshotReturns;
515}
516
517/// Returns a document snapshot, including the full DOM tree of the root node (including iframes,
518/// template contents, and imported documents) in a flattened array, as well as layout and
519/// white-listed computed style information for the nodes. Shadow DOM in the returned DOM tree is
520/// flattened.
521
522#[derive(Debug, Clone, Serialize, Deserialize, Default)]
523#[serde(rename_all = "camelCase")]
524pub struct CaptureSnapshotParams {
525 /// Whitelist of computed styles to return.
526
527 pub computedStyles: Vec<String>,
528 /// Whether to include layout object paint orders into the snapshot.
529
530 #[serde(skip_serializing_if = "Option::is_none")]
531 pub includePaintOrder: Option<bool>,
532 /// Whether to include DOM rectangles (offsetRects, clientRects, scrollRects) into the snapshot
533
534 #[serde(skip_serializing_if = "Option::is_none")]
535 pub includeDOMRects: Option<bool>,
536 /// Whether to include blended background colors in the snapshot (default: false).
537 /// Blended background color is achieved by blending background colors of all elements
538 /// that overlap with the current element.
539
540 #[serde(skip_serializing_if = "Option::is_none")]
541 pub includeBlendedBackgroundColors: Option<bool>,
542 /// Whether to include text color opacity in the snapshot (default: false).
543 /// An element might have the opacity property set that affects the text color of the element.
544 /// The final text color opacity is computed based on the opacity of all overlapping elements.
545
546 #[serde(skip_serializing_if = "Option::is_none")]
547 pub includeTextColorOpacities: Option<bool>,
548}
549
550/// Returns a document snapshot, including the full DOM tree of the root node (including iframes,
551/// template contents, and imported documents) in a flattened array, as well as layout and
552/// white-listed computed style information for the nodes. Shadow DOM in the returned DOM tree is
553/// flattened.
554
555#[derive(Debug, Clone, Serialize, Deserialize, Default)]
556#[serde(rename_all = "camelCase")]
557pub struct CaptureSnapshotReturns {
558 /// The nodes in the DOM tree. The DOMNode at index 0 corresponds to the root document.
559
560 pub documents: Vec<DocumentSnapshot>,
561 /// Shared string table that all string properties refer to with indexes.
562
563 pub strings: Vec<String>,
564}
565
566impl CaptureSnapshotParams { pub const METHOD: &'static str = "DOMSnapshot.captureSnapshot"; }
567
568impl crate::CdpCommand for CaptureSnapshotParams {
569 const METHOD: &'static str = "DOMSnapshot.captureSnapshot";
570 type Response = CaptureSnapshotReturns;
571}