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.

//! A domain for ad-related metrics and data.
//!
//! Types, command parameters and event payloads for the `Ads`
//! domain. The method-name constants for the same domain are in
//! [`crate::methods`].
//!
//! This domain is experimental and may change without notice.

use serde::{Deserialize, Serialize};

/// Ad frame data.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct AdFrameData {
    /// The DevTools frame token.
    #[serde(rename = "frameId")]
    pub frame_id: crate::protocol::page::FrameId,
    /// The initial origin of the frame. To minimize the payload size, this is
    /// only sent once per frame.
    #[serde(
        rename = "initialOrigin",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub initial_origin: Option<String>,
    /// The network bytes of the frame.
    #[serde(rename = "networkBytes")]
    pub network_bytes: f64,
    /// The CPU time of the frame, in milliseconds.
    #[serde(rename = "cpuTime")]
    pub cpu_time: f64,
}

/// Ad metrics for a page.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct AdMetrics {
    /// The viewport ad density by area, represented as a percentage (an integer
    /// between 0 and 100).
    #[serde(rename = "viewportAdDensityByArea")]
    pub viewport_ad_density_by_area: i64,
    /// The time-weighted average of the viewport ad density by area, measured
    /// across the duration of the page.
    #[serde(rename = "averageViewportAdDensityByArea")]
    pub average_viewport_ad_density_by_area: f64,
    /// The number of ads currently visible within the viewport.
    #[serde(rename = "viewportAdCount")]
    pub viewport_ad_count: i64,
    /// The time-weighted average of the viewport ad count, measured across the
    /// duration of the page.
    #[serde(rename = "averageViewportAdCount")]
    pub average_viewport_ad_count: f64,
    /// The total ad CPU usage, in milliseconds.
    #[serde(rename = "totalAdCpuTime")]
    pub total_ad_cpu_time: f64,
    /// The total ad network bytes.
    #[serde(rename = "totalAdNetworkBytes")]
    pub total_ad_network_bytes: f64,
    /// The list of ad frames that have been updated since the last event.
    #[serde(rename = "updateAdFrames")]
    pub update_ad_frames: Vec<AdFrameData>,
    /// The list of ad frame IDs that have been removed since the last event.
    #[serde(rename = "removeAdFrames")]
    pub remove_ad_frames: Vec<crate::protocol::page::FrameId>,
}

/// An ad script. Note: when the script is a transitive ad script, we only
/// fill in the immediate ancestor script in the provenance's adScriptAncestry
/// field (as its first entry), rather than filling in the full ancestry. This
/// saves work for the backend, and the frontend can reconstruct the full
/// ancestry if necessary.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct AdScript {
    /// The script ID.
    #[serde(rename = "scriptId")]
    pub script_id: crate::protocol::runtime::ScriptId,
    /// The ad provenance.
    pub provenance: crate::protocol::network::AdProvenance,
}

/// Retrieves ad metrics for the current page.
///
/// Parameters of `Ads.getAdMetrics`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct GetAdMetricsParams {}

/// What `Ads.getAdMetrics` answers with.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct GetAdMetricsReturns {
    pub metrics: AdMetrics,
}

impl crate::typed::Command for GetAdMetricsParams {
    const METHOD: &'static str = "Ads.getAdMetrics";
    type Returns = GetAdMetricsReturns;
}

/// Retrieves ad scripts for the current page. To minimize payload size, this
/// only returns the newly tracked ad scripts since the last call to
/// getAdScripts (i.e., the delta).
///
/// Parameters of `Ads.getAdScripts`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct GetAdScriptsParams {}

/// What `Ads.getAdScripts` answers with.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct GetAdScriptsReturns {
    #[serde(rename = "newScripts")]
    pub new_scripts: Vec<AdScript>,
}

impl crate::typed::Command for GetAdScriptsParams {
    const METHOD: &'static str = "Ads.getAdScripts";
    type Returns = GetAdScriptsReturns;
}