CDPotion.Domain.DOM (cdpotion v0.1.4)

Summary

Types

Backend node with a friendly name.

Unique DOM node identifier used to reference a node that may not have been pushed to the front-end.

Box model.

Document compatibility mode.

description not provided :(

ContainerSelector logical axes

DOM interaction is implemented in terms of mirror objects that represent the actual DOM nodes. DOMNode is a base node mirror type.

Unique DOM node identifier.

ContainerSelector physical axes

Pseudo element type.

An array of quad vertices, x immediately followed by y for each point, points clock-wise.

Rectangle.

A structure holding an RGBA color.

Shadow root type.

CSS Shape Outside details.

Functions

Collects class names for the node with given id and all of it's child nodes.

Creates a deep copy of the specified node and places it into the target container before the given anchor.

Describes node given its id, does not require domain to be enabled. Does not start tracking any objects, can be used for automation.

Disables DOM agent for the given page.

Discards search results from the session with the given id. getSearchResults should no longer be called for that search.

Enables DOM agent for the given page.

Returns attributes for the specified node.

Returns the query container of the given node based on container query conditions: containerName, physical, and logical axes. If no axes are provided, the style container is returned, which is the direct parent or the closest element with a matching container-name.

Returns quads that describe node position on the page. This method might return multiple quads for inline nodes.

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

Returns file information for the given File wrapper.

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.

Returns iframe node that owns iframe with the given domain.

Returns node id at given location. Depending on whether DOM domain is enabled, nodeId is either returned or not.

Gets stack traces associated with a Node. As of now, only provides stack trace for Node creation.

Finds nodes with a given computed style in a subtree.

Returns the descendants of a container query container that have container queries against this container.

Returns the id of the nearest ancestor that is a relayout boundary.

Returns search results from given fromIndex to given toIndex from the search with the given identifier.

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.

Hides any highlight.

Highlights DOM node.

Highlights given rectangle.

Marks last undoable state.

Moves node into the new container, places it before the given anchor.

Searches for a given string in the DOM tree. Use getSearchResults to access search results or cancelSearch to end this search session.

Requests that the node is sent to the caller given its path. // FIXME, use XPath

Requests that a batch of nodes is sent to the caller given their backend node ids.

Executes querySelector on a given node.

Executes querySelectorAll on a given node.

Re-does the last undone action.

Removes attribute with given name from an element with given id.

Removes node with given id.

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.

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.

Resolves the JavaScript node object for a given NodeId or BackendNodeId.

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.

Sets attribute for an element with given id.

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.

Enables console to refer to the node with given id via $x (see Command Line API for more details $x functions).

Sets node name for a node with given id.

Sets if stack traces should be captured for Nodes. See Node.getNodeStackTraces. Default is disabled.

Sets node value for a node with given id.

Sets node HTML markup, returns new node id.

Undoes the last performed action.

Types

Link to this type

backend_node()

@type backend_node() :: %{
  backendNodeId: backend_node_id(),
  nodeName: String.t(),
  nodeType: integer()
}

Backend node with a friendly name.

Link to this type

backend_node_id()

@type backend_node_id() :: integer()

Unique DOM node identifier used to reference a node that may not have been pushed to the front-end.

@type box_model() :: %{
  border: quad(),
  content: quad(),
  height: integer(),
  margin: quad(),
  padding: quad(),
  shapeOutside: shape_outside_info() | nil,
  width: integer()
}

Box model.

Link to this type

compatibility_mode()

@type compatibility_mode() :: :QuirksMode | :LimitedQuirksMode | :NoQuirksMode

Document compatibility mode.

Link to this type

css_computed_style_property()

@type css_computed_style_property() :: %{name: String.t(), value: String.t()}

description not provided :(

Link to this type

logical_axes()

@type logical_axes() :: :Inline | :Block | :Both

ContainerSelector logical axes

Link to this type

node_element()

@type node_element() :: %{
  assignedSlot: backend_node() | nil,
  attributes: [String.t()] | nil,
  backendNodeId: backend_node_id(),
  baseURL: String.t() | nil,
  childNodeCount: integer() | nil,
  children: [node_element()] | nil,
  compatibilityMode: compatibility_mode() | nil,
  contentDocument: node_element() | nil,
  distributedNodes: [backend_node()] | nil,
  documentURL: String.t() | nil,
  frameId: CDPotion.Domain.Page.frame_id() | nil,
  importedDocument: node_element() | nil,
  internalSubset: String.t() | nil,
  isSVG: boolean() | nil,
  localName: String.t(),
  name: String.t() | nil,
  nodeId: node_id(),
  nodeName: String.t(),
  nodeType: integer(),
  nodeValue: String.t(),
  parentId: node_id() | nil,
  pseudoElements: [node_element()] | nil,
  pseudoIdentifier: String.t() | nil,
  pseudoType: pseudo_type() | nil,
  publicId: String.t() | nil,
  shadowRootType: shadow_root_type() | nil,
  shadowRoots: [node_element()] | nil,
  systemId: String.t() | nil,
  templateContent: node_element() | nil,
  value: String.t() | nil,
  xmlVersion: String.t() | nil
}

DOM interaction is implemented in terms of mirror objects that represent the actual DOM nodes. DOMNode is a base node mirror type.

@type node_id() :: integer()

Unique DOM node identifier.

Link to this type

physical_axes()

@type physical_axes() :: :Horizontal | :Vertical | :Both

ContainerSelector physical axes

Link to this type

pseudo_type()

@type pseudo_type() ::
  :"first-line"
  | :"first-letter"
  | :before
  | :after
  | :marker
  | :backdrop
  | :selection
  | :"target-text"
  | :"spelling-error"
  | :"grammar-error"
  | :highlight
  | :"first-line-inherited"
  | :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-old"
  | :"view-transition-new"

Pseudo element type.

@type quad() :: [number()]

An array of quad vertices, x immediately followed by y for each point, points clock-wise.

@type rect() :: %{height: number(), width: number(), x: number(), y: number()}

Rectangle.

@type rgba() :: %{a: number() | nil, b: integer(), g: integer(), r: integer()}

A structure holding an RGBA color.

Link to this type

shadow_root_type()

@type shadow_root_type() :: :"user-agent" | :open | :closed

Shadow root type.

Link to this type

shape_outside_info()

@type shape_outside_info() :: %{bounds: quad(), marginShape: [any()], shape: [any()]}

CSS Shape Outside details.

Functions

Link to this function

collect_class_names_from_subtree(node_id)

@spec collect_class_names_from_subtree(node_id()) :: {String.t(), map()}

Collects class names for the node with given id and all of it's child nodes.

Parameters:

  • (Required) node_id: Id of the node to collect class names.
Link to this function

copy_to(node_id, target_node_id, insert_before_node_id \\ nil)

@spec copy_to(
  node_id(),
  node_id(),
  node_id()
) :: {String.t(), map()}

Creates a deep copy of the specified node and places it into the target container before the given anchor.

Parameters:

  • (Required) node_id: Id of the node to copy.
  • (Required) target_node_id: Id of the element to drop the copy into.
  • (Optional) insert_before_node_id: Drop the copy before this node (if absent, the copy becomes the last child of targetNodeId).
Link to this function

describe_node(node_id \\ nil, backend_node_id \\ nil, object_id \\ nil, depth \\ nil, pierce \\ nil)

Describes node given its id, does not require domain to be enabled. Does not start tracking any objects, can be used for automation.

Parameters:

  • (Optional) node_id: Identifier of the node.
  • (Optional) backend_node_id: Identifier of the backend node.
  • (Optional) object_id: JavaScript object id of the node wrapper.
  • (Optional) depth: The maximum depth at which children should be retrieved, defaults to 1. Use -1 for the entire subtree or provide an integer larger than 0.
  • (Optional) pierce: Whether or not iframes and shadow roots should be traversed when returning the subtree (default is false).
@spec disable() :: {String.t(), map()}

Disables DOM agent for the given page.

Link to this function

discard_search_results(search_id)

@spec discard_search_results(String.t()) :: {String.t(), map()}

Discards search results from the session with the given id. getSearchResults should no longer be called for that search.

Parameters:

  • (Required) search_id: Unique search session identifier.
Link to this function

enable(include_whitespace \\ nil)

@spec enable(String.t()) :: {String.t(), map()}

Enables DOM agent for the given page.

Parameters:

  • (Optional) include_whitespace: Whether to include whitespaces in the children array of returned Nodes.
Link to this function

focus(node_id \\ nil, backend_node_id \\ nil, object_id \\ nil)

Focuses the given element.

Parameters:

  • (Optional) node_id: Identifier of the node.
  • (Optional) backend_node_id: Identifier of the backend node.
  • (Optional) object_id: JavaScript object id of the node wrapper.
Link to this function

get_attributes(node_id)

@spec get_attributes(node_id()) :: {String.t(), map()}

Returns attributes for the specified node.

Parameters:

  • (Required) node_id: Id of the node to retrieve attibutes for.
Link to this function

get_box_model(node_id \\ nil, backend_node_id \\ nil, object_id \\ nil)

Returns boxes for the given node.

Parameters:

  • (Optional) node_id: Identifier of the node.
  • (Optional) backend_node_id: Identifier of the backend node.
  • (Optional) object_id: JavaScript object id of the node wrapper.
Link to this function

get_container_for_node(node_id, container_name \\ nil, physical_axes \\ nil, logical_axes \\ nil)

@spec get_container_for_node(
  node_id(),
  String.t(),
  physical_axes(),
  logical_axes()
) :: {String.t(), map()}

Returns the query container of the given node based on container query conditions: containerName, physical, and logical axes. If no axes are provided, the style container is returned, which is the direct parent or the closest element with a matching container-name.

Parameters:

  • (Required) node_id: description not provided :(
  • (Optional) container_name: description not provided :(
  • (Optional) physical_axes: description not provided :(
  • (Optional) logical_axes: description not provided :(
Link to this function

get_content_quads(node_id \\ nil, backend_node_id \\ nil, object_id \\ nil)

@spec get_content_quads(
  node_id(),
  backend_node_id(),
  CDPotion.Domain.Runtime.remote_object_id()
) :: {String.t(), map()}

Returns quads that describe node position on the page. This method might return multiple quads for inline nodes.

Parameters:

  • (Optional) node_id: Identifier of the node.
  • (Optional) backend_node_id: Identifier of the backend node.
  • (Optional) object_id: JavaScript object id of the node wrapper.
Link to this function

get_document(depth \\ nil, pierce \\ nil)

@spec get_document(integer(), boolean()) :: {String.t(), map()}

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

Parameters:

  • (Optional) depth: The maximum depth at which children should be retrieved, defaults to 1. Use -1 for the entire subtree or provide an integer larger than 0.
  • (Optional) pierce: Whether or not iframes and shadow roots should be traversed when returning the subtree (default is false).
Link to this function

get_file_info(object_id)

@spec get_file_info(CDPotion.Domain.Runtime.remote_object_id()) :: {String.t(), map()}

Returns file information for the given File wrapper.

Parameters:

  • (Required) object_id: JavaScript object id of the node wrapper.
Link to this function

get_flattened_document(depth \\ nil, pierce \\ nil)

@spec get_flattened_document(integer(), boolean()) :: {String.t(), map()}

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:

  • (Optional) depth: The maximum depth at which children should be retrieved, defaults to 1. Use -1 for the entire subtree or provide an integer larger than 0.
  • (Optional) pierce: Whether or not iframes and shadow roots should be traversed when returning the subtree (default is false).
Link to this function

get_frame_owner(frame_id)

@spec get_frame_owner(CDPotion.Domain.Page.frame_id()) :: {String.t(), map()}

Returns iframe node that owns iframe with the given domain.

Parameters:

  • (Required) frame_id: description not provided :(
Link to this function

get_node_for_location(x, y, include_user_agent_shadow_dom \\ nil, ignore_pointer_events_none \\ nil)

@spec get_node_for_location(integer(), integer(), boolean(), boolean()) ::
  {String.t(), map()}

Returns node id at given location. Depending on whether DOM domain is enabled, nodeId is either returned or not.

Parameters:

  • (Required) x: X coordinate.
  • (Required) y: Y coordinate.
  • (Optional) include_user_agent_shadow_dom: False to skip to the nearest non-UA shadow root ancestor (default: false).
  • (Optional) ignore_pointer_events_none: Whether to ignore pointer-events: none on elements and hit test them.
Link to this function

get_node_stack_traces(node_id)

@spec get_node_stack_traces(node_id()) :: {String.t(), map()}

Gets stack traces associated with a Node. As of now, only provides stack trace for Node creation.

Parameters:

  • (Required) node_id: Id of the node to get stack traces for.
Link to this function

get_nodes_for_subtree_by_style(node_id, computed_styles, pierce \\ nil)

@spec get_nodes_for_subtree_by_style(
  node_id(),
  [css_computed_style_property()],
  boolean()
) :: {String.t(), map()}

Finds nodes with a given computed style in a subtree.

Parameters:

  • (Required) node_id: Node ID pointing to the root of a subtree.
  • (Required) computed_styles: The style to filter nodes by (includes nodes if any of properties matches).
  • (Optional) pierce: Whether or not iframes and shadow roots in the same target should be traversed when returning the results (default is false).
Link to this function

get_outer_html(node_id \\ nil, backend_node_id \\ nil, object_id \\ nil)

Returns node's HTML markup.

Parameters:

  • (Optional) node_id: Identifier of the node.
  • (Optional) backend_node_id: Identifier of the backend node.
  • (Optional) object_id: JavaScript object id of the node wrapper.
Link to this function

get_querying_descendants_for_container(node_id)

@spec get_querying_descendants_for_container(node_id()) :: {String.t(), map()}

Returns the descendants of a container query container that have container queries against this container.

Parameters:

  • (Required) node_id: Id of the container node to find querying descendants from.
Link to this function

get_relayout_boundary(node_id)

@spec get_relayout_boundary(node_id()) :: {String.t(), map()}

Returns the id of the nearest ancestor that is a relayout boundary.

Parameters:

  • (Required) node_id: Id of the node.
Link to this function

get_search_results(search_id, from_index, to_index)

@spec get_search_results(String.t(), integer(), integer()) :: {String.t(), map()}

Returns search results from given fromIndex to given toIndex from the search with the given identifier.

Parameters:

  • (Required) search_id: Unique search session identifier.
  • (Required) from_index: Start index of the search result to be returned.
  • (Required) to_index: End index of the search result to be returned.
Link to this function

get_top_layer_elements()

@spec get_top_layer_elements() :: {String.t(), map()}

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.

Link to this function

hide_highlight()

@spec hide_highlight() :: {String.t(), map()}

Hides any highlight.

Link to this function

highlight_node()

@spec highlight_node() :: {String.t(), map()}

Highlights DOM node.

Link to this function

highlight_rect()

@spec highlight_rect() :: {String.t(), map()}

Highlights given rectangle.

Link to this function

mark_undoable_state()

@spec mark_undoable_state() :: {String.t(), map()}

Marks last undoable state.

Link to this function

move_to(node_id, target_node_id, insert_before_node_id \\ nil)

@spec move_to(
  node_id(),
  node_id(),
  node_id()
) :: {String.t(), map()}

Moves node into the new container, places it before the given anchor.

Parameters:

  • (Required) node_id: Id of the node to move.
  • (Required) target_node_id: Id of the element to drop the moved node into.
  • (Optional) insert_before_node_id: Drop node before this one (if absent, the moved node becomes the last child of targetNodeId).
Link to this function

perform_search(query, include_user_agent_shadow_dom \\ nil)

@spec perform_search(String.t(), boolean()) :: {String.t(), map()}

Searches for a given string in the DOM tree. Use getSearchResults to access search results or cancelSearch to end this search session.

Parameters:

  • (Required) query: Plain text or query selector or XPath search query.
  • (Optional) include_user_agent_shadow_dom: True to search in user agent shadow DOM.
Link to this function

push_node_by_path_to_frontend(path)

@spec push_node_by_path_to_frontend(String.t()) :: {String.t(), map()}

Requests that the node is sent to the caller given its path. // FIXME, use XPath

Parameters:

  • (Required) path: Path to node in the proprietary format.
Link to this function

push_nodes_by_backend_ids_to_frontend(backend_node_ids)

@spec push_nodes_by_backend_ids_to_frontend([backend_node_id()]) ::
  {String.t(), map()}

Requests that a batch of nodes is sent to the caller given their backend node ids.

Parameters:

  • (Required) backend_node_ids: The array of backend node ids.
Link to this function

query_selector(node_id, selector)

@spec query_selector(node_id(), String.t()) :: {String.t(), map()}

Executes querySelector on a given node.

Parameters:

  • (Required) node_id: Id of the node to query upon.
  • (Required) selector: Selector string.
Link to this function

query_selector_all(node_id, selector)

@spec query_selector_all(node_id(), String.t()) :: {String.t(), map()}

Executes querySelectorAll on a given node.

Parameters:

  • (Required) node_id: Id of the node to query upon.
  • (Required) selector: Selector string.
@spec redo() :: {String.t(), map()}

Re-does the last undone action.

Link to this function

remove_attribute(node_id, name)

@spec remove_attribute(node_id(), String.t()) :: {String.t(), map()}

Removes attribute with given name from an element with given id.

Parameters:

  • (Required) node_id: Id of the element to remove attribute from.
  • (Required) name: Name of the attribute to remove.
Link to this function

remove_node(node_id)

@spec remove_node(node_id()) :: {String.t(), map()}

Removes node with given id.

Parameters:

  • (Required) node_id: Id of the node to remove.
Link to this function

request_child_nodes(node_id, depth \\ nil, pierce \\ nil)

@spec request_child_nodes(node_id(), integer(), boolean()) :: {String.t(), map()}

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:

  • (Required) node_id: Id of the node to get children for.
  • (Optional) depth: The maximum depth at which children should be retrieved, defaults to 1. Use -1 for the entire subtree or provide an integer larger than 0.
  • (Optional) pierce: Whether or not iframes and shadow roots should be traversed when returning the sub-tree (default is false).
Link to this function

request_node(object_id)

@spec request_node(CDPotion.Domain.Runtime.remote_object_id()) :: {String.t(), map()}

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:

  • (Required) object_id: JavaScript object id to convert into node.
Link to this function

resolve_node(node_id \\ nil, backend_node_id \\ nil, object_group \\ nil, execution_context_id \\ nil)

Resolves the JavaScript node object for a given NodeId or BackendNodeId.

Parameters:

  • (Optional) node_id: Id of the node to resolve.
  • (Optional) backend_node_id: Backend identifier of the node to resolve.
  • (Optional) object_group: Symbolic group name that can be used to release multiple objects.
  • (Optional) execution_context_id: Execution context in which to resolve the node.
Link to this function

scroll_into_view_if_needed(node_id \\ nil, backend_node_id \\ nil, object_id \\ nil, rect \\ nil)

@spec scroll_into_view_if_needed(
  node_id(),
  backend_node_id(),
  CDPotion.Domain.Runtime.remote_object_id(),
  rect()
) :: {String.t(), map()}

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:

  • (Optional) node_id: Identifier of the node.
  • (Optional) backend_node_id: Identifier of the backend node.
  • (Optional) object_id: JavaScript object id of the node wrapper.
  • (Optional) rect: 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.
Link to this function

set_attribute_value(node_id, name, value)

@spec set_attribute_value(node_id(), String.t(), String.t()) :: {String.t(), map()}

Sets attribute for an element with given id.

Parameters:

  • (Required) node_id: Id of the element to set attribute for.
  • (Required) name: Attribute name.
  • (Required) value: Attribute value.
Link to this function

set_attributes_as_text(node_id, text, name \\ nil)

@spec set_attributes_as_text(node_id(), String.t(), String.t()) :: {String.t(), map()}

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:

  • (Required) node_id: Id of the element to set attributes for.
  • (Required) text: Text with a number of attributes. Will parse this text using HTML parser.
  • (Optional) name: Attribute name to replace with new attributes derived from text in case text parsed successfully.
Link to this function

set_file_input_files(files, node_id \\ nil, backend_node_id \\ nil, object_id \\ nil)

@spec set_file_input_files(
  [String.t()],
  node_id(),
  backend_node_id(),
  CDPotion.Domain.Runtime.remote_object_id()
) :: {String.t(), map()}

Sets files for the given file input element.

Parameters:

  • (Required) files: Array of file paths to set.
  • (Optional) node_id: Identifier of the node.
  • (Optional) backend_node_id: Identifier of the backend node.
  • (Optional) object_id: JavaScript object id of the node wrapper.
Link to this function

set_inspected_node(node_id)

@spec set_inspected_node(node_id()) :: {String.t(), map()}

Enables console to refer to the node with given id via $x (see Command Line API for more details $x functions).

Parameters:

  • (Required) node_id: DOM node id to be accessible by means of $x command line API.
Link to this function

set_node_name(node_id, name)

@spec set_node_name(node_id(), String.t()) :: {String.t(), map()}

Sets node name for a node with given id.

Parameters:

  • (Required) node_id: Id of the node to set name for.
  • (Required) name: New node's name.
Link to this function

set_node_stack_traces_enabled(enable)

@spec set_node_stack_traces_enabled(boolean()) :: {String.t(), map()}

Sets if stack traces should be captured for Nodes. See Node.getNodeStackTraces. Default is disabled.

Parameters:

  • (Required) enable: Enable or disable.
Link to this function

set_node_value(node_id, value)

@spec set_node_value(node_id(), String.t()) :: {String.t(), map()}

Sets node value for a node with given id.

Parameters:

  • (Required) node_id: Id of the node to set value for.
  • (Required) value: New node's value.
Link to this function

set_outer_html(node_id, outer_html)

@spec set_outer_html(node_id(), String.t()) :: {String.t(), map()}

Sets node HTML markup, returns new node id.

Parameters:

  • (Required) node_id: Id of the node to set markup for.
  • (Required) outer_html: Outer HTML markup to set.
@spec undo() :: {String.t(), map()}

Undoes the last performed action.