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.

//! The `Performance` domain.
//!
//! Types, command parameters and event payloads for the `Performance`
//! domain. The method-name constants for the same domain are in
//! [`crate::methods`].

use serde::{Deserialize, Serialize};

/// Run-time execution metric.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct Metric {
    /// Metric name.
    pub name: String,
    /// Metric value.
    pub value: f64,
}

/// Disable collecting and reporting metrics.
///
/// Parameters of `Performance.disable`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct DisableParams {}

impl crate::typed::Command for DisableParams {
    const METHOD: &'static str = "Performance.disable";
    type Returns = crate::typed::NoReturns;
}

/// Enable collecting and reporting metrics.
///
/// Parameters of `Performance.enable`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct EnableParams {
    /// Time domain to use for collecting and reporting duration metrics.
    #[serde(
        rename = "timeDomain",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub time_domain: Option<EnableTimeDomain>,
}

/// The values `timeDomain` accepts on `enable`.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum EnableTimeDomain {
    /// `timeTicks`
    #[serde(rename = "timeTicks")]
    TimeTicks,
    /// `threadTicks`
    #[serde(rename = "threadTicks")]
    ThreadTicks,
    /// 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),
}

impl crate::typed::Command for EnableParams {
    const METHOD: &'static str = "Performance.enable";
    type Returns = crate::typed::NoReturns;
}

/// Sets time domain to use for collecting and reporting duration metrics.
/// Note that this must be called before enabling metrics collection. Calling
/// this method while metrics collection is enabled returns an error.
///
/// Deprecated in the protocol.
///
/// Experimental: may change without notice.
///
/// Parameters of `Performance.setTimeDomain`.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct SetTimeDomainParams {
    /// Time domain
    #[serde(rename = "timeDomain")]
    pub time_domain: SetTimeDomainTimeDomain,
}

/// The values `timeDomain` accepts on `setTimeDomain`.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum SetTimeDomainTimeDomain {
    /// `timeTicks`
    #[serde(rename = "timeTicks")]
    TimeTicks,
    /// `threadTicks`
    #[serde(rename = "threadTicks")]
    ThreadTicks,
    /// 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),
}

impl crate::typed::Command for SetTimeDomainParams {
    const METHOD: &'static str = "Performance.setTimeDomain";
    type Returns = crate::typed::NoReturns;
}

/// Retrieve current values of run-time metrics.
///
/// Parameters of `Performance.getMetrics`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct GetMetricsParams {}

/// What `Performance.getMetrics` answers with.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct GetMetricsReturns {
    /// Current values for run-time metrics.
    pub metrics: Vec<Metric>,
}

impl crate::typed::Command for GetMetricsParams {
    const METHOD: &'static str = "Performance.getMetrics";
    type Returns = GetMetricsReturns;
}

/// Current values of the metrics.
///
/// Payload of the `Performance.metrics` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct MetricsEvent {
    /// Current values of the metrics.
    pub metrics: Vec<Metric>,
    /// Timestamp title.
    pub title: String,
}

impl crate::typed::Event for MetricsEvent {
    const METHOD: &'static str = "Performance.metrics";
}