Skip to main content

browser_protocol/performancetimeline/
mod.rs

1//! Reporting of performance timeline events, as specified in
2//! https://w3c.github.io/performance-timeline/#dom-performanceobserver.
3use serde::{Serialize, Deserialize};
4use serde_json::Value as JsonValue;
5
6/// See https://github.com/WICG/LargestContentfulPaint and largest_contentful_paint.idl
7
8#[derive(Debug, Clone, Serialize, Deserialize, Default)]
9#[serde(rename_all = "camelCase")]
10pub struct LargestContentfulPaint {
11
12    pub renderTime: crate::network::TimeSinceEpoch,
13
14    pub loadTime: crate::network::TimeSinceEpoch,
15    /// The number of pixels being painted.
16
17    pub size: f64,
18    /// The id attribute of the element, if available.
19
20    #[serde(skip_serializing_if = "Option::is_none")]
21    pub elementId: Option<String>,
22    /// The URL of the image (may be trimmed).
23
24    #[serde(skip_serializing_if = "Option::is_none")]
25    pub url: Option<String>,
26
27    #[serde(skip_serializing_if = "Option::is_none")]
28    pub nodeId: Option<crate::dom::BackendNodeId>,
29}
30
31
32#[derive(Debug, Clone, Serialize, Deserialize, Default)]
33#[serde(rename_all = "camelCase")]
34pub struct LayoutShiftAttribution {
35
36    pub previousRect: crate::dom::Rect,
37
38    pub currentRect: crate::dom::Rect,
39
40    #[serde(skip_serializing_if = "Option::is_none")]
41    pub nodeId: Option<crate::dom::BackendNodeId>,
42}
43
44/// See https://wicg.github.io/layout-instability/#sec-layout-shift and layout_shift.idl
45
46#[derive(Debug, Clone, Serialize, Deserialize, Default)]
47#[serde(rename_all = "camelCase")]
48pub struct LayoutShift {
49    /// Score increment produced by this event.
50
51    pub value: f64,
52
53    pub hadRecentInput: bool,
54
55    pub lastInputTime: crate::network::TimeSinceEpoch,
56
57    pub sources: Vec<LayoutShiftAttribution>,
58}
59
60
61#[derive(Debug, Clone, Serialize, Deserialize, Default)]
62#[serde(rename_all = "camelCase")]
63pub struct TimelineEvent {
64    /// Identifies the frame that this event is related to. Empty for non-frame targets.
65
66    pub frameId: crate::page::FrameId,
67    /// The event type, as specified in https://w3c.github.io/performance-timeline/#dom-performanceentry-entrytype
68    /// This determines which of the optional "details" fields is present.
69
70    #[serde(rename = "type")]
71    pub type_: String,
72    /// Name may be empty depending on the type.
73
74    pub name: String,
75    /// Time in seconds since Epoch, monotonically increasing within document lifetime.
76
77    pub time: crate::network::TimeSinceEpoch,
78    /// Event duration, if applicable.
79
80    #[serde(skip_serializing_if = "Option::is_none")]
81    pub duration: Option<f64>,
82
83    #[serde(skip_serializing_if = "Option::is_none")]
84    pub lcpDetails: Option<LargestContentfulPaint>,
85
86    #[serde(skip_serializing_if = "Option::is_none")]
87    pub layoutShiftDetails: Option<LayoutShift>,
88}
89
90/// Previously buffered events would be reported before method returns.
91/// See also: timelineEventAdded
92
93#[derive(Debug, Clone, Serialize, Deserialize, Default)]
94#[serde(rename_all = "camelCase")]
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
99    /// filter disables recording.
100    /// Note that not all types exposed to the web platform are currently supported.
101
102    pub eventTypes: Vec<String>,
103}
104
105impl EnableParams { pub const METHOD: &'static str = "PerformanceTimeline.enable"; }
106
107impl crate::CdpCommand for EnableParams {
108    const METHOD: &'static str = "PerformanceTimeline.enable";
109    type Response = crate::EmptyReturns;
110}