Skip to main content

browser_protocol/domsnapshot/
mod.rs

1//! This domain facilitates obtaining document snapshots with DOM, layout, and style information.
2
3use serde::{Serialize, Deserialize};
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/// Returns a document snapshot, including the full DOM tree of the root node (including iframes,
447/// template contents, and imported documents) in a flattened array, as well as layout and
448/// white-listed computed style information for the nodes. Shadow DOM in the returned DOM tree is
449/// flattened.
450
451#[derive(Debug, Clone, Serialize, Deserialize, Default)]
452#[serde(rename_all = "camelCase")]
453pub struct GetSnapshotParams {
454    /// Whitelist of computed styles to return.
455
456    pub computedStyleWhitelist: Vec<String>,
457    /// Whether or not to retrieve details of DOM listeners (default false).
458
459    #[serde(skip_serializing_if = "Option::is_none")]
460    pub includeEventListeners: Option<bool>,
461    /// Whether to determine and include the paint order index of LayoutTreeNodes (default false).
462
463    #[serde(skip_serializing_if = "Option::is_none")]
464    pub includePaintOrder: Option<bool>,
465    /// Whether to include UA shadow tree in the snapshot (default false).
466
467    #[serde(skip_serializing_if = "Option::is_none")]
468    pub includeUserAgentShadowTree: Option<bool>,
469}
470
471/// Returns a document snapshot, including the full DOM tree of the root node (including iframes,
472/// template contents, and imported documents) in a flattened array, as well as layout and
473/// white-listed computed style information for the nodes. Shadow DOM in the returned DOM tree is
474/// flattened.
475
476#[derive(Debug, Clone, Serialize, Deserialize, Default)]
477#[serde(rename_all = "camelCase")]
478pub struct GetSnapshotReturns {
479    /// The nodes in the DOM tree. The DOMNode at index 0 corresponds to the root document.
480
481    pub domNodes: Vec<DOMNode>,
482    /// The nodes in the layout tree.
483
484    pub layoutTreeNodes: Vec<LayoutTreeNode>,
485    /// Whitelisted ComputedStyle properties for each node in the layout tree.
486
487    pub computedStyles: Vec<ComputedStyle>,
488}
489
490/// Returns a document snapshot, including the full DOM tree of the root node (including iframes,
491/// template contents, and imported documents) in a flattened array, as well as layout and
492/// white-listed computed style information for the nodes. Shadow DOM in the returned DOM tree is
493/// flattened.
494
495#[derive(Debug, Clone, Serialize, Deserialize, Default)]
496#[serde(rename_all = "camelCase")]
497pub struct CaptureSnapshotParams {
498    /// Whitelist of computed styles to return.
499
500    pub computedStyles: Vec<String>,
501    /// Whether to include layout object paint orders into the snapshot.
502
503    #[serde(skip_serializing_if = "Option::is_none")]
504    pub includePaintOrder: Option<bool>,
505    /// Whether to include DOM rectangles (offsetRects, clientRects, scrollRects) into the snapshot
506
507    #[serde(skip_serializing_if = "Option::is_none")]
508    pub includeDOMRects: Option<bool>,
509    /// Whether to include blended background colors in the snapshot (default: false).
510    /// Blended background color is achieved by blending background colors of all elements
511    /// that overlap with the current element.
512
513    #[serde(skip_serializing_if = "Option::is_none")]
514    pub includeBlendedBackgroundColors: Option<bool>,
515    /// Whether to include text color opacity in the snapshot (default: false).
516    /// An element might have the opacity property set that affects the text color of the element.
517    /// The final text color opacity is computed based on the opacity of all overlapping elements.
518
519    #[serde(skip_serializing_if = "Option::is_none")]
520    pub includeTextColorOpacities: Option<bool>,
521}
522
523/// Returns a document snapshot, including the full DOM tree of the root node (including iframes,
524/// template contents, and imported documents) in a flattened array, as well as layout and
525/// white-listed computed style information for the nodes. Shadow DOM in the returned DOM tree is
526/// flattened.
527
528#[derive(Debug, Clone, Serialize, Deserialize, Default)]
529#[serde(rename_all = "camelCase")]
530pub struct CaptureSnapshotReturns {
531    /// The nodes in the DOM tree. The DOMNode at index 0 corresponds to the root document.
532
533    pub documents: Vec<DocumentSnapshot>,
534    /// Shared string table that all string properties refer to with indexes.
535
536    pub strings: Vec<String>,
537}