browser_protocol/performancetimeline/
mod.rs1use serde::{Serialize, Deserialize};
6use serde_json::Value as JsonValue;
7use std::borrow::Cow;
8
9#[derive(Debug, Clone, Serialize, Deserialize, Default)]
12#[serde(rename_all = "camelCase")]
13pub struct LargestContentfulPaint<'a> {
14 #[serde(rename = "renderTime")]
15 render_time: crate::network::TimeSinceEpoch,
16 #[serde(rename = "loadTime")]
17 load_time: crate::network::TimeSinceEpoch,
18 size: f64,
20 #[serde(skip_serializing_if = "Option::is_none", rename = "elementId")]
22 element_id: Option<Cow<'a, str>>,
23 #[serde(skip_serializing_if = "Option::is_none")]
25 url: Option<Cow<'a, str>>,
26 #[serde(skip_serializing_if = "Option::is_none", rename = "nodeId")]
27 node_id: Option<crate::dom::BackendNodeId>,
28}
29
30impl<'a> LargestContentfulPaint<'a> {
31 pub fn builder(render_time: crate::network::TimeSinceEpoch, load_time: crate::network::TimeSinceEpoch, size: f64) -> LargestContentfulPaintBuilder<'a> {
36 LargestContentfulPaintBuilder {
37 render_time: render_time,
38 load_time: load_time,
39 size: size,
40 element_id: None,
41 url: None,
42 node_id: None,
43 }
44 }
45 pub fn render_time(&self) -> &crate::network::TimeSinceEpoch { &self.render_time }
46 pub fn load_time(&self) -> &crate::network::TimeSinceEpoch { &self.load_time }
47 pub fn size(&self) -> f64 { self.size }
49 pub fn element_id(&self) -> Option<&str> { self.element_id.as_deref() }
51 pub fn url(&self) -> Option<&str> { self.url.as_deref() }
53 pub fn node_id(&self) -> Option<&crate::dom::BackendNodeId> { self.node_id.as_ref() }
54}
55
56
57pub struct LargestContentfulPaintBuilder<'a> {
58 render_time: crate::network::TimeSinceEpoch,
59 load_time: crate::network::TimeSinceEpoch,
60 size: f64,
61 element_id: Option<Cow<'a, str>>,
62 url: Option<Cow<'a, str>>,
63 node_id: Option<crate::dom::BackendNodeId>,
64}
65
66impl<'a> LargestContentfulPaintBuilder<'a> {
67 pub fn element_id(mut self, element_id: impl Into<Cow<'a, str>>) -> Self { self.element_id = Some(element_id.into()); self }
69 pub fn url(mut self, url: impl Into<Cow<'a, str>>) -> Self { self.url = Some(url.into()); self }
71 pub fn node_id(mut self, node_id: crate::dom::BackendNodeId) -> Self { self.node_id = Some(node_id); self }
72 pub fn build(self) -> LargestContentfulPaint<'a> {
73 LargestContentfulPaint {
74 render_time: self.render_time,
75 load_time: self.load_time,
76 size: self.size,
77 element_id: self.element_id,
78 url: self.url,
79 node_id: self.node_id,
80 }
81 }
82}
83
84
85#[derive(Debug, Clone, Serialize, Deserialize, Default)]
86#[serde(rename_all = "camelCase")]
87pub struct LayoutShiftAttribution {
88 #[serde(rename = "previousRect")]
89 previous_rect: crate::dom::Rect,
90 #[serde(rename = "currentRect")]
91 current_rect: crate::dom::Rect,
92 #[serde(skip_serializing_if = "Option::is_none", rename = "nodeId")]
93 node_id: Option<crate::dom::BackendNodeId>,
94}
95
96impl LayoutShiftAttribution {
97 pub fn builder(previous_rect: crate::dom::Rect, current_rect: crate::dom::Rect) -> LayoutShiftAttributionBuilder {
101 LayoutShiftAttributionBuilder {
102 previous_rect: previous_rect,
103 current_rect: current_rect,
104 node_id: None,
105 }
106 }
107 pub fn previous_rect(&self) -> &crate::dom::Rect { &self.previous_rect }
108 pub fn current_rect(&self) -> &crate::dom::Rect { &self.current_rect }
109 pub fn node_id(&self) -> Option<&crate::dom::BackendNodeId> { self.node_id.as_ref() }
110}
111
112
113pub struct LayoutShiftAttributionBuilder {
114 previous_rect: crate::dom::Rect,
115 current_rect: crate::dom::Rect,
116 node_id: Option<crate::dom::BackendNodeId>,
117}
118
119impl LayoutShiftAttributionBuilder {
120 pub fn node_id(mut self, node_id: crate::dom::BackendNodeId) -> Self { self.node_id = Some(node_id); self }
121 pub fn build(self) -> LayoutShiftAttribution {
122 LayoutShiftAttribution {
123 previous_rect: self.previous_rect,
124 current_rect: self.current_rect,
125 node_id: self.node_id,
126 }
127 }
128}
129
130#[derive(Debug, Clone, Serialize, Deserialize, Default)]
133#[serde(rename_all = "camelCase")]
134pub struct LayoutShift {
135 value: f64,
137 #[serde(rename = "hadRecentInput")]
138 had_recent_input: bool,
139 #[serde(rename = "lastInputTime")]
140 last_input_time: crate::network::TimeSinceEpoch,
141 sources: Vec<LayoutShiftAttribution>,
142}
143
144impl LayoutShift {
145 pub fn builder(value: f64, had_recent_input: bool, last_input_time: crate::network::TimeSinceEpoch, sources: Vec<LayoutShiftAttribution>) -> LayoutShiftBuilder {
151 LayoutShiftBuilder {
152 value: value,
153 had_recent_input: had_recent_input,
154 last_input_time: last_input_time,
155 sources: sources,
156 }
157 }
158 pub fn value(&self) -> f64 { self.value }
160 pub fn had_recent_input(&self) -> bool { self.had_recent_input }
161 pub fn last_input_time(&self) -> &crate::network::TimeSinceEpoch { &self.last_input_time }
162 pub fn sources(&self) -> &[LayoutShiftAttribution] { &self.sources }
163}
164
165
166pub struct LayoutShiftBuilder {
167 value: f64,
168 had_recent_input: bool,
169 last_input_time: crate::network::TimeSinceEpoch,
170 sources: Vec<LayoutShiftAttribution>,
171}
172
173impl LayoutShiftBuilder {
174 pub fn build(self) -> LayoutShift {
175 LayoutShift {
176 value: self.value,
177 had_recent_input: self.had_recent_input,
178 last_input_time: self.last_input_time,
179 sources: self.sources,
180 }
181 }
182}
183
184
185#[derive(Debug, Clone, Serialize, Deserialize, Default)]
186#[serde(rename_all = "camelCase")]
187pub struct TimelineEvent<'a> {
188 #[serde(rename = "frameId")]
190 frame_id: crate::page::FrameId<'a>,
191 #[serde(rename = "type")]
194 type_: Cow<'a, str>,
195 name: Cow<'a, str>,
197 time: crate::network::TimeSinceEpoch,
199 #[serde(skip_serializing_if = "Option::is_none")]
201 duration: Option<f64>,
202 #[serde(skip_serializing_if = "Option::is_none", rename = "lcpDetails")]
203 lcp_details: Option<LargestContentfulPaint<'a>>,
204 #[serde(skip_serializing_if = "Option::is_none", rename = "layoutShiftDetails")]
205 layout_shift_details: Option<LayoutShift>,
206}
207
208impl<'a> TimelineEvent<'a> {
209 pub fn builder(frame_id: crate::page::FrameId<'a>, type_: impl Into<Cow<'a, str>>, name: impl Into<Cow<'a, str>>, time: crate::network::TimeSinceEpoch) -> TimelineEventBuilder<'a> {
215 TimelineEventBuilder {
216 frame_id: frame_id,
217 type_: type_.into(),
218 name: name.into(),
219 time: time,
220 duration: None,
221 lcp_details: None,
222 layout_shift_details: None,
223 }
224 }
225 pub fn frame_id(&self) -> &crate::page::FrameId<'a> { &self.frame_id }
227 pub fn type_(&self) -> &str { self.type_.as_ref() }
230 pub fn name(&self) -> &str { self.name.as_ref() }
232 pub fn time(&self) -> &crate::network::TimeSinceEpoch { &self.time }
234 pub fn duration(&self) -> Option<f64> { self.duration }
236 pub fn lcp_details(&self) -> Option<&LargestContentfulPaint<'a>> { self.lcp_details.as_ref() }
237 pub fn layout_shift_details(&self) -> Option<&LayoutShift> { self.layout_shift_details.as_ref() }
238}
239
240
241pub struct TimelineEventBuilder<'a> {
242 frame_id: crate::page::FrameId<'a>,
243 type_: Cow<'a, str>,
244 name: Cow<'a, str>,
245 time: crate::network::TimeSinceEpoch,
246 duration: Option<f64>,
247 lcp_details: Option<LargestContentfulPaint<'a>>,
248 layout_shift_details: Option<LayoutShift>,
249}
250
251impl<'a> TimelineEventBuilder<'a> {
252 pub fn duration(mut self, duration: f64) -> Self { self.duration = Some(duration); self }
254 pub fn lcp_details(mut self, lcp_details: LargestContentfulPaint<'a>) -> Self { self.lcp_details = Some(lcp_details); self }
255 pub fn layout_shift_details(mut self, layout_shift_details: LayoutShift) -> Self { self.layout_shift_details = Some(layout_shift_details); self }
256 pub fn build(self) -> TimelineEvent<'a> {
257 TimelineEvent {
258 frame_id: self.frame_id,
259 type_: self.type_,
260 name: self.name,
261 time: self.time,
262 duration: self.duration,
263 lcp_details: self.lcp_details,
264 layout_shift_details: self.layout_shift_details,
265 }
266 }
267}
268
269#[derive(Debug, Clone, Serialize, Deserialize, Default)]
273#[serde(rename_all = "camelCase")]
274pub struct EnableParams<'a> {
275 #[serde(rename = "eventTypes")]
281 event_types: Vec<Cow<'a, str>>,
282}
283
284impl<'a> EnableParams<'a> {
285 pub fn builder(event_types: Vec<Cow<'a, str>>) -> EnableParamsBuilder<'a> {
288 EnableParamsBuilder {
289 event_types: event_types,
290 }
291 }
292 pub fn event_types(&self) -> &[Cow<'a, str>] { &self.event_types }
298}
299
300
301pub struct EnableParamsBuilder<'a> {
302 event_types: Vec<Cow<'a, str>>,
303}
304
305impl<'a> EnableParamsBuilder<'a> {
306 pub fn build(self) -> EnableParams<'a> {
307 EnableParams {
308 event_types: self.event_types,
309 }
310 }
311}
312
313impl<'a> EnableParams<'a> { pub const METHOD: &'static str = "PerformanceTimeline.enable"; }
314
315impl<'a> crate::CdpCommand<'a> for EnableParams<'a> {
316 const METHOD: &'static str = "PerformanceTimeline.enable";
317 type Response = crate::EmptyReturns;
318}