browser_protocol/headlessexperimental/
mod.rs1use serde::{Serialize, Deserialize};
5use serde_json::Value as JsonValue;
6use std::borrow::Cow;
7
8#[derive(Debug, Clone, Serialize, Deserialize, Default)]
11#[serde(rename_all = "camelCase")]
12pub struct ScreenshotParams<'a> {
13 #[serde(skip_serializing_if = "Option::is_none")]
15 format: Option<Cow<'a, str>>,
16 #[serde(skip_serializing_if = "Option::is_none")]
18 quality: Option<i64>,
19 #[serde(skip_serializing_if = "Option::is_none", rename = "optimizeForSpeed")]
21 optimize_for_speed: Option<bool>,
22}
23
24impl<'a> ScreenshotParams<'a> {
25 pub fn builder() -> ScreenshotParamsBuilder<'a> {
27 ScreenshotParamsBuilder {
28 format: None,
29 quality: None,
30 optimize_for_speed: None,
31 }
32 }
33 pub fn format(&self) -> Option<&str> { self.format.as_deref() }
35 pub fn quality(&self) -> Option<i64> { self.quality }
37 pub fn optimize_for_speed(&self) -> Option<bool> { self.optimize_for_speed }
39}
40
41#[derive(Default)]
42pub struct ScreenshotParamsBuilder<'a> {
43 format: Option<Cow<'a, str>>,
44 quality: Option<i64>,
45 optimize_for_speed: Option<bool>,
46}
47
48impl<'a> ScreenshotParamsBuilder<'a> {
49 pub fn format(mut self, format: impl Into<Cow<'a, str>>) -> Self { self.format = Some(format.into()); self }
51 pub fn quality(mut self, quality: i64) -> Self { self.quality = Some(quality); self }
53 pub fn optimize_for_speed(mut self, optimize_for_speed: bool) -> Self { self.optimize_for_speed = Some(optimize_for_speed); self }
55 pub fn build(self) -> ScreenshotParams<'a> {
56 ScreenshotParams {
57 format: self.format,
58 quality: self.quality,
59 optimize_for_speed: self.optimize_for_speed,
60 }
61 }
62}
63
64#[derive(Debug, Clone, Serialize, Deserialize, Default)]
70#[serde(rename_all = "camelCase")]
71pub struct BeginFrameParams<'a> {
72 #[serde(skip_serializing_if = "Option::is_none", rename = "frameTimeTicks")]
75 frame_time_ticks: Option<f64>,
76 #[serde(skip_serializing_if = "Option::is_none")]
79 interval: Option<f64>,
80 #[serde(skip_serializing_if = "Option::is_none", rename = "noDisplayUpdates")]
84 no_display_updates: Option<bool>,
85 #[serde(skip_serializing_if = "Option::is_none")]
89 screenshot: Option<ScreenshotParams<'a>>,
90}
91
92impl<'a> BeginFrameParams<'a> {
93 pub fn builder() -> BeginFrameParamsBuilder<'a> {
95 BeginFrameParamsBuilder {
96 frame_time_ticks: None,
97 interval: None,
98 no_display_updates: None,
99 screenshot: None,
100 }
101 }
102 pub fn frame_time_ticks(&self) -> Option<f64> { self.frame_time_ticks }
105 pub fn interval(&self) -> Option<f64> { self.interval }
108 pub fn no_display_updates(&self) -> Option<bool> { self.no_display_updates }
112 pub fn screenshot(&self) -> Option<&ScreenshotParams<'a>> { self.screenshot.as_ref() }
116}
117
118#[derive(Default)]
119pub struct BeginFrameParamsBuilder<'a> {
120 frame_time_ticks: Option<f64>,
121 interval: Option<f64>,
122 no_display_updates: Option<bool>,
123 screenshot: Option<ScreenshotParams<'a>>,
124}
125
126impl<'a> BeginFrameParamsBuilder<'a> {
127 pub fn frame_time_ticks(mut self, frame_time_ticks: f64) -> Self { self.frame_time_ticks = Some(frame_time_ticks); self }
130 pub fn interval(mut self, interval: f64) -> Self { self.interval = Some(interval); self }
133 pub fn no_display_updates(mut self, no_display_updates: bool) -> Self { self.no_display_updates = Some(no_display_updates); self }
137 pub fn screenshot(mut self, screenshot: ScreenshotParams<'a>) -> Self { self.screenshot = Some(screenshot); self }
141 pub fn build(self) -> BeginFrameParams<'a> {
142 BeginFrameParams {
143 frame_time_ticks: self.frame_time_ticks,
144 interval: self.interval,
145 no_display_updates: self.no_display_updates,
146 screenshot: self.screenshot,
147 }
148 }
149}
150
151#[derive(Debug, Clone, Serialize, Deserialize, Default)]
157#[serde(rename_all = "camelCase")]
158pub struct BeginFrameReturns<'a> {
159 #[serde(rename = "hasDamage")]
162 has_damage: bool,
163 #[serde(skip_serializing_if = "Option::is_none", rename = "screenshotData")]
165 screenshot_data: Option<Cow<'a, str>>,
166}
167
168impl<'a> BeginFrameReturns<'a> {
169 pub fn builder(has_damage: bool) -> BeginFrameReturnsBuilder<'a> {
172 BeginFrameReturnsBuilder {
173 has_damage: has_damage,
174 screenshot_data: None,
175 }
176 }
177 pub fn has_damage(&self) -> bool { self.has_damage }
180 pub fn screenshot_data(&self) -> Option<&str> { self.screenshot_data.as_deref() }
182}
183
184
185pub struct BeginFrameReturnsBuilder<'a> {
186 has_damage: bool,
187 screenshot_data: Option<Cow<'a, str>>,
188}
189
190impl<'a> BeginFrameReturnsBuilder<'a> {
191 pub fn screenshot_data(mut self, screenshot_data: impl Into<Cow<'a, str>>) -> Self { self.screenshot_data = Some(screenshot_data.into()); self }
193 pub fn build(self) -> BeginFrameReturns<'a> {
194 BeginFrameReturns {
195 has_damage: self.has_damage,
196 screenshot_data: self.screenshot_data,
197 }
198 }
199}
200
201impl<'a> BeginFrameParams<'a> { pub const METHOD: &'static str = "HeadlessExperimental.beginFrame"; }
202
203impl<'a> crate::CdpCommand<'a> for BeginFrameParams<'a> {
204 const METHOD: &'static str = "HeadlessExperimental.beginFrame";
205 type Response = BeginFrameReturns<'a>;
206}
207
208#[derive(Debug, Clone, Serialize, Deserialize, Default)]
209pub struct DisableParams {}
210
211impl DisableParams { pub const METHOD: &'static str = "HeadlessExperimental.disable"; }
212
213impl<'a> crate::CdpCommand<'a> for DisableParams {
214 const METHOD: &'static str = "HeadlessExperimental.disable";
215 type Response = crate::EmptyReturns;
216}
217
218#[derive(Debug, Clone, Serialize, Deserialize, Default)]
219pub struct EnableParams {}
220
221impl EnableParams { pub const METHOD: &'static str = "HeadlessExperimental.enable"; }
222
223impl<'a> crate::CdpCommand<'a> for EnableParams {
224 const METHOD: &'static str = "HeadlessExperimental.enable";
225 type Response = crate::EmptyReturns;
226}