Skip to content

dom_debugger

CSPViolationType

Bases: Enum

CSP Violation type.

Source code in zendriver/cdp/dom_debugger.py
class CSPViolationType(enum.Enum):
    """
    CSP Violation type.
    """

    TRUSTEDTYPE_SINK_VIOLATION = "trustedtype-sink-violation"
    TRUSTEDTYPE_POLICY_VIOLATION = "trustedtype-policy-violation"

    def to_json(self) -> str:
        return self.value

    @classmethod
    def from_json(cls, json: str) -> CSPViolationType:
        return cls(json)

TRUSTEDTYPE_POLICY_VIOLATION = 'trustedtype-policy-violation' class-attribute instance-attribute

TRUSTEDTYPE_SINK_VIOLATION = 'trustedtype-sink-violation' class-attribute instance-attribute

from_json(json) classmethod

Source code in zendriver/cdp/dom_debugger.py
@classmethod
def from_json(cls, json: str) -> CSPViolationType:
    return cls(json)

to_json()

Source code in zendriver/cdp/dom_debugger.py
def to_json(self) -> str:
    return self.value

DOMBreakpointType

Bases: Enum

DOM breakpoint type.

Source code in zendriver/cdp/dom_debugger.py
class DOMBreakpointType(enum.Enum):
    """
    DOM breakpoint type.
    """

    SUBTREE_MODIFIED = "subtree-modified"
    ATTRIBUTE_MODIFIED = "attribute-modified"
    NODE_REMOVED = "node-removed"

    def to_json(self) -> str:
        return self.value

    @classmethod
    def from_json(cls, json: str) -> DOMBreakpointType:
        return cls(json)

ATTRIBUTE_MODIFIED = 'attribute-modified' class-attribute instance-attribute

NODE_REMOVED = 'node-removed' class-attribute instance-attribute

SUBTREE_MODIFIED = 'subtree-modified' class-attribute instance-attribute

from_json(json) classmethod

Source code in zendriver/cdp/dom_debugger.py
@classmethod
def from_json(cls, json: str) -> DOMBreakpointType:
    return cls(json)

to_json()

Source code in zendriver/cdp/dom_debugger.py
def to_json(self) -> str:
    return self.value

EventListener dataclass

Object event listener.

Source code in zendriver/cdp/dom_debugger.py
@dataclass
class EventListener:
    """
    Object event listener.
    """

    #: ``EventListener``'s type.
    type_: str

    #: ``EventListener``'s useCapture.
    use_capture: bool

    #: ``EventListener``'s passive flag.
    passive: bool

    #: ``EventListener``'s once flag.
    once: bool

    #: Script id of the handler code.
    script_id: runtime.ScriptId

    #: Line number in the script (0-based).
    line_number: int

    #: Column number in the script (0-based).
    column_number: int

    #: Event handler function value.
    handler: typing.Optional[runtime.RemoteObject] = None

    #: Event original handler function value.
    original_handler: typing.Optional[runtime.RemoteObject] = None

    #: Node the listener is added to (if any).
    backend_node_id: typing.Optional[dom.BackendNodeId] = None

    def to_json(self) -> T_JSON_DICT:
        json: T_JSON_DICT = dict()
        json["type"] = self.type_
        json["useCapture"] = self.use_capture
        json["passive"] = self.passive
        json["once"] = self.once
        json["scriptId"] = self.script_id.to_json()
        json["lineNumber"] = self.line_number
        json["columnNumber"] = self.column_number
        if self.handler is not None:
            json["handler"] = self.handler.to_json()
        if self.original_handler is not None:
            json["originalHandler"] = self.original_handler.to_json()
        if self.backend_node_id is not None:
            json["backendNodeId"] = self.backend_node_id.to_json()
        return json

    @classmethod
    def from_json(cls, json: T_JSON_DICT) -> EventListener:
        return cls(
            type_=str(json["type"]),
            use_capture=bool(json["useCapture"]),
            passive=bool(json["passive"]),
            once=bool(json["once"]),
            script_id=runtime.ScriptId.from_json(json["scriptId"]),
            line_number=int(json["lineNumber"]),
            column_number=int(json["columnNumber"]),
            handler=runtime.RemoteObject.from_json(json["handler"])
            if json.get("handler", None) is not None
            else None,
            original_handler=runtime.RemoteObject.from_json(json["originalHandler"])
            if json.get("originalHandler", None) is not None
            else None,
            backend_node_id=dom.BackendNodeId.from_json(json["backendNodeId"])
            if json.get("backendNodeId", None) is not None
            else None,
        )

backend_node_id: typing.Optional[dom.BackendNodeId] = None class-attribute instance-attribute

column_number: int instance-attribute

handler: typing.Optional[runtime.RemoteObject] = None class-attribute instance-attribute

line_number: int instance-attribute

once: bool instance-attribute

original_handler: typing.Optional[runtime.RemoteObject] = None class-attribute instance-attribute

passive: bool instance-attribute

script_id: runtime.ScriptId instance-attribute

type_: str instance-attribute

use_capture: bool instance-attribute

__init__(type_, use_capture, passive, once, script_id, line_number, column_number, handler=None, original_handler=None, backend_node_id=None)

from_json(json) classmethod

Source code in zendriver/cdp/dom_debugger.py
@classmethod
def from_json(cls, json: T_JSON_DICT) -> EventListener:
    return cls(
        type_=str(json["type"]),
        use_capture=bool(json["useCapture"]),
        passive=bool(json["passive"]),
        once=bool(json["once"]),
        script_id=runtime.ScriptId.from_json(json["scriptId"]),
        line_number=int(json["lineNumber"]),
        column_number=int(json["columnNumber"]),
        handler=runtime.RemoteObject.from_json(json["handler"])
        if json.get("handler", None) is not None
        else None,
        original_handler=runtime.RemoteObject.from_json(json["originalHandler"])
        if json.get("originalHandler", None) is not None
        else None,
        backend_node_id=dom.BackendNodeId.from_json(json["backendNodeId"])
        if json.get("backendNodeId", None) is not None
        else None,
    )

to_json()

Source code in zendriver/cdp/dom_debugger.py
def to_json(self) -> T_JSON_DICT:
    json: T_JSON_DICT = dict()
    json["type"] = self.type_
    json["useCapture"] = self.use_capture
    json["passive"] = self.passive
    json["once"] = self.once
    json["scriptId"] = self.script_id.to_json()
    json["lineNumber"] = self.line_number
    json["columnNumber"] = self.column_number
    if self.handler is not None:
        json["handler"] = self.handler.to_json()
    if self.original_handler is not None:
        json["originalHandler"] = self.original_handler.to_json()
    if self.backend_node_id is not None:
        json["backendNodeId"] = self.backend_node_id.to_json()
    return json

get_event_listeners(object_id, depth=None, pierce=None)

Returns event listeners of the given object.

Parameters:

Name Type Description Default
object_id RemoteObjectId

Identifier of the object to return listeners for.

required
depth Optional[int]

(Optional) The maximum depth at which Node children should be retrieved, defaults to 1. Use -1 for the entire subtree or provide an integer larger than 0.

None
pierce Optional[bool]

(Optional) Whether or not iframes and shadow roots should be traversed when returning the subtree (default is false). Reports listeners for all contexts if pierce is enabled.

None

Returns:

Type Description
Generator[T_JSON_DICT, T_JSON_DICT, List[EventListener]]

Array of relevant listeners.

Source code in zendriver/cdp/dom_debugger.py
def get_event_listeners(
    object_id: runtime.RemoteObjectId,
    depth: typing.Optional[int] = None,
    pierce: typing.Optional[bool] = None,
) -> typing.Generator[T_JSON_DICT, T_JSON_DICT, typing.List[EventListener]]:
    """
    Returns event listeners of the given object.

    :param object_id: Identifier of the object to return listeners for.
    :param depth: *(Optional)* The maximum depth at which Node children should be retrieved, defaults to 1. Use -1 for the entire subtree or provide an integer larger than 0.
    :param pierce: *(Optional)* Whether or not iframes and shadow roots should be traversed when returning the subtree (default is false). Reports listeners for all contexts if pierce is enabled.
    :returns: Array of relevant listeners.
    """
    params: T_JSON_DICT = dict()
    params["objectId"] = object_id.to_json()
    if depth is not None:
        params["depth"] = depth
    if pierce is not None:
        params["pierce"] = pierce
    cmd_dict: T_JSON_DICT = {
        "method": "DOMDebugger.getEventListeners",
        "params": params,
    }
    json = yield cmd_dict
    return [EventListener.from_json(i) for i in json["listeners"]]

remove_dom_breakpoint(node_id, type_)

Removes DOM breakpoint that was set using setDOMBreakpoint.

Parameters:

Name Type Description Default
node_id NodeId

Identifier of the node to remove breakpoint from.

required
type_ DOMBreakpointType

Type of the breakpoint to remove.

required
Source code in zendriver/cdp/dom_debugger.py
def remove_dom_breakpoint(
    node_id: dom.NodeId, type_: DOMBreakpointType
) -> typing.Generator[T_JSON_DICT, T_JSON_DICT, None]:
    """
    Removes DOM breakpoint that was set using ``setDOMBreakpoint``.

    :param node_id: Identifier of the node to remove breakpoint from.
    :param type_: Type of the breakpoint to remove.
    """
    params: T_JSON_DICT = dict()
    params["nodeId"] = node_id.to_json()
    params["type"] = type_.to_json()
    cmd_dict: T_JSON_DICT = {
        "method": "DOMDebugger.removeDOMBreakpoint",
        "params": params,
    }
    json = yield cmd_dict

remove_event_listener_breakpoint(event_name, target_name=None)

Removes breakpoint on particular DOM event.

Parameters:

Name Type Description Default
event_name str

Event name.

required
target_name Optional[str]

(EXPERIMENTAL) (Optional) EventTarget interface name.

None
Source code in zendriver/cdp/dom_debugger.py
def remove_event_listener_breakpoint(
    event_name: str, target_name: typing.Optional[str] = None
) -> typing.Generator[T_JSON_DICT, T_JSON_DICT, None]:
    """
    Removes breakpoint on particular DOM event.

    :param event_name: Event name.
    :param target_name: **(EXPERIMENTAL)** *(Optional)* EventTarget interface name.
    """
    params: T_JSON_DICT = dict()
    params["eventName"] = event_name
    if target_name is not None:
        params["targetName"] = target_name
    cmd_dict: T_JSON_DICT = {
        "method": "DOMDebugger.removeEventListenerBreakpoint",
        "params": params,
    }
    json = yield cmd_dict

remove_instrumentation_breakpoint(event_name)

Removes breakpoint on particular native event.

.. deprecated:: 1.3

EXPERIMENTAL

Parameters:

Name Type Description Default
event_name str

Instrumentation name to stop on.

required
Source code in zendriver/cdp/dom_debugger.py
@deprecated(version="1.3")
def remove_instrumentation_breakpoint(
    event_name: str,
) -> typing.Generator[T_JSON_DICT, T_JSON_DICT, None]:
    """
    Removes breakpoint on particular native event.

    .. deprecated:: 1.3

    **EXPERIMENTAL**

    :param event_name: Instrumentation name to stop on.
    """
    params: T_JSON_DICT = dict()
    params["eventName"] = event_name
    cmd_dict: T_JSON_DICT = {
        "method": "DOMDebugger.removeInstrumentationBreakpoint",
        "params": params,
    }
    json = yield cmd_dict

remove_xhr_breakpoint(url)

Removes breakpoint from XMLHttpRequest.

Parameters:

Name Type Description Default
url str

Resource URL substring.

required
Source code in zendriver/cdp/dom_debugger.py
def remove_xhr_breakpoint(url: str) -> typing.Generator[T_JSON_DICT, T_JSON_DICT, None]:
    """
    Removes breakpoint from XMLHttpRequest.

    :param url: Resource URL substring.
    """
    params: T_JSON_DICT = dict()
    params["url"] = url
    cmd_dict: T_JSON_DICT = {
        "method": "DOMDebugger.removeXHRBreakpoint",
        "params": params,
    }
    json = yield cmd_dict

set_break_on_csp_violation(violation_types)

Sets breakpoint on particular CSP violations.

EXPERIMENTAL

Parameters:

Name Type Description Default
violation_types List[CSPViolationType]

CSP Violations to stop upon.

required
Source code in zendriver/cdp/dom_debugger.py
def set_break_on_csp_violation(
    violation_types: typing.List[CSPViolationType],
) -> typing.Generator[T_JSON_DICT, T_JSON_DICT, None]:
    """
    Sets breakpoint on particular CSP violations.

    **EXPERIMENTAL**

    :param violation_types: CSP Violations to stop upon.
    """
    params: T_JSON_DICT = dict()
    params["violationTypes"] = [i.to_json() for i in violation_types]
    cmd_dict: T_JSON_DICT = {
        "method": "DOMDebugger.setBreakOnCSPViolation",
        "params": params,
    }
    json = yield cmd_dict

set_dom_breakpoint(node_id, type_)

Sets breakpoint on particular operation with DOM.

Parameters:

Name Type Description Default
node_id NodeId

Identifier of the node to set breakpoint on.

required
type_ DOMBreakpointType

Type of the operation to stop upon.

required
Source code in zendriver/cdp/dom_debugger.py
def set_dom_breakpoint(
    node_id: dom.NodeId, type_: DOMBreakpointType
) -> typing.Generator[T_JSON_DICT, T_JSON_DICT, None]:
    """
    Sets breakpoint on particular operation with DOM.

    :param node_id: Identifier of the node to set breakpoint on.
    :param type_: Type of the operation to stop upon.
    """
    params: T_JSON_DICT = dict()
    params["nodeId"] = node_id.to_json()
    params["type"] = type_.to_json()
    cmd_dict: T_JSON_DICT = {
        "method": "DOMDebugger.setDOMBreakpoint",
        "params": params,
    }
    json = yield cmd_dict

set_event_listener_breakpoint(event_name, target_name=None)

Sets breakpoint on particular DOM event.

Parameters:

Name Type Description Default
event_name str

DOM Event name to stop on (any DOM event will do).

required
target_name Optional[str]

(EXPERIMENTAL) (Optional) EventTarget interface name to stop on. If equal to "*" or not provided, will stop on any EventTarget.

None
Source code in zendriver/cdp/dom_debugger.py
def set_event_listener_breakpoint(
    event_name: str, target_name: typing.Optional[str] = None
) -> typing.Generator[T_JSON_DICT, T_JSON_DICT, None]:
    """
    Sets breakpoint on particular DOM event.

    :param event_name: DOM Event name to stop on (any DOM event will do).
    :param target_name: **(EXPERIMENTAL)** *(Optional)* EventTarget interface name to stop on. If equal to ```"*"``` or not provided, will stop on any EventTarget.
    """
    params: T_JSON_DICT = dict()
    params["eventName"] = event_name
    if target_name is not None:
        params["targetName"] = target_name
    cmd_dict: T_JSON_DICT = {
        "method": "DOMDebugger.setEventListenerBreakpoint",
        "params": params,
    }
    json = yield cmd_dict

set_instrumentation_breakpoint(event_name)

Sets breakpoint on particular native event.

.. deprecated:: 1.3

EXPERIMENTAL

Parameters:

Name Type Description Default
event_name str

Instrumentation name to stop on.

required
Source code in zendriver/cdp/dom_debugger.py
@deprecated(version="1.3")
def set_instrumentation_breakpoint(
    event_name: str,
) -> typing.Generator[T_JSON_DICT, T_JSON_DICT, None]:
    """
    Sets breakpoint on particular native event.

    .. deprecated:: 1.3

    **EXPERIMENTAL**

    :param event_name: Instrumentation name to stop on.
    """
    params: T_JSON_DICT = dict()
    params["eventName"] = event_name
    cmd_dict: T_JSON_DICT = {
        "method": "DOMDebugger.setInstrumentationBreakpoint",
        "params": params,
    }
    json = yield cmd_dict

set_xhr_breakpoint(url)

Sets breakpoint on XMLHttpRequest.

Parameters:

Name Type Description Default
url str

Resource URL substring. All XHRs having this substring in the URL will get stopped upon.

required
Source code in zendriver/cdp/dom_debugger.py
def set_xhr_breakpoint(url: str) -> typing.Generator[T_JSON_DICT, T_JSON_DICT, None]:
    """
    Sets breakpoint on XMLHttpRequest.

    :param url: Resource URL substring. All XHRs having this substring in the URL will get stopped upon.
    """
    params: T_JSON_DICT = dict()
    params["url"] = url
    cmd_dict: T_JSON_DICT = {
        "method": "DOMDebugger.setXHRBreakpoint",
        "params": params,
    }
    json = yield cmd_dict