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.

//! Reporting of performance timeline events, as specified in
//! <https://w3c.github.io/performance-timeline/#dom-performanceobserver>.
//!
//! Types, command parameters and event payloads for the `PerformanceTimeline`
//! 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};

/// See <https://github.com/WICG/LargestContentfulPaint> and
/// largest_contentful_paint.idl
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct LargestContentfulPaint {
    #[serde(rename = "renderTime")]
    pub render_time: crate::protocol::network::TimeSinceEpoch,
    #[serde(rename = "loadTime")]
    pub load_time: crate::protocol::network::TimeSinceEpoch,
    /// The number of pixels being painted.
    pub size: f64,
    /// The id attribute of the element, if available.
    #[serde(rename = "elementId", default, skip_serializing_if = "Option::is_none")]
    pub element_id: Option<String>,
    /// The URL of the image (may be trimmed).
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub url: Option<String>,
    #[serde(rename = "nodeId", default, skip_serializing_if = "Option::is_none")]
    pub node_id: Option<crate::protocol::dom::BackendNodeId>,
}

#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct LayoutShiftAttribution {
    #[serde(rename = "previousRect")]
    pub previous_rect: crate::protocol::dom::Rect,
    #[serde(rename = "currentRect")]
    pub current_rect: crate::protocol::dom::Rect,
    #[serde(rename = "nodeId", default, skip_serializing_if = "Option::is_none")]
    pub node_id: Option<crate::protocol::dom::BackendNodeId>,
}

/// See <https://wicg.github.io/layout-instability/#sec-layout-shift> and
/// layout_shift.idl
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct LayoutShift {
    /// Score increment produced by this event.
    pub value: f64,
    #[serde(rename = "hadRecentInput")]
    pub had_recent_input: bool,
    #[serde(rename = "lastInputTime")]
    pub last_input_time: crate::protocol::network::TimeSinceEpoch,
    pub sources: Vec<LayoutShiftAttribution>,
}

#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct TimelineEvent {
    /// Identifies the frame that this event is related to. Empty for non-frame
    /// targets.
    #[serde(rename = "frameId")]
    pub frame_id: crate::protocol::page::FrameId,
    /// The event type, as specified in
    /// <https://w3c.github.io/performance-timeline/#dom-performanceentry-entrytype>
    /// This determines which of the optional "details" fields is present.
    pub r#type: String,
    /// Name may be empty depending on the type.
    pub name: String,
    /// Time in seconds since Epoch, monotonically increasing within document
    /// lifetime.
    pub time: crate::protocol::network::TimeSinceEpoch,
    /// Event duration, if applicable.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub duration: Option<f64>,
    #[serde(
        rename = "lcpDetails",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub lcp_details: Option<LargestContentfulPaint>,
    #[serde(
        rename = "layoutShiftDetails",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub layout_shift_details: Option<LayoutShift>,
}

/// Previously buffered events would be reported before method returns. See
/// also: timelineEventAdded
///
/// Parameters of `PerformanceTimeline.enable`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct EnableParams {
    /// The types of event to report, as specified in
    /// <https://w3c.github.io/performance-timeline/#dom-performanceentry-entrytype>
    /// The specified filter overrides any previous filters, passing empty filter
    /// disables recording. Note that not all types exposed to the web platform
    /// are currently supported.
    #[serde(rename = "eventTypes")]
    pub event_types: Vec<String>,
}

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

/// Sent when a performance timeline event is added. See
/// reportPerformanceTimeline method.
///
/// Payload of the `PerformanceTimeline.timelineEventAdded` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct TimelineEventAddedEvent {
    pub event: TimelineEvent,
}

impl crate::typed::Event for TimelineEventAddedEvent {
    const METHOD: &'static str = "PerformanceTimeline.timelineEventAdded";
}