DOMSnapshot

This domain facilitates obtaining document snapshots with DOM, layout, and style information.

This CDP domain is experimental.

Types

Generally, you do not need to instantiate CDP types yourself. Instead, the API creates objects for you as return values from commands, and then you can use those objects as arguments to other commands.

class cdp.dom_snapshot.DOMNode(node_type, node_name, node_value, backend_node_id, text_value=None, input_value=None, input_checked=None, option_selected=None, child_node_indexes=None, attributes=None, pseudo_element_indexes=None, layout_node_index=None, document_url=None, base_url=None, content_language=None, document_encoding=None, public_id=None, system_id=None, frame_id=None, content_document_index=None, pseudo_type=None, shadow_root_type=None, is_clickable=None, event_listeners=None, current_source_url=None, origin_url=None, scroll_offset_x=None, scroll_offset_y=None)

A Node in the DOM tree.

attributes = None

Attributes of an Element node.

backend_node_id = None

Node’s id, corresponds to DOM.Node.backendNodeId.

base_url = None

Base URL that Document or FrameOwner node uses for URL completion.

child_node_indexes = None

The indexes of the node’s child nodes in the domNodes array returned by getSnapshot, if any.

content_document_index = None

The index of a frame owner element’s content document in the domNodes array returned by getSnapshot, if any.

content_language = None

Only set for documents, contains the document’s content language.

current_source_url = None

The selected url for nodes with a srcset attribute.

document_encoding = None

Only set for documents, contains the document’s character set encoding.

document_url = None

Document URL that Document or FrameOwner node points to.

event_listeners = None

Details of the node’s event listeners, if any.

frame_id = None

Frame ID for frame owner elements and also for the document node.

input_checked = None

Only set for radio and checkbox input elements, indicates if the element has been checked

input_value = None

Only set for input elements, contains the input’s associated text value.

is_clickable = None

Whether this DOM node responds to mouse clicks. This includes nodes that have had click event listeners attached via JavaScript as well as anchor tags that naturally navigate when clicked.

layout_node_index = None

The index of the node’s related layout tree node in the layoutTreeNodes array returned by getSnapshot, if any.

node_name = None

Node’s nodeName.

node_type = None

Node’s nodeType.

node_value = None

Node’s nodeValue.

option_selected = None

Only set for option elements, indicates if the element has been selected

origin_url = None

The url of the script (if any) that generates this node.

pseudo_element_indexes = None

Indexes of pseudo elements associated with this node in the domNodes array returned by getSnapshot, if any.

pseudo_type = None

Type of a pseudo element node.

public_id = None

DocumentType node’s publicId.

scroll_offset_x = None

Scroll offsets, set when this node is a Document.

scroll_offset_y = None
shadow_root_type = None

Shadow root type.

system_id = None

DocumentType node’s systemId.

text_value = None

Only set for textarea elements, contains the text value.

class cdp.dom_snapshot.InlineTextBox(bounding_box, start_character_index, num_characters)

Details of post layout rendered text positions. The exact layout should not be regarded as stable and may change between versions.

bounding_box = None

The bounding box in document coordinates. Note that scroll offset of the document is ignored.

num_characters = None

The number of characters in this post layout textbox substring. Characters that would be represented as a surrogate pair in UTF-16 have length 2.

start_character_index = None

The starting index in characters, for this post layout textbox substring. Characters that would be represented as a surrogate pair in UTF-16 have length 2.

class cdp.dom_snapshot.LayoutTreeNode(dom_node_index, bounding_box, layout_text=None, inline_text_nodes=None, style_index=None, paint_order=None, is_stacking_context=None)

Details of an element in the DOM tree with a LayoutObject.

bounding_box = None

The bounding box in document coordinates. Note that scroll offset of the document is ignored.

dom_node_index = None

The index of the related DOM node in the domNodes array returned by getSnapshot.

inline_text_nodes = None

The post-layout inline text nodes, if any.

is_stacking_context = None

Set to true to indicate the element begins a new stacking context.

layout_text = None

Contents of the LayoutText, if any.

paint_order = None

Global paint order index, which is determined by the stacking order of the nodes. Nodes that are painted together will have the same index. Only provided if includePaintOrder in getSnapshot was true.

style_index = None

Index into the computedStyles array returned by getSnapshot.

class cdp.dom_snapshot.ComputedStyle(properties)

A subset of the full ComputedStyle as defined by the request whitelist.

properties = None

Name/value pairs of computed style properties.

class cdp.dom_snapshot.NameValue(name, value)

A name/value pair.

name = None

Attribute/property name.

value = None

Attribute/property value.

class cdp.dom_snapshot.StringIndex

Index of the string in the strings table.

class cdp.dom_snapshot.ArrayOfStrings

Index of the string in the strings table.

class cdp.dom_snapshot.RareStringData(index, value)

Data that is only present on rare nodes.

class cdp.dom_snapshot.RareBooleanData(index)
class cdp.dom_snapshot.RareIntegerData(index, value)
class cdp.dom_snapshot.Rectangle
class cdp.dom_snapshot.DocumentSnapshot(document_url, base_url, content_language, encoding_name, public_id, system_id, frame_id, nodes, layout, text_boxes, scroll_offset_x=None, scroll_offset_y=None)

Document snapshot.

base_url = None

Base URL that Document or FrameOwner node uses for URL completion.

content_language = None

Contains the document’s content language.

document_url = None

Document URL that Document or FrameOwner node points to.

encoding_name = None

Contains the document’s character set encoding.

frame_id = None

Frame ID for frame owner elements and also for the document node.

layout = None

The nodes in the layout tree.

nodes = None

A table with dom nodes.

public_id = None

DocumentType node’s publicId.

scroll_offset_x = None

Horizontal scroll offset.

scroll_offset_y = None

Vertical scroll offset.

system_id = None

DocumentType node’s systemId.

text_boxes = None

The post-layout inline text nodes.

class cdp.dom_snapshot.NodeTreeSnapshot(parent_index=None, node_type=None, node_name=None, node_value=None, backend_node_id=None, attributes=None, text_value=None, input_value=None, input_checked=None, option_selected=None, content_document_index=None, pseudo_type=None, is_clickable=None, current_source_url=None, origin_url=None)

Table containing nodes.

attributes = None

Attributes of an Element node. Flatten name, value pairs.

backend_node_id = None

Node’s id, corresponds to DOM.Node.backendNodeId.

content_document_index = None

The index of the document in the list of the snapshot documents.

current_source_url = None

The selected url for nodes with a srcset attribute.

input_checked = None

Only set for radio and checkbox input elements, indicates if the element has been checked

input_value = None

Only set for input elements, contains the input’s associated text value.

is_clickable = None

Whether this DOM node responds to mouse clicks. This includes nodes that have had click event listeners attached via JavaScript as well as anchor tags that naturally navigate when clicked.

node_name = None

Node’s nodeName.

node_type = None

Node’s nodeType.

node_value = None

Node’s nodeValue.

option_selected = None

Only set for option elements, indicates if the element has been selected

origin_url = None

The url of the script (if any) that generates this node.

parent_index = None

Parent node index.

pseudo_type = None

Type of a pseudo element node.

text_value = None

Only set for textarea elements, contains the text value.

class cdp.dom_snapshot.LayoutTreeSnapshot(node_index, styles, bounds, text, stacking_contexts, offset_rects=None, scroll_rects=None, client_rects=None)

Table of details of an element in the DOM tree with a LayoutObject.

bounds = None

The absolute position bounding box.

client_rects = None

The client rect of nodes. Only available when includeDOMRects is set to true

node_index = None

Index of the corresponding node in the NodeTreeSnapshot array returned by captureSnapshot.

offset_rects = None

The offset rect of nodes. Only available when includeDOMRects is set to true

scroll_rects = None

The scroll rect of nodes. Only available when includeDOMRects is set to true

stacking_contexts = None

Stacking context information.

styles = None

Array of indexes specifying computed style strings, filtered according to the computedStyles parameter passed to captureSnapshot.

text = None

Contents of the LayoutText, if any.

class cdp.dom_snapshot.TextBoxSnapshot(layout_index, bounds, start, length)

Table of details of the post layout rendered text positions. The exact layout should not be regarded as stable and may change between versions.

bounds = None

The absolute position bounding box.

layout_index = None

Index of the layout tree node that owns this box collection.

length = None

The number of characters in this post layout textbox substring. Characters that would be represented as a surrogate pair in UTF-16 have length 2.

start = None

The starting index in characters, for this post layout textbox substring. Characters that would be represented as a surrogate pair in UTF-16 have length 2.

Commands

Each command is a generator function. The return type Generator[x, y, z] indicates that the generator yields arguments of type x, it must be resumed with an argument of type y, and it returns type z. In this library, types x and y are the same for all commands, and z is the return type you should pay attention to. For more information, see Getting Started: Commands.

cdp.dom_snapshot.capture_snapshot(computed_styles, include_dom_rects=None)

Returns a document snapshot, including the full DOM tree of the root node (including iframes, template contents, and imported documents) in a flattened array, as well as layout and white-listed computed style information for the nodes. Shadow DOM in the returned DOM tree is flattened.

Parameters:
  • computed_styles (List[str]) – Whitelist of computed styles to return.
  • include_dom_rects (Optional[bool]) – (Optional) Whether to include DOM rectangles (offsetRects, clientRects, scrollRects) into the snapshot
Return type:

Generator[Dict[str, Any], Dict[str, Any], Tuple[List[DocumentSnapshot], List[str]]]

Returns:

A tuple with the following items:

  1. documents - The nodes in the DOM tree. The DOMNode at index 0 corresponds to the root document.
  2. strings - Shared string table that all string properties refer to with indexes.

cdp.dom_snapshot.disable()

Disables DOM snapshot agent for the given page.

Return type:Generator[Dict[str, Any], Dict[str, Any], None]
cdp.dom_snapshot.enable()

Enables DOM snapshot agent for the given page.

Return type:Generator[Dict[str, Any], Dict[str, Any], None]
cdp.dom_snapshot.get_snapshot(computed_style_whitelist, include_event_listeners=None, include_paint_order=None, include_user_agent_shadow_tree=None)

Returns a document snapshot, including the full DOM tree of the root node (including iframes, template contents, and imported documents) in a flattened array, as well as layout and white-listed computed style information for the nodes. Shadow DOM in the returned DOM tree is flattened.

Deprecated since version 1.3.

Parameters:
  • computed_style_whitelist (List[str]) – Whitelist of computed styles to return.
  • include_event_listeners (Optional[bool]) – (Optional) Whether or not to retrieve details of DOM listeners (default false).
  • include_paint_order (Optional[bool]) – (Optional) Whether to determine and include the paint order index of LayoutTreeNodes (default false).
  • include_user_agent_shadow_tree (Optional[bool]) – (Optional) Whether to include UA shadow tree in the snapshot (default false).
Return type:

Generator[Dict[str, Any], Dict[str, Any], Tuple[List[DOMNode], List[LayoutTreeNode], List[ComputedStyle]]]

Returns:

A tuple with the following items:

  1. domNodes - The nodes in the DOM tree. The DOMNode at index 0 corresponds to the root document.
  2. layoutTreeNodes - The nodes in the layout tree.
  3. computedStyles - Whitelisted ComputedStyle properties for each node in the layout tree.

Deprecated since version 1.3.

Events

There are no events in this module.