use serde::{Serialize, Deserialize};
use serde_json::Value as JsonValue;
use std::borrow::Cow;
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct LargestContentfulPaint<'a> {
#[serde(rename = "renderTime")]
render_time: crate::network::TimeSinceEpoch,
#[serde(rename = "loadTime")]
load_time: crate::network::TimeSinceEpoch,
size: f64,
#[serde(skip_serializing_if = "Option::is_none", rename = "elementId")]
element_id: Option<Cow<'a, str>>,
#[serde(skip_serializing_if = "Option::is_none")]
url: Option<Cow<'a, str>>,
#[serde(skip_serializing_if = "Option::is_none", rename = "nodeId")]
node_id: Option<crate::dom::BackendNodeId>,
}
impl<'a> LargestContentfulPaint<'a> {
pub fn builder(render_time: crate::network::TimeSinceEpoch, load_time: crate::network::TimeSinceEpoch, size: f64) -> LargestContentfulPaintBuilder<'a> {
LargestContentfulPaintBuilder {
render_time: render_time,
load_time: load_time,
size: size,
element_id: None,
url: None,
node_id: None,
}
}
pub fn render_time(&self) -> &crate::network::TimeSinceEpoch { &self.render_time }
pub fn load_time(&self) -> &crate::network::TimeSinceEpoch { &self.load_time }
pub fn size(&self) -> f64 { self.size }
pub fn element_id(&self) -> Option<&str> { self.element_id.as_deref() }
pub fn url(&self) -> Option<&str> { self.url.as_deref() }
pub fn node_id(&self) -> Option<&crate::dom::BackendNodeId> { self.node_id.as_ref() }
}
pub struct LargestContentfulPaintBuilder<'a> {
render_time: crate::network::TimeSinceEpoch,
load_time: crate::network::TimeSinceEpoch,
size: f64,
element_id: Option<Cow<'a, str>>,
url: Option<Cow<'a, str>>,
node_id: Option<crate::dom::BackendNodeId>,
}
impl<'a> LargestContentfulPaintBuilder<'a> {
pub fn element_id(mut self, element_id: impl Into<Cow<'a, str>>) -> Self { self.element_id = Some(element_id.into()); self }
pub fn url(mut self, url: impl Into<Cow<'a, str>>) -> Self { self.url = Some(url.into()); self }
pub fn node_id(mut self, node_id: crate::dom::BackendNodeId) -> Self { self.node_id = Some(node_id); self }
pub fn build(self) -> LargestContentfulPaint<'a> {
LargestContentfulPaint {
render_time: self.render_time,
load_time: self.load_time,
size: self.size,
element_id: self.element_id,
url: self.url,
node_id: self.node_id,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct LayoutShiftAttribution {
#[serde(rename = "previousRect")]
previous_rect: crate::dom::Rect,
#[serde(rename = "currentRect")]
current_rect: crate::dom::Rect,
#[serde(skip_serializing_if = "Option::is_none", rename = "nodeId")]
node_id: Option<crate::dom::BackendNodeId>,
}
impl LayoutShiftAttribution {
pub fn builder(previous_rect: crate::dom::Rect, current_rect: crate::dom::Rect) -> LayoutShiftAttributionBuilder {
LayoutShiftAttributionBuilder {
previous_rect: previous_rect,
current_rect: current_rect,
node_id: None,
}
}
pub fn previous_rect(&self) -> &crate::dom::Rect { &self.previous_rect }
pub fn current_rect(&self) -> &crate::dom::Rect { &self.current_rect }
pub fn node_id(&self) -> Option<&crate::dom::BackendNodeId> { self.node_id.as_ref() }
}
pub struct LayoutShiftAttributionBuilder {
previous_rect: crate::dom::Rect,
current_rect: crate::dom::Rect,
node_id: Option<crate::dom::BackendNodeId>,
}
impl LayoutShiftAttributionBuilder {
pub fn node_id(mut self, node_id: crate::dom::BackendNodeId) -> Self { self.node_id = Some(node_id); self }
pub fn build(self) -> LayoutShiftAttribution {
LayoutShiftAttribution {
previous_rect: self.previous_rect,
current_rect: self.current_rect,
node_id: self.node_id,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct LayoutShift {
value: f64,
#[serde(rename = "hadRecentInput")]
had_recent_input: bool,
#[serde(rename = "lastInputTime")]
last_input_time: crate::network::TimeSinceEpoch,
sources: Vec<LayoutShiftAttribution>,
}
impl LayoutShift {
pub fn builder(value: f64, had_recent_input: bool, last_input_time: crate::network::TimeSinceEpoch, sources: Vec<LayoutShiftAttribution>) -> LayoutShiftBuilder {
LayoutShiftBuilder {
value: value,
had_recent_input: had_recent_input,
last_input_time: last_input_time,
sources: sources,
}
}
pub fn value(&self) -> f64 { self.value }
pub fn had_recent_input(&self) -> bool { self.had_recent_input }
pub fn last_input_time(&self) -> &crate::network::TimeSinceEpoch { &self.last_input_time }
pub fn sources(&self) -> &[LayoutShiftAttribution] { &self.sources }
}
pub struct LayoutShiftBuilder {
value: f64,
had_recent_input: bool,
last_input_time: crate::network::TimeSinceEpoch,
sources: Vec<LayoutShiftAttribution>,
}
impl LayoutShiftBuilder {
pub fn build(self) -> LayoutShift {
LayoutShift {
value: self.value,
had_recent_input: self.had_recent_input,
last_input_time: self.last_input_time,
sources: self.sources,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct TimelineEvent<'a> {
#[serde(rename = "frameId")]
frame_id: crate::page::FrameId<'a>,
#[serde(rename = "type")]
type_: Cow<'a, str>,
name: Cow<'a, str>,
time: crate::network::TimeSinceEpoch,
#[serde(skip_serializing_if = "Option::is_none")]
duration: Option<f64>,
#[serde(skip_serializing_if = "Option::is_none", rename = "lcpDetails")]
lcp_details: Option<LargestContentfulPaint<'a>>,
#[serde(skip_serializing_if = "Option::is_none", rename = "layoutShiftDetails")]
layout_shift_details: Option<LayoutShift>,
}
impl<'a> TimelineEvent<'a> {
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> {
TimelineEventBuilder {
frame_id: frame_id,
type_: type_.into(),
name: name.into(),
time: time,
duration: None,
lcp_details: None,
layout_shift_details: None,
}
}
pub fn frame_id(&self) -> &crate::page::FrameId<'a> { &self.frame_id }
pub fn type_(&self) -> &str { self.type_.as_ref() }
pub fn name(&self) -> &str { self.name.as_ref() }
pub fn time(&self) -> &crate::network::TimeSinceEpoch { &self.time }
pub fn duration(&self) -> Option<f64> { self.duration }
pub fn lcp_details(&self) -> Option<&LargestContentfulPaint<'a>> { self.lcp_details.as_ref() }
pub fn layout_shift_details(&self) -> Option<&LayoutShift> { self.layout_shift_details.as_ref() }
}
pub struct TimelineEventBuilder<'a> {
frame_id: crate::page::FrameId<'a>,
type_: Cow<'a, str>,
name: Cow<'a, str>,
time: crate::network::TimeSinceEpoch,
duration: Option<f64>,
lcp_details: Option<LargestContentfulPaint<'a>>,
layout_shift_details: Option<LayoutShift>,
}
impl<'a> TimelineEventBuilder<'a> {
pub fn duration(mut self, duration: f64) -> Self { self.duration = Some(duration); self }
pub fn lcp_details(mut self, lcp_details: LargestContentfulPaint<'a>) -> Self { self.lcp_details = Some(lcp_details); self }
pub fn layout_shift_details(mut self, layout_shift_details: LayoutShift) -> Self { self.layout_shift_details = Some(layout_shift_details); self }
pub fn build(self) -> TimelineEvent<'a> {
TimelineEvent {
frame_id: self.frame_id,
type_: self.type_,
name: self.name,
time: self.time,
duration: self.duration,
lcp_details: self.lcp_details,
layout_shift_details: self.layout_shift_details,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct EnableParams<'a> {
#[serde(rename = "eventTypes")]
event_types: Vec<Cow<'a, str>>,
}
impl<'a> EnableParams<'a> {
pub fn builder(event_types: Vec<Cow<'a, str>>) -> EnableParamsBuilder<'a> {
EnableParamsBuilder {
event_types: event_types,
}
}
pub fn event_types(&self) -> &[Cow<'a, str>] { &self.event_types }
}
pub struct EnableParamsBuilder<'a> {
event_types: Vec<Cow<'a, str>>,
}
impl<'a> EnableParamsBuilder<'a> {
pub fn build(self) -> EnableParams<'a> {
EnableParams {
event_types: self.event_types,
}
}
}
impl<'a> EnableParams<'a> { pub const METHOD: &'static str = "PerformanceTimeline.enable"; }
impl<'a> crate::CdpCommand<'a> for EnableParams<'a> {
const METHOD: &'static str = "PerformanceTimeline.enable";
type Response = crate::EmptyReturns;
}