DOM Domain
This domain exposes DOM read/write operations. Each DOM Node is represented with its mirror object
that has an id. This id can be used to get additional information on the Node, resolve it into
the JavaScript object wrapper, etc. It is important that client receives DOM events only for the
nodes that are known to the client. Backend keeps track of the nodes that were sent to the client
and never sends the same node twice. It is client's responsibility to collect information about
the nodes that were sent to the client. Note that iframe owner elements will return
corresponding document elements as their child nodes.
Methods
- DOM.describeNode
- DOM.disable
- DOM.enable
- DOM.focus
- DOM.getAttributes
- DOM.getBoxModel
- DOM.getDocument
- DOM.getNodeForLocation
- DOM.getOuterHTML
- DOM.hideHighlight
- DOM.highlightNode
- DOM.highlightRect
- DOM.moveTo
- DOM.querySelector
- DOM.querySelectorAll
- DOM.removeAttribute
- DOM.removeNode
- DOM.requestChildNodes
- DOM.requestNode
- DOM.resolveNode
- DOM.scrollIntoViewIfNeeded
- DOM.setAttributesAsText
- DOM.setAttributeValue
- DOM.setFileInputFiles
- DOM.setNodeName
- DOM.setNodeValue
- DOM.setOuterHTML
- DOM.getFlattenedDocument Deprecated
- DOM.collectClassNamesFromSubtree Experimental
- DOM.copyTo Experimental
- DOM.discardSearchResults Experimental
- DOM.forceShowPopover Experimental
- DOM.getAnchorElement Experimental
- DOM.getContainerForNode Experimental
- DOM.getContentQuads Experimental
- DOM.getDetachedDomNodes Experimental
- DOM.getElementByRelation Experimental
- DOM.getFileInfo Experimental
- DOM.getFrameOwner Experimental
- DOM.getNodesForSubtreeByStyle Experimental
- DOM.getNodeStackTraces Experimental
- DOM.getQueryingDescendantsForContainer Experimental
- DOM.getRelayoutBoundary Experimental
- DOM.getSearchResults Experimental
- DOM.getTopLayerElements Experimental
- DOM.markUndoableState Experimental
- DOM.performSearch Experimental
- DOM.pushNodeByPathToFrontend Experimental
- DOM.pushNodesByBackendIdsToFrontend Experimental
- DOM.redo Experimental
- DOM.setInspectedNode Experimental
- DOM.setNodeStackTracesEnabled Experimental
- DOM.undo Experimental
Events
- DOM.attributeModified
- DOM.attributeRemoved
- DOM.characterDataModified
- DOM.childNodeCountUpdated
- DOM.childNodeInserted
- DOM.childNodeRemoved
- DOM.documentUpdated
- DOM.setChildNodes
- DOM.affectedByStartingStylesFlagUpdated Experimental
- DOM.distributedNodesUpdated Experimental
- DOM.inlineStyleInvalidated Experimental
- DOM.pseudoElementAdded Experimental
- DOM.pseudoElementRemoved Experimental
- DOM.scrollableFlagUpdated Experimental
- DOM.shadowRootPopped Experimental
- DOM.shadowRootPushed Experimental
- DOM.topLayerElementsUpdated Experimental
Types
Methods
DOM.describeNode #
Describes node given its id, does not require domain to be enabled. Does not start tracking any objects, can be used for automation.
Parameters
nodeIdOptional
Identifier of the node.
backendNodeIdOptional
Identifier of the backend node.
objectIdOptional
JavaScript object id of the node wrapper.
depthOptional
integerThe maximum depth at which children should be retrieved, defaults to 1. Use -1 for the entire subtree or provide an integer larger than 0.
pierceOptional
booleanWhether or not iframes and shadow roots should be traversed when returning the subtree (default is false).
Return object
node Node description.
DOM.enable #
Enables DOM agent for the given page.
Parameters
includeWhitespaceOptional
stringWhether to include whitespaces in the children array of returned Nodes.
Allowed values: none, all
DOM.focus #
Focuses the given element.
Parameters
nodeIdOptional
Identifier of the node.
backendNodeIdOptional
Identifier of the backend node.
objectIdOptional
JavaScript object id of the node wrapper.
DOM.getAttributes #
Returns attributes for the specified node.
Parameters
nodeId Id of the node to retrieve attributes for.
Return object
attributes array[ string ]An interleaved array of node attribute names and values.
DOM.getBoxModel #
Returns boxes for the given node.
Parameters
nodeIdOptional
Identifier of the node.
backendNodeIdOptional
Identifier of the backend node.
objectIdOptional
JavaScript object id of the node wrapper.
Return object
model Box model for the node.
DOM.getDocument #
Returns the root DOM node (and optionally the subtree) to the caller. Implicitly enables the DOM domain events for the current target.
Parameters
depthOptional
integerThe maximum depth at which children should be retrieved, defaults to 1. Use -1 for the entire subtree or provide an integer larger than 0.
pierceOptional
booleanWhether or not iframes and shadow roots should be traversed when returning the subtree (default is false).
Return object
root Resulting node.
DOM.getNodeForLocation #
Returns node id at given location. Depending on whether DOM domain is enabled, nodeId is either returned or not.
Parameters
x integerX coordinate.
y integerY coordinate.
includeUserAgentShadowDOMOptional
booleanFalse to skip to the nearest non-UA shadow root ancestor (default: false).
ignorePointerEventsNoneOptional
booleanWhether to ignore pointer-events: none on elements and hit test them.
Return object
backendNodeId Resulting node.
frameId Frame this node belongs to.
nodeIdOptional
Id of the node at given coordinates, only when enabled and requested document.
DOM.getOuterHTML #
Returns node's HTML markup.
Parameters
nodeIdOptional
Identifier of the node.
backendNodeIdOptional
Identifier of the backend node.
objectIdOptional
JavaScript object id of the node wrapper.
includeShadowDOMOptional
booleanInclude all shadow roots. Equals to false if not specified.
Return object
outerHTML stringOuter HTML markup.
DOM.moveTo #
Moves node into the new container, places it before the given anchor.
Parameters
nodeId Id of the node to move.
targetNodeId Id of the element to drop the moved node into.
insertBeforeNodeIdOptional
Drop node before this one (if absent, the moved node becomes the last child of
targetNodeId).
Return object
nodeId New id of the moved node.
DOM.querySelector #
Executes querySelector on a given node.
Parameters
nodeId Id of the node to query upon.
selector stringSelector string.
Return object
nodeId Query selector result.
DOM.querySelectorAll #
Executes querySelectorAll on a given node.
Parameters
nodeId Id of the node to query upon.
selector stringSelector string.
Return object
nodeIds array[ NodeId ]Query selector result.
DOM.removeAttribute #
Removes attribute with given name from an element with given id.
Parameters
nodeId Id of the element to remove attribute from.
name stringName of the attribute to remove.
DOM.requestChildNodes #
Requests that children of the node with given id are returned to the caller in form of
setChildNodes events where not only immediate children are retrieved, but all children down to
the specified depth.
Parameters
nodeId Id of the node to get children for.
depthOptional
integerThe maximum depth at which children should be retrieved, defaults to 1. Use -1 for the entire subtree or provide an integer larger than 0.
pierceOptional
booleanWhether or not iframes and shadow roots should be traversed when returning the sub-tree (default is false).
DOM.requestNode #
Requests that the node is sent to the caller given the JavaScript node object reference. All
nodes that form the path from the node to the root are also sent to the client as a series of
setChildNodes notifications.
Parameters
objectId JavaScript object id to convert into node.
Return object
nodeId Node id for given object.
DOM.resolveNode #
Resolves the JavaScript node object for a given NodeId or BackendNodeId.
Parameters
nodeIdOptional
Id of the node to resolve.
backendNodeIdOptional
Backend identifier of the node to resolve.
objectGroupOptional
stringSymbolic group name that can be used to release multiple objects.
executionContextIdOptional
Execution context in which to resolve the node.
Return object
object JavaScript object wrapper for given node.
DOM.scrollIntoViewIfNeeded #
Scrolls the specified rect of the given node into view if not already visible. Note: exactly one between nodeId, backendNodeId and objectId should be passed to identify the node.
Parameters
nodeIdOptional
Identifier of the node.
backendNodeIdOptional
Identifier of the backend node.
objectIdOptional
JavaScript object id of the node wrapper.
rectOptional
The rect to be scrolled into view, relative to the node's border box, in CSS pixels. When omitted, center of the node will be used, similar to Element.scrollIntoView.
DOM.setAttributesAsText #
Sets attributes on element with given id. This method is useful when user edits some existing attribute value and types in several attribute name/value pairs.
Parameters
nodeId Id of the element to set attributes for.
text stringText with a number of attributes. Will parse this text using HTML parser.
nameOptional
stringAttribute name to replace with new attributes derived from text in case text parsed successfully.
DOM.setAttributeValue #
Sets attribute for an element with given id.
Parameters
nodeId Id of the element to set attribute for.
name stringAttribute name.
value stringAttribute value.
DOM.setFileInputFiles #
Sets files for the given file input element.
Parameters
files array[ string ]Array of file paths to set.
nodeIdOptional
Identifier of the node.
backendNodeIdOptional
Identifier of the backend node.
objectIdOptional
JavaScript object id of the node wrapper.
DOM.setNodeName #
Sets node name for a node with given id.
Parameters
nodeId Id of the node to set name for.
name stringNew node's name.
Return object
nodeId New node's id.
DOM.setNodeValue #
Sets node value for a node with given id.
Parameters
nodeId Id of the node to set value for.
value stringNew node's value.
DOM.setOuterHTML #
Sets node HTML markup, returns new node id.
Parameters
nodeId Id of the node to set markup for.
outerHTML stringOuter HTML markup to set.
DOM.getFlattenedDocument Deprecated#
Returns the root DOM node (and optionally the subtree) to the caller. Deprecated, as it is not designed to work well with the rest of the DOM agent. Use DOMSnapshot.captureSnapshot instead.
Parameters
depthOptional
integerThe maximum depth at which children should be retrieved, defaults to 1. Use -1 for the entire subtree or provide an integer larger than 0.
pierceOptional
booleanWhether or not iframes and shadow roots should be traversed when returning the subtree (default is false).
Return object
nodes array[ Node ]Resulting node.
DOM.collectClassNamesFromSubtree Experimental#
Collects class names for the node with given id and all of it's child nodes.
Parameters
nodeId Id of the node to collect class names.
Return object
classNames array[ string ]Class name list.
DOM.copyTo Experimental#
Creates a deep copy of the specified node and places it into the target container before the given anchor.
Parameters
nodeId Id of the node to copy.
targetNodeId Id of the element to drop the copy into.
insertBeforeNodeIdOptional
Drop the copy before this node (if absent, the copy becomes the last child of
targetNodeId).
Return object
nodeId Id of the node clone.
DOM.discardSearchResults Experimental#
Discards search results from the session with the given id. getSearchResults should no longer
be called for that search.
Parameters
searchId stringUnique search session identifier.
DOM.forceShowPopover Experimental#
When enabling, this API force-opens the popover identified by nodeId and keeps it open until disabled.
Parameters
nodeId Id of the popover HTMLElement
enable booleanIf true, opens the popover and keeps it open. If false, closes the popover if it was previously force-opened.
Return object
nodeIds array[ NodeId ]List of popovers that were closed in order to respect popover stacking order.
DOM.getAnchorElement Experimental#
Returns the target anchor element of the given anchor query according to https://www.w3.org/TR/css-anchor-position-1/#target.
Parameters
nodeId Id of the positioned element from which to find the anchor.
anchorSpecifierOptional
stringAn optional anchor specifier, as defined in https://www.w3.org/TR/css-anchor-position-1/#anchor-specifier. If not provided, it will return the implicit anchor element for the given positioned element.
Return object
nodeId The anchor element of the given anchor query.
DOM.getContainerForNode Experimental#
Returns the query container of the given node based on container query conditions: containerName, physical and logical axes, and whether it queries scroll-state or anchored elements. If no axes are provided and queriesScrollState is false, the style container is returned, which is the direct parent or the closest element with a matching container-name.
Parameters
nodeId containerNameOptional
stringphysicalAxesOptional
logicalAxesOptional
queriesScrollStateOptional
booleanqueriesAnchoredOptional
booleanReturn object
nodeIdOptional
The container node for the given node, or null if not found.
DOM.getContentQuads Experimental#
Returns quads that describe node position on the page. This method might return multiple quads for inline nodes.
Parameters
nodeIdOptional
Identifier of the node.
backendNodeIdOptional
Identifier of the backend node.
objectIdOptional
JavaScript object id of the node wrapper.
Return object
quads array[ Quad ]Quads that describe node layout relative to viewport.
DOM.getDetachedDomNodes Experimental#
Returns list of detached nodes
Return object
detachedNodes array[ DetachedElementInfo ]The list of detached nodes
DOM.getElementByRelation Experimental#
Returns the NodeId of the matched element according to certain relations.
Parameters
nodeId Id of the node from which to query the relation.
relation stringType of relation to get.
Allowed values: PopoverTarget, InterestTarget, CommandFor
Return object
nodeId NodeId of the element matching the queried relation.
DOM.getFileInfo Experimental#
Returns file information for the given File wrapper.
Parameters
objectId JavaScript object id of the node wrapper.
Return object
path stringDOM.getFrameOwner Experimental#
Returns iframe node that owns iframe with the given domain.
Parameters
frameId Return object
backendNodeId Resulting node.
nodeIdOptional
Id of the node at given coordinates, only when enabled and requested document.
DOM.getNodesForSubtreeByStyle Experimental#
Finds nodes with a given computed style in a subtree.
Parameters
nodeId Node ID pointing to the root of a subtree.
computedStyles array[ CSSComputedStyleProperty ]The style to filter nodes by (includes nodes if any of properties matches).
pierceOptional
booleanWhether or not iframes and shadow roots in the same target should be traversed when returning the results (default is false).
Return object
nodeIds array[ NodeId ]Resulting nodes.
DOM.getNodeStackTraces Experimental#
Gets stack traces associated with a Node. As of now, only provides stack trace for Node creation.
Parameters
nodeId Id of the node to get stack traces for.
Return object
creationOptional
Creation stack trace, if available.
DOM.getQueryingDescendantsForContainer Experimental#
Returns the descendants of a container query container that have container queries against this container.
Parameters
nodeId Id of the container node to find querying descendants from.
Return object
nodeIds array[ NodeId ]Descendant nodes with container queries against the given container.
DOM.getRelayoutBoundary Experimental#
Returns the id of the nearest ancestor that is a relayout boundary.
Parameters
nodeId Id of the node.
Return object
nodeId Relayout boundary node id for the given node.
DOM.getSearchResults Experimental#
Returns search results from given fromIndex to given toIndex from the search with the given
identifier.
Parameters
searchId stringUnique search session identifier.
fromIndex integerStart index of the search result to be returned.
toIndex integerEnd index of the search result to be returned.
Return object
nodeIds array[ NodeId ]Ids of the search result nodes.
DOM.getTopLayerElements Experimental#
Returns NodeIds of current top layer elements. Top layer is rendered closest to the user within a viewport, therefore its elements always appear on top of all other content.
Return object
nodeIds array[ NodeId ]NodeIds of top layer elements
DOM.performSearch Experimental#
Searches for a given string in the DOM tree. Use getSearchResults to access search results or
cancelSearch to end this search session.
Parameters
query stringPlain text or query selector or XPath search query.
includeUserAgentShadowDOMOptional
booleanTrue to search in user agent shadow DOM.
Return object
searchId stringUnique search session identifier.
resultCount integerNumber of search results.
DOM.pushNodeByPathToFrontend Experimental#
Requests that the node is sent to the caller given its path. // FIXME, use XPath
Parameters
path stringPath to node in the proprietary format.
Return object
nodeId Id of the node for given path.
DOM.pushNodesByBackendIdsToFrontend Experimental#
Requests that a batch of nodes is sent to the caller given their backend node ids.
Parameters
backendNodeIds array[ BackendNodeId ]The array of backend node ids.
Return object
nodeIds array[ NodeId ]The array of ids of pushed nodes that correspond to the backend ids specified in backendNodeIds.
DOM.setInspectedNode Experimental#
Enables console to refer to the node with given id via $x (see Command Line API for more details $x functions).
Parameters
nodeId DOM node id to be accessible by means of $x command line API.
DOM.setNodeStackTracesEnabled Experimental#
Sets if stack traces should be captured for Nodes. See Node.getNodeStackTraces. Default is disabled.
Parameters
enable booleanEnable or disable.
Events
DOM.attributeModified #
Fired when Element's attribute is modified.
Parameters
nodeId Id of the node that has changed.
name stringAttribute name.
value stringAttribute value.
DOM.attributeRemoved #
Fired when Element's attribute is removed.
Parameters
nodeId Id of the node that has changed.
name stringA ttribute name.
DOM.characterDataModified #
Mirrors DOMCharacterDataModified event.
Parameters
nodeId Id of the node that has changed.
characterData stringNew text value.
DOM.childNodeCountUpdated #
Fired when Container's child node count has changed.
Parameters
nodeId Id of the node that has changed.
childNodeCount integerNew node count.
DOM.childNodeInserted #
Mirrors DOMNodeInserted event.
Parameters
parentNodeId Id of the node that has changed.
previousNodeId Id of the previous sibling.
node Inserted node data.
DOM.childNodeRemoved #
Mirrors DOMNodeRemoved event.
Parameters
parentNodeId Parent id.
nodeId Id of the node that has been removed.
DOM.setChildNodes #
Fired when backend wants to provide client with the missing DOM structure. This happens upon most of the calls requesting node ids.
Parameters
parentId Parent node id to populate with children.
nodes array[ Node ]Child nodes array.
DOM.affectedByStartingStylesFlagUpdated Experimental#
Fired when a node's starting styles changes.
Parameters
nodeId The id of the node.
affectedByStartingStyles booleanIf the node has starting styles.
DOM.distributedNodesUpdated Experimental#
Called when distribution is changed.
Parameters
insertionPointId Insertion point where distributed nodes were updated.
distributedNodes array[ BackendNode ]Distributed nodes for given insertion point.
DOM.inlineStyleInvalidated Experimental#
Fired when Element's inline style is modified via a CSS property modification.
Parameters
nodeIds array[ NodeId ]Ids of the nodes for which the inline styles have been invalidated.
DOM.pseudoElementAdded Experimental#
Called when a pseudo element is added to an element.
Parameters
parentId Pseudo element's parent element id.
pseudoElement The added pseudo element.
DOM.pseudoElementRemoved Experimental#
Called when a pseudo element is removed from an element.
Parameters
parentId Pseudo element's parent element id.
pseudoElementId The removed pseudo element id.
DOM.scrollableFlagUpdated Experimental#
Fired when a node's scrollability state changes.
Parameters
nodeId The id of the node.
isScrollable booleanIf the node is scrollable.
DOM.shadowRootPopped Experimental#
Called when shadow root is popped from the element.
Parameters
hostId Host element id.
rootId Shadow root id.
Types
DOM.BackendNode #
Backend node with a friendly name.
Type: object
Properties
nodeType integerNode's nodeType.
nodeName stringNode's nodeName.
backendNodeId DOM.BackendNodeId #
Unique DOM node identifier used to reference a node that may not have been pushed to the front-end.
Type: integer
DOM.BoxModel #
Box model.
Type: object
Properties
content Content box
padding Padding box
border Border box
margin Margin box
width integerNode width
height integerNode height
shapeOutsideOptional
Shape outside coordinates
DOM.CompatibilityMode #
Document compatibility mode.
Type: string
Allowed values: QuirksMode, LimitedQuirksMode, NoQuirksMode
DOM.CSSComputedStyleProperty #
Type: object
Properties
name stringComputed style property name.
value stringComputed style property value.
DOM.DetachedElementInfo #
A structure to hold the top-level node of a detached tree and an array of its retained descendants.
Type: object
Properties
treeNode retainedNodeIds array[ NodeId ]DOM.Node #
DOM interaction is implemented in terms of mirror objects that represent the actual DOM nodes. DOMNode is a base node mirror type.
Type: object
Properties
nodeId Node identifier that is passed into the rest of the DOM messages as the nodeId. Backend
will only push node with given id once. It is aware of all requested nodes and will only
fire DOM events for nodes known to the client.
parentIdOptional
The id of the parent node if any.
backendNodeId The BackendNodeId for this node.
nodeType integerNode's nodeType.
nodeName stringNode's nodeName.
localName stringNode's localName.
nodeValue stringNode's nodeValue.
childNodeCountOptional
integerChild count for Container nodes.
childrenOptional
array[ Node ]Child nodes of this node when requested with children.
attributesOptional
array[ string ]Attributes of the Element node in the form of flat array [name1, value1, name2, value2].
documentURLOptional
stringDocument URL that Document or FrameOwner node points to.
baseURLOptional
stringBase URL that Document or FrameOwner node uses for URL completion.
publicIdOptional
stringDocumentType's publicId.
systemIdOptional
stringDocumentType's systemId.
internalSubsetOptional
stringDocumentType's internalSubset.
xmlVersionOptional
stringDocument's XML version in case of XML documents.
nameOptional
stringAttr's name.
valueOptional
stringAttr's value.
pseudoTypeOptional
Pseudo element type for this node.
pseudoIdentifierOptional
stringPseudo element identifier for this node. Only present if there is a valid pseudoType.
shadowRootTypeOptional
Shadow root type.
frameIdOptional
Frame ID for frame owner elements.
contentDocumentOptional
Content document for frame owner elements.
shadowRootsOptional
array[ Node ]Shadow root list for given element host.
templateContentOptional
Content document fragment for template elements.
pseudoElementsOptional
array[ Node ]Pseudo elements associated with this node.
importedDocumentOptional
Deprecated, as the HTML Imports API has been removed (crbug.com/937746). This property used to return the imported document for the HTMLImport links. The property is always undefined now.
distributedNodesOptional
array[ BackendNode ]Distributed nodes for given insertion point.
isSVGOptional
booleanWhether the node is SVG.
compatibilityModeOptional
assignedSlotOptional
isScrollableOptional
booleanExperimentalaffectedByStartingStylesOptional
booleanExperimentalDOM.PhysicalAxes #
ContainerSelector physical axes
Type: string
Allowed values: Horizontal, Vertical, Both
DOM.PseudoType #
Pseudo element type.
Type: string
Allowed values: first-line, first-letter, checkmark, before, after, picker-icon, interest-hint, marker, backdrop, column, selection, search-text, target-text, spelling-error, grammar-error, highlight, first-line-inherited, scroll-marker, scroll-marker-group, scroll-button, scrollbar, scrollbar-thumb, scrollbar-button, scrollbar-track, scrollbar-track-piece, scrollbar-corner, resizer, input-list-button, view-transition, view-transition-group, view-transition-image-pair, view-transition-group-children, view-transition-old, view-transition-new, placeholder, file-selector-button, details-content, picker, permission-icon
DOM.Quad #
An array of quad vertices, x immediately followed by y for each point, points clock-wise.
Type: array[ number ]
DOM.Rect #
Rectangle.
Type: object
Properties
x numberX coordinate
y numberY coordinate
width numberRectangle width
height numberRectangle height
DOM.RGBA #
A structure holding an RGBA color.
Type: object
Properties
r integerThe red component, in the [0-255] range.
g integerThe green component, in the [0-255] range.
b integerThe blue component, in the [0-255] range.
aOptional
numberThe alpha component, in the [0-1] range (default: 1).