viewpoint_cdp/protocol/emulation/
mod.rs

1//! Emulation domain types.
2//!
3//! The Emulation domain emulates different device metrics and capabilities.
4
5use serde::{Deserialize, Serialize};
6
7/// Screen orientation.
8#[derive(Debug, Clone, Serialize)]
9#[serde(rename_all = "camelCase")]
10pub struct ScreenOrientation {
11    /// Orientation type.
12    #[serde(rename = "type")]
13    pub orientation_type: ScreenOrientationType,
14    /// Orientation angle.
15    pub angle: i32,
16}
17
18/// Screen orientation type.
19#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
20#[serde(rename_all = "camelCase")]
21pub enum ScreenOrientationType {
22    /// Portrait orientation (primary).
23    PortraitPrimary,
24    /// Portrait orientation (secondary).
25    PortraitSecondary,
26    /// Landscape orientation (primary).
27    LandscapePrimary,
28    /// Landscape orientation (secondary).
29    LandscapeSecondary,
30}
31
32/// Display feature.
33#[derive(Debug, Clone, Serialize)]
34#[serde(rename_all = "camelCase")]
35pub struct DisplayFeature {
36    /// Orientation of the display feature.
37    pub orientation: DisplayFeatureOrientation,
38    /// The offset from the screen origin in pixels.
39    pub offset: i32,
40    /// The length of the feature in pixels.
41    pub mask_length: i32,
42}
43
44/// Display feature orientation.
45#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
46#[serde(rename_all = "camelCase")]
47pub enum DisplayFeatureOrientation {
48    /// Vertical orientation.
49    Vertical,
50    /// Horizontal orientation.
51    Horizontal,
52}
53
54/// Device posture.
55#[derive(Debug, Clone, Serialize)]
56#[serde(rename_all = "camelCase")]
57pub struct DevicePosture {
58    /// Current posture type.
59    #[serde(rename = "type")]
60    pub posture_type: DevicePostureType,
61}
62
63/// Device posture type.
64#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
65#[serde(rename_all = "camelCase")]
66pub enum DevicePostureType {
67    /// Continuous posture.
68    Continuous,
69    /// Folded posture.
70    Folded,
71}
72
73/// Parameters for Emulation.setDeviceMetricsOverride.
74#[derive(Debug, Clone, Serialize)]
75#[serde(rename_all = "camelCase")]
76pub struct SetDeviceMetricsOverrideParams {
77    /// Overriding width value in pixels (0 disables override).
78    pub width: i32,
79    /// Overriding height value in pixels (0 disables override).
80    pub height: i32,
81    /// Overriding device scale factor value (0 disables override).
82    pub device_scale_factor: f64,
83    /// Whether to emulate mobile device.
84    pub mobile: bool,
85    /// Scale to apply to resulting view image.
86    #[serde(skip_serializing_if = "Option::is_none")]
87    pub scale: Option<f64>,
88    /// Overriding screen width value in pixels.
89    #[serde(skip_serializing_if = "Option::is_none")]
90    pub screen_width: Option<i32>,
91    /// Overriding screen height value in pixels.
92    #[serde(skip_serializing_if = "Option::is_none")]
93    pub screen_height: Option<i32>,
94    /// Overriding view X position on screen in pixels.
95    #[serde(skip_serializing_if = "Option::is_none")]
96    pub position_x: Option<i32>,
97    /// Overriding view Y position on screen in pixels.
98    #[serde(skip_serializing_if = "Option::is_none")]
99    pub position_y: Option<i32>,
100    /// Do not set visible view size, rely upon explicit setVisibleSize call.
101    #[serde(skip_serializing_if = "Option::is_none")]
102    pub dont_set_visible_size: Option<bool>,
103    /// Screen orientation override.
104    #[serde(skip_serializing_if = "Option::is_none")]
105    pub screen_orientation: Option<ScreenOrientation>,
106    /// The viewport dimensions and scale.
107    #[serde(skip_serializing_if = "Option::is_none")]
108    pub viewport: Option<Viewport>,
109    /// Display feature for foldable devices.
110    #[serde(skip_serializing_if = "Option::is_none")]
111    pub display_feature: Option<DisplayFeature>,
112    /// Device posture for foldable devices.
113    #[serde(skip_serializing_if = "Option::is_none")]
114    pub device_posture: Option<DevicePosture>,
115}
116
117/// Viewport for device metrics override.
118#[derive(Debug, Clone, Serialize)]
119pub struct Viewport {
120    /// X offset in viewport.
121    pub x: f64,
122    /// Y offset in viewport.
123    pub y: f64,
124    /// Viewport width.
125    pub width: f64,
126    /// Viewport height.
127    pub height: f64,
128    /// Viewport scale.
129    pub scale: f64,
130}
131
132/// Parameters for Emulation.clearDeviceMetricsOverride (empty).
133#[derive(Debug, Clone, Serialize, Default)]
134pub struct ClearDeviceMetricsOverrideParams {}
135
136/// Media type for emulation.
137#[derive(Debug, Clone, Serialize)]
138#[serde(rename_all = "lowercase")]
139pub enum MediaType {
140    /// Print media.
141    Print,
142    /// Screen media.
143    Screen,
144}
145
146/// Parameters for Emulation.setEmulatedMedia.
147#[derive(Debug, Clone, Serialize)]
148#[serde(rename_all = "camelCase")]
149pub struct SetEmulatedMediaParams {
150    /// Media type to emulate. Empty string disables the override.
151    #[serde(skip_serializing_if = "Option::is_none")]
152    pub media: Option<String>,
153    /// Media features to emulate.
154    #[serde(skip_serializing_if = "Option::is_none")]
155    pub features: Option<Vec<MediaFeature>>,
156}
157
158/// Media feature for emulation.
159#[derive(Debug, Clone, Serialize)]
160pub struct MediaFeature {
161    /// Feature name.
162    pub name: String,
163    /// Feature value.
164    pub value: String,
165}
166
167/// Viewport size.
168#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
169pub struct ViewportSize {
170    /// Width in pixels.
171    pub width: i32,
172    /// Height in pixels.
173    pub height: i32,
174}
175
176impl ViewportSize {
177    /// Create a new viewport size.
178    pub fn new(width: i32, height: i32) -> Self {
179        Self { width, height }
180    }
181}
182
183/// Parameters for Emulation.setTouchEmulationEnabled.
184#[derive(Debug, Clone, Serialize)]
185#[serde(rename_all = "camelCase")]
186pub struct SetTouchEmulationEnabledParams {
187    /// Whether touch emulation is enabled.
188    pub enabled: bool,
189    /// Maximum touch points. Defaults to 1.
190    #[serde(skip_serializing_if = "Option::is_none")]
191    pub max_touch_points: Option<i32>,
192}
193
194// =============================================================================
195// Geolocation Emulation
196// =============================================================================
197
198/// Parameters for Emulation.setGeolocationOverride.
199#[derive(Debug, Clone, Serialize, Default)]
200#[serde(rename_all = "camelCase")]
201pub struct SetGeolocationOverrideParams {
202    /// Latitude in degrees.
203    #[serde(skip_serializing_if = "Option::is_none")]
204    pub latitude: Option<f64>,
205    /// Longitude in degrees.
206    #[serde(skip_serializing_if = "Option::is_none")]
207    pub longitude: Option<f64>,
208    /// Accuracy in meters.
209    #[serde(skip_serializing_if = "Option::is_none")]
210    pub accuracy: Option<f64>,
211}
212
213impl SetGeolocationOverrideParams {
214    /// Create geolocation override with coordinates.
215    pub fn new(latitude: f64, longitude: f64) -> Self {
216        Self {
217            latitude: Some(latitude),
218            longitude: Some(longitude),
219            accuracy: Some(0.0), // Default to exact accuracy
220        }
221    }
222
223    /// Create geolocation override with coordinates and accuracy.
224    pub fn with_accuracy(latitude: f64, longitude: f64, accuracy: f64) -> Self {
225        Self {
226            latitude: Some(latitude),
227            longitude: Some(longitude),
228            accuracy: Some(accuracy),
229        }
230    }
231
232    /// Create params that indicate position unavailable.
233    pub fn unavailable() -> Self {
234        Self::default()
235    }
236}
237
238/// Parameters for Emulation.clearGeolocationOverride (empty).
239#[derive(Debug, Clone, Serialize, Default)]
240pub struct ClearGeolocationOverrideParams {}
241
242// =============================================================================
243// Timezone Emulation
244// =============================================================================
245
246/// Parameters for Emulation.setTimezoneOverride.
247#[derive(Debug, Clone, Serialize)]
248#[serde(rename_all = "camelCase")]
249pub struct SetTimezoneOverrideParams {
250    /// The timezone identifier. If empty, disables the override.
251    pub timezone_id: String,
252}
253
254impl SetTimezoneOverrideParams {
255    /// Create timezone override.
256    pub fn new(timezone_id: impl Into<String>) -> Self {
257        Self {
258            timezone_id: timezone_id.into(),
259        }
260    }
261}
262
263// =============================================================================
264// Locale Emulation
265// =============================================================================
266
267/// Parameters for Emulation.setLocaleOverride.
268#[derive(Debug, Clone, Serialize)]
269#[serde(rename_all = "camelCase")]
270pub struct SetLocaleOverrideParams {
271    /// ICU locale. Empty string disables the override.
272    #[serde(skip_serializing_if = "Option::is_none")]
273    pub locale: Option<String>,
274}
275
276impl SetLocaleOverrideParams {
277    /// Create locale override.
278    pub fn new(locale: impl Into<String>) -> Self {
279        Self {
280            locale: Some(locale.into()),
281        }
282    }
283
284    /// Clear locale override.
285    pub fn clear() -> Self {
286        Self { locale: None }
287    }
288}
289
290// =============================================================================
291// User Agent Emulation
292// =============================================================================
293
294/// Parameters for Emulation.setUserAgentOverride.
295#[derive(Debug, Clone, Serialize)]
296#[serde(rename_all = "camelCase")]
297pub struct SetUserAgentOverrideParams {
298    /// User agent to use.
299    pub user_agent: String,
300    /// Browser language to emulate.
301    #[serde(skip_serializing_if = "Option::is_none")]
302    pub accept_language: Option<String>,
303    /// The platform navigator.platform should return.
304    #[serde(skip_serializing_if = "Option::is_none")]
305    pub platform: Option<String>,
306    /// User agent client hints.
307    #[serde(skip_serializing_if = "Option::is_none")]
308    pub user_agent_metadata: Option<UserAgentMetadata>,
309}
310
311impl SetUserAgentOverrideParams {
312    /// Create user agent override.
313    pub fn new(user_agent: impl Into<String>) -> Self {
314        Self {
315            user_agent: user_agent.into(),
316            accept_language: None,
317            platform: None,
318            user_agent_metadata: None,
319        }
320    }
321}
322
323/// User agent metadata.
324#[derive(Debug, Clone, Serialize)]
325#[serde(rename_all = "camelCase")]
326pub struct UserAgentMetadata {
327    /// Brands.
328    #[serde(skip_serializing_if = "Option::is_none")]
329    pub brands: Option<Vec<UserAgentBrandVersion>>,
330    /// Full version list.
331    #[serde(skip_serializing_if = "Option::is_none")]
332    pub full_version_list: Option<Vec<UserAgentBrandVersion>>,
333    /// Full version.
334    #[serde(skip_serializing_if = "Option::is_none")]
335    pub full_version: Option<String>,
336    /// Platform.
337    pub platform: String,
338    /// Platform version.
339    pub platform_version: String,
340    /// Architecture.
341    pub architecture: String,
342    /// Model.
343    pub model: String,
344    /// Mobile.
345    pub mobile: bool,
346    /// Bitness.
347    #[serde(skip_serializing_if = "Option::is_none")]
348    pub bitness: Option<String>,
349    /// Whether on a `WoW64` machine.
350    #[serde(skip_serializing_if = "Option::is_none")]
351    pub wow64: Option<bool>,
352}
353
354/// User agent brand version.
355#[derive(Debug, Clone, Serialize)]
356pub struct UserAgentBrandVersion {
357    /// Brand.
358    pub brand: String,
359    /// Version.
360    pub version: String,
361}
362
363// =============================================================================
364// Vision Deficiency Emulation
365// =============================================================================
366
367/// Vision deficiency type for emulation.
368#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
369#[serde(rename_all = "camelCase")]
370#[derive(Default)]
371pub enum VisionDeficiency {
372    /// No vision deficiency emulation.
373    #[default]
374    None,
375    /// Achromatopsia (no color vision).
376    Achromatopsia,
377    /// Blue blindness.
378    BlurredVision,
379    /// Deuteranopia (green-blind).
380    Deuteranopia,
381    /// Protanopia (red-blind).
382    Protanopia,
383    /// Tritanopia (blue-blind).
384    Tritanopia,
385}
386
387
388/// Parameters for Emulation.setEmulatedVisionDeficiency.
389#[derive(Debug, Clone, Serialize)]
390#[serde(rename_all = "camelCase")]
391pub struct SetEmulatedVisionDeficiencyParams {
392    /// Vision deficiency type to emulate.
393    #[serde(rename = "type")]
394    pub deficiency_type: VisionDeficiency,
395}
396
397impl SetEmulatedVisionDeficiencyParams {
398    /// Create vision deficiency emulation params.
399    pub fn new(deficiency_type: VisionDeficiency) -> Self {
400        Self { deficiency_type }
401    }
402
403    /// Clear vision deficiency emulation.
404    pub fn clear() -> Self {
405        Self {
406            deficiency_type: VisionDeficiency::None,
407        }
408    }
409}