← Back to DOM domain

DOM.getDocument

Returns the root DOM node (and optionally the subtree) to the caller. Implicitly enables the DOM domain events for the current target.

Domain: DOM stable

Parameters

NameTypeDescription
depth (optional)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.
pierce (optional)booleanWhether or not iframes and shadow roots should be traversed when returning the subtree (default is false).

Returns

NameTypeDescription
rootNodeResulting node.

Example Request

{
  "id": 1,
  "method": "DOM.getDocument"
}

Example Response

{
  "id": 1,
  "result": {
    "root": {
      "nodeId": 1,
      "nodeType": 9,
      "nodeName": "#document",
      "childNodeCount": 2
    }
  }
}

Usage in Node.js

const result = await send('DOM.getDocument');
console.log(result);
// {"root": {"nodeId": 1, "nodeType": 9, "nodeName": "#document", "childNodeCount": 2}}