cdp-driver 0.5.0

Chrome DevTools Protocol (CDP) client for Rust: every command, event and type generated from the schema, with sessions, for browser automation and AI agents
Documentation
// @generated by `just generate-methods` from protocol/*.json.
// Do not edit by hand; edit xtask/ and regenerate.

//! DOM debugging allows setting breakpoints on particular DOM operations and
//! events. JavaScript execution will stop on these operations as if there was
//! a regular breakpoint set.
//!
//! Types, command parameters and event payloads for the `DOMDebugger`
//! domain. The method-name constants for the same domain are in
//! [`crate::methods`].

use serde::{Deserialize, Serialize};

/// DOM breakpoint type.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum DomBreakpointType {
    /// `subtree-modified`
    #[serde(rename = "subtree-modified")]
    SubtreeModified,
    /// `attribute-modified`
    #[serde(rename = "attribute-modified")]
    AttributeModified,
    /// `node-removed`
    #[serde(rename = "node-removed")]
    NodeRemoved,
    /// A value this vendored schema does not list. Chrome adds values ahead of
    /// the published protocol, so an unrecognised one is kept as it arrived
    /// rather than failing the payload it came in.
    #[serde(untagged)]
    Unrecognized(String),
}

/// CSP Violation type.
///
/// Experimental: may change without notice.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum CspViolationType {
    /// `trustedtype-sink-violation`
    #[serde(rename = "trustedtype-sink-violation")]
    TrustedtypeSinkViolation,
    /// `trustedtype-policy-violation`
    #[serde(rename = "trustedtype-policy-violation")]
    TrustedtypePolicyViolation,
    /// A value this vendored schema does not list. Chrome adds values ahead of
    /// the published protocol, so an unrecognised one is kept as it arrived
    /// rather than failing the payload it came in.
    #[serde(untagged)]
    Unrecognized(String),
}

/// Object event listener.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct EventListener {
    /// `EventListener`'s type.
    pub r#type: String,
    /// `EventListener`'s useCapture.
    #[serde(rename = "useCapture")]
    pub use_capture: bool,
    /// `EventListener`'s passive flag.
    pub passive: bool,
    /// `EventListener`'s once flag.
    pub once: bool,
    /// Script id of the handler code.
    #[serde(rename = "scriptId")]
    pub script_id: crate::protocol::runtime::ScriptId,
    /// Line number in the script (0-based).
    #[serde(rename = "lineNumber")]
    pub line_number: i64,
    /// Column number in the script (0-based).
    #[serde(rename = "columnNumber")]
    pub column_number: i64,
    /// Event handler function value.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub handler: Option<crate::protocol::runtime::RemoteObject>,
    /// Event original handler function value.
    #[serde(
        rename = "originalHandler",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub original_handler: Option<crate::protocol::runtime::RemoteObject>,
    /// Node the listener is added to (if any).
    #[serde(
        rename = "backendNodeId",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub backend_node_id: Option<crate::protocol::dom::BackendNodeId>,
}

/// Returns event listeners of the given object.
///
/// Parameters of `DOMDebugger.getEventListeners`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct GetEventListenersParams {
    /// Identifier of the object to return listeners for.
    #[serde(rename = "objectId")]
    pub object_id: crate::protocol::runtime::RemoteObjectId,
    /// 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.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub depth: Option<i64>,
    /// 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.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub pierce: Option<bool>,
}

/// What `DOMDebugger.getEventListeners` answers with.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct GetEventListenersReturns {
    /// Array of relevant listeners.
    pub listeners: Vec<EventListener>,
}

impl crate::typed::Command for GetEventListenersParams {
    const METHOD: &'static str = "DOMDebugger.getEventListeners";
    type Returns = GetEventListenersReturns;
}

/// Removes DOM breakpoint that was set using `setDOMBreakpoint`.
///
/// Parameters of `DOMDebugger.removeDOMBreakpoint`.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct RemoveDomBreakpointParams {
    /// Identifier of the node to remove breakpoint from.
    #[serde(rename = "nodeId")]
    pub node_id: crate::protocol::dom::NodeId,
    /// Type of the breakpoint to remove.
    pub r#type: DomBreakpointType,
}

impl crate::typed::Command for RemoveDomBreakpointParams {
    const METHOD: &'static str = "DOMDebugger.removeDOMBreakpoint";
    type Returns = crate::typed::NoReturns;
}

/// Removes breakpoint on particular DOM event.
///
/// Parameters of `DOMDebugger.removeEventListenerBreakpoint`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct RemoveEventListenerBreakpointParams {
    /// Event name.
    #[serde(rename = "eventName")]
    pub event_name: String,
    /// EventTarget interface name.
    ///
    /// Experimental: may change without notice.
    #[serde(
        rename = "targetName",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub target_name: Option<String>,
}

impl crate::typed::Command for RemoveEventListenerBreakpointParams {
    const METHOD: &'static str = "DOMDebugger.removeEventListenerBreakpoint";
    type Returns = crate::typed::NoReturns;
}

/// Removes breakpoint on particular native event.
///
/// Deprecated in the protocol.
///
/// Experimental: may change without notice.
///
/// Parameters of `DOMDebugger.removeInstrumentationBreakpoint`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct RemoveInstrumentationBreakpointParams {
    /// Instrumentation name to stop on.
    #[serde(rename = "eventName")]
    pub event_name: String,
}

impl crate::typed::Command for RemoveInstrumentationBreakpointParams {
    const METHOD: &'static str = "DOMDebugger.removeInstrumentationBreakpoint";
    type Returns = crate::typed::NoReturns;
}

/// Removes breakpoint from XMLHttpRequest.
///
/// Parameters of `DOMDebugger.removeXHRBreakpoint`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct RemoveXhrBreakpointParams {
    /// Resource URL substring.
    pub url: String,
}

impl crate::typed::Command for RemoveXhrBreakpointParams {
    const METHOD: &'static str = "DOMDebugger.removeXHRBreakpoint";
    type Returns = crate::typed::NoReturns;
}

/// Sets breakpoint on particular CSP violations.
///
/// Experimental: may change without notice.
///
/// Parameters of `DOMDebugger.setBreakOnCSPViolation`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct SetBreakOnCspViolationParams {
    /// CSP Violations to stop upon.
    #[serde(rename = "violationTypes")]
    pub violation_types: Vec<CspViolationType>,
}

impl crate::typed::Command for SetBreakOnCspViolationParams {
    const METHOD: &'static str = "DOMDebugger.setBreakOnCSPViolation";
    type Returns = crate::typed::NoReturns;
}

/// Sets breakpoint on particular operation with DOM.
///
/// Parameters of `DOMDebugger.setDOMBreakpoint`.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct SetDomBreakpointParams {
    /// Identifier of the node to set breakpoint on.
    #[serde(rename = "nodeId")]
    pub node_id: crate::protocol::dom::NodeId,
    /// Type of the operation to stop upon.
    pub r#type: DomBreakpointType,
}

impl crate::typed::Command for SetDomBreakpointParams {
    const METHOD: &'static str = "DOMDebugger.setDOMBreakpoint";
    type Returns = crate::typed::NoReturns;
}

/// Sets breakpoint on particular DOM event.
///
/// Parameters of `DOMDebugger.setEventListenerBreakpoint`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct SetEventListenerBreakpointParams {
    /// DOM Event name to stop on (any DOM event will do).
    #[serde(rename = "eventName")]
    pub event_name: String,
    /// EventTarget interface name to stop on. If equal to `"*"` or not provided,
    /// will stop on any EventTarget.
    ///
    /// Experimental: may change without notice.
    #[serde(
        rename = "targetName",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub target_name: Option<String>,
}

impl crate::typed::Command for SetEventListenerBreakpointParams {
    const METHOD: &'static str = "DOMDebugger.setEventListenerBreakpoint";
    type Returns = crate::typed::NoReturns;
}

/// Sets breakpoint on particular native event.
///
/// Deprecated in the protocol.
///
/// Experimental: may change without notice.
///
/// Parameters of `DOMDebugger.setInstrumentationBreakpoint`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct SetInstrumentationBreakpointParams {
    /// Instrumentation name to stop on.
    #[serde(rename = "eventName")]
    pub event_name: String,
}

impl crate::typed::Command for SetInstrumentationBreakpointParams {
    const METHOD: &'static str = "DOMDebugger.setInstrumentationBreakpoint";
    type Returns = crate::typed::NoReturns;
}

/// Sets breakpoint on XMLHttpRequest.
///
/// Parameters of `DOMDebugger.setXHRBreakpoint`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct SetXhrBreakpointParams {
    /// Resource URL substring. All XHRs having this substring in the URL will get
    /// stopped upon.
    pub url: String,
}

impl crate::typed::Command for SetXhrBreakpointParams {
    const METHOD: &'static str = "DOMDebugger.setXHRBreakpoint";
    type Returns = crate::typed::NoReturns;
}