Skip to main content

cdp_driver/protocol/
performance_timeline.rs

1// @generated by `just generate-methods` from protocol/*.json.
2// Do not edit by hand; edit xtask/ and regenerate.
3
4//! Reporting of performance timeline events, as specified in
5//! <https://w3c.github.io/performance-timeline/#dom-performanceobserver>.
6//!
7//! Types, command parameters and event payloads for the `PerformanceTimeline`
8//! domain. The method-name constants for the same domain are in
9//! [`crate::methods`].
10//!
11//! This domain is experimental and may change without notice.
12
13use serde::{Deserialize, Serialize};
14
15/// See <https://github.com/WICG/LargestContentfulPaint> and
16/// largest_contentful_paint.idl
17#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
18pub struct LargestContentfulPaint {
19    #[serde(rename = "renderTime")]
20    pub render_time: crate::protocol::network::TimeSinceEpoch,
21    #[serde(rename = "loadTime")]
22    pub load_time: crate::protocol::network::TimeSinceEpoch,
23    /// The number of pixels being painted.
24    pub size: f64,
25    /// The id attribute of the element, if available.
26    #[serde(rename = "elementId", default, skip_serializing_if = "Option::is_none")]
27    pub element_id: Option<String>,
28    /// The URL of the image (may be trimmed).
29    #[serde(default, skip_serializing_if = "Option::is_none")]
30    pub url: Option<String>,
31    #[serde(rename = "nodeId", default, skip_serializing_if = "Option::is_none")]
32    pub node_id: Option<crate::protocol::dom::BackendNodeId>,
33}
34
35#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
36pub struct LayoutShiftAttribution {
37    #[serde(rename = "previousRect")]
38    pub previous_rect: crate::protocol::dom::Rect,
39    #[serde(rename = "currentRect")]
40    pub current_rect: crate::protocol::dom::Rect,
41    #[serde(rename = "nodeId", default, skip_serializing_if = "Option::is_none")]
42    pub node_id: Option<crate::protocol::dom::BackendNodeId>,
43}
44
45/// See <https://wicg.github.io/layout-instability/#sec-layout-shift> and
46/// layout_shift.idl
47#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
48pub struct LayoutShift {
49    /// Score increment produced by this event.
50    pub value: f64,
51    #[serde(rename = "hadRecentInput")]
52    pub had_recent_input: bool,
53    #[serde(rename = "lastInputTime")]
54    pub last_input_time: crate::protocol::network::TimeSinceEpoch,
55    pub sources: Vec<LayoutShiftAttribution>,
56}
57
58#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
59pub struct TimelineEvent {
60    /// Identifies the frame that this event is related to. Empty for non-frame
61    /// targets.
62    #[serde(rename = "frameId")]
63    pub frame_id: crate::protocol::page::FrameId,
64    /// The event type, as specified in
65    /// <https://w3c.github.io/performance-timeline/#dom-performanceentry-entrytype>
66    /// This determines which of the optional "details" fields is present.
67    pub r#type: String,
68    /// Name may be empty depending on the type.
69    pub name: String,
70    /// Time in seconds since Epoch, monotonically increasing within document
71    /// lifetime.
72    pub time: crate::protocol::network::TimeSinceEpoch,
73    /// Event duration, if applicable.
74    #[serde(default, skip_serializing_if = "Option::is_none")]
75    pub duration: Option<f64>,
76    #[serde(
77        rename = "lcpDetails",
78        default,
79        skip_serializing_if = "Option::is_none"
80    )]
81    pub lcp_details: Option<LargestContentfulPaint>,
82    #[serde(
83        rename = "layoutShiftDetails",
84        default,
85        skip_serializing_if = "Option::is_none"
86    )]
87    pub layout_shift_details: Option<LayoutShift>,
88}
89
90/// Previously buffered events would be reported before method returns. See
91/// also: timelineEventAdded
92///
93/// Parameters of `PerformanceTimeline.enable`.
94#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
95pub struct EnableParams {
96    /// The types of event to report, as specified in
97    /// <https://w3c.github.io/performance-timeline/#dom-performanceentry-entrytype>
98    /// The specified filter overrides any previous filters, passing empty filter
99    /// disables recording. Note that not all types exposed to the web platform
100    /// are currently supported.
101    #[serde(rename = "eventTypes")]
102    pub event_types: Vec<String>,
103}
104
105impl crate::typed::Command for EnableParams {
106    const METHOD: &'static str = "PerformanceTimeline.enable";
107    type Returns = crate::typed::NoReturns;
108}
109
110/// Sent when a performance timeline event is added. See
111/// reportPerformanceTimeline method.
112///
113/// Payload of the `PerformanceTimeline.timelineEventAdded` event.
114#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
115pub struct TimelineEventAddedEvent {
116    pub event: TimelineEvent,
117}
118
119impl crate::typed::Event for TimelineEventAddedEvent {
120    const METHOD: &'static str = "PerformanceTimeline.timelineEventAdded";
121}