viewpoint_cdp/protocol/page/
mod.rs

1//! Page domain types.
2//!
3//! The Page domain provides actions and events related to the inspected page.
4
5use serde::{Deserialize, Serialize};
6
7/// Frame information.
8#[derive(Debug, Clone, Deserialize)]
9#[serde(rename_all = "camelCase")]
10pub struct Frame {
11    /// Frame unique identifier.
12    pub id: String,
13    /// Parent frame identifier.
14    pub parent_id: Option<String>,
15    /// Identifier of the loader associated with this frame.
16    pub loader_id: String,
17    /// Frame's name as specified in the tag.
18    pub name: Option<String>,
19    /// Frame document's URL.
20    pub url: String,
21    /// Frame document's security origin.
22    pub security_origin: Option<String>,
23    /// Frame document's mimeType.
24    pub mime_type: Option<String>,
25}
26
27/// Parameters for Page.navigate.
28#[derive(Debug, Clone, Serialize)]
29#[serde(rename_all = "camelCase")]
30pub struct NavigateParams {
31    /// URL to navigate the page to.
32    pub url: String,
33    /// Referrer URL.
34    #[serde(skip_serializing_if = "Option::is_none")]
35    pub referrer: Option<String>,
36    /// Intended transition type.
37    #[serde(skip_serializing_if = "Option::is_none")]
38    pub transition_type: Option<String>,
39    /// Frame id to navigate.
40    #[serde(skip_serializing_if = "Option::is_none")]
41    pub frame_id: Option<String>,
42}
43
44/// Result of Page.navigate.
45#[derive(Debug, Clone, Deserialize)]
46#[serde(rename_all = "camelCase")]
47pub struct NavigateResult {
48    /// Frame id that has navigated (or failed to navigate).
49    pub frame_id: String,
50    /// Loader identifier.
51    pub loader_id: Option<String>,
52    /// User friendly error message if navigation failed.
53    pub error_text: Option<String>,
54}
55
56/// Parameters for Page.reload.
57#[derive(Debug, Clone, Serialize, Default)]
58#[serde(rename_all = "camelCase")]
59pub struct ReloadParams {
60    /// If true, browser cache is ignored.
61    #[serde(skip_serializing_if = "Option::is_none")]
62    pub ignore_cache: Option<bool>,
63    /// Script to inject into all frames.
64    #[serde(skip_serializing_if = "Option::is_none")]
65    pub script_to_evaluate_on_load: Option<String>,
66}
67
68/// Result of Page.getFrameTree.
69#[derive(Debug, Clone, Deserialize)]
70#[serde(rename_all = "camelCase")]
71pub struct GetFrameTreeResult {
72    /// Frame tree structure.
73    pub frame_tree: FrameTree,
74}
75
76/// Frame tree structure.
77#[derive(Debug, Clone, Deserialize)]
78#[serde(rename_all = "camelCase")]
79pub struct FrameTree {
80    /// Frame information.
81    pub frame: Frame,
82    /// Child frames.
83    pub child_frames: Option<Vec<FrameTree>>,
84}
85
86/// Event: Page.loadEventFired
87#[derive(Debug, Clone, Deserialize)]
88pub struct LoadEventFiredEvent {
89    /// Monotonic time.
90    pub timestamp: f64,
91}
92
93/// Event: Page.domContentEventFired
94#[derive(Debug, Clone, Deserialize)]
95pub struct DomContentEventFiredEvent {
96    /// Monotonic time.
97    pub timestamp: f64,
98}
99
100/// Event: Page.frameNavigated
101#[derive(Debug, Clone, Deserialize)]
102#[serde(rename_all = "camelCase")]
103pub struct FrameNavigatedEvent {
104    /// Frame object.
105    pub frame: Frame,
106    /// Navigation type.
107    #[serde(rename = "type")]
108    pub navigation_type: Option<String>,
109}
110
111/// Event: Page.frameStartedLoading
112#[derive(Debug, Clone, Deserialize)]
113#[serde(rename_all = "camelCase")]
114pub struct FrameStartedLoadingEvent {
115    /// Frame ID.
116    pub frame_id: String,
117}
118
119/// Event: Page.frameStoppedLoading
120#[derive(Debug, Clone, Deserialize)]
121#[serde(rename_all = "camelCase")]
122pub struct FrameStoppedLoadingEvent {
123    /// Frame ID.
124    pub frame_id: String,
125}
126
127/// Event: Page.lifecycleEvent
128#[derive(Debug, Clone, Deserialize)]
129#[serde(rename_all = "camelCase")]
130pub struct LifecycleEvent {
131    /// Frame ID.
132    pub frame_id: String,
133    /// Loader identifier.
134    pub loader_id: String,
135    /// Lifecycle event name.
136    pub name: String,
137    /// Timestamp.
138    pub timestamp: f64,
139}
140
141/// Parameters for Page.setLifecycleEventsEnabled.
142#[derive(Debug, Clone, Serialize)]
143pub struct SetLifecycleEventsEnabledParams {
144    /// Whether to enable lifecycle events.
145    pub enabled: bool,
146}
147
148// ============================================================================
149// Screenshot
150// ============================================================================
151
152/// Image format for screenshots.
153#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Default)]
154#[serde(rename_all = "lowercase")]
155pub enum ScreenshotFormat {
156    /// PNG format (default).
157    #[default]
158    Png,
159    /// JPEG format.
160    Jpeg,
161    /// WebP format.
162    Webp,
163}
164
165/// Viewport for capturing a screenshot.
166#[derive(Debug, Clone, Serialize)]
167#[serde(rename_all = "camelCase")]
168pub struct Viewport {
169    /// X offset in device independent pixels.
170    pub x: f64,
171    /// Y offset in device independent pixels.
172    pub y: f64,
173    /// Rectangle width in device independent pixels.
174    pub width: f64,
175    /// Rectangle height in device independent pixels.
176    pub height: f64,
177    /// Page scale factor.
178    pub scale: f64,
179}
180
181/// Parameters for Page.captureScreenshot.
182#[derive(Debug, Clone, Serialize, Default)]
183#[serde(rename_all = "camelCase")]
184pub struct CaptureScreenshotParams {
185    /// Image compression format.
186    #[serde(skip_serializing_if = "Option::is_none")]
187    pub format: Option<ScreenshotFormat>,
188    /// Compression quality from range [0..100] (jpeg/webp only).
189    #[serde(skip_serializing_if = "Option::is_none")]
190    pub quality: Option<u8>,
191    /// Capture the screenshot of a given region only.
192    #[serde(skip_serializing_if = "Option::is_none")]
193    pub clip: Option<Viewport>,
194    /// Capture the screenshot from the surface, rather than the view.
195    #[serde(skip_serializing_if = "Option::is_none")]
196    pub from_surface: Option<bool>,
197    /// Capture the screenshot beyond the viewport.
198    #[serde(skip_serializing_if = "Option::is_none")]
199    pub capture_beyond_viewport: Option<bool>,
200    /// Optimize image encoding for speed, not for resulting size.
201    #[serde(skip_serializing_if = "Option::is_none")]
202    pub optimize_for_speed: Option<bool>,
203}
204
205/// Result of Page.captureScreenshot.
206#[derive(Debug, Clone, Deserialize)]
207pub struct CaptureScreenshotResult {
208    /// Base64-encoded image data.
209    pub data: String,
210}
211
212// ============================================================================
213// PDF
214// ============================================================================
215
216/// Parameters for Page.printToPDF.
217#[derive(Debug, Clone, Serialize, Default)]
218#[serde(rename_all = "camelCase")]
219pub struct PrintToPdfParams {
220    /// Paper orientation (default: false = portrait).
221    #[serde(skip_serializing_if = "Option::is_none")]
222    pub landscape: Option<bool>,
223    /// Display header and footer (default: false).
224    #[serde(skip_serializing_if = "Option::is_none")]
225    pub display_header_footer: Option<bool>,
226    /// Print background graphics (default: false).
227    #[serde(skip_serializing_if = "Option::is_none")]
228    pub print_background: Option<bool>,
229    /// Scale of the webpage rendering (default: 1).
230    #[serde(skip_serializing_if = "Option::is_none")]
231    pub scale: Option<f64>,
232    /// Paper width in inches (default: 8.5).
233    #[serde(skip_serializing_if = "Option::is_none")]
234    pub paper_width: Option<f64>,
235    /// Paper height in inches (default: 11).
236    #[serde(skip_serializing_if = "Option::is_none")]
237    pub paper_height: Option<f64>,
238    /// Top margin in inches (default: 0.4).
239    #[serde(skip_serializing_if = "Option::is_none")]
240    pub margin_top: Option<f64>,
241    /// Bottom margin in inches (default: 0.4).
242    #[serde(skip_serializing_if = "Option::is_none")]
243    pub margin_bottom: Option<f64>,
244    /// Left margin in inches (default: 0.4).
245    #[serde(skip_serializing_if = "Option::is_none")]
246    pub margin_left: Option<f64>,
247    /// Right margin in inches (default: 0.4).
248    #[serde(skip_serializing_if = "Option::is_none")]
249    pub margin_right: Option<f64>,
250    /// Paper ranges to print, e.g., '1-5, 8, 11-13'.
251    #[serde(skip_serializing_if = "Option::is_none")]
252    pub page_ranges: Option<String>,
253    /// HTML template for the print header.
254    #[serde(skip_serializing_if = "Option::is_none")]
255    pub header_template: Option<String>,
256    /// HTML template for the print footer.
257    #[serde(skip_serializing_if = "Option::is_none")]
258    pub footer_template: Option<String>,
259    /// Whether or not to prefer page size as defined by css.
260    #[serde(skip_serializing_if = "Option::is_none")]
261    pub prefer_css_page_size: Option<bool>,
262    /// Return as stream (experimental).
263    #[serde(skip_serializing_if = "Option::is_none")]
264    pub transfer_mode: Option<String>,
265    /// Whether to generate tagged PDF. Default: true.
266    #[serde(skip_serializing_if = "Option::is_none")]
267    pub generate_tagged_pdf: Option<bool>,
268    /// Whether to generate document outline. Default: false.
269    #[serde(skip_serializing_if = "Option::is_none")]
270    pub generate_document_outline: Option<bool>,
271}
272
273/// Result of Page.printToPDF.
274#[derive(Debug, Clone, Deserialize)]
275pub struct PrintToPdfResult {
276    /// Base64-encoded pdf data.
277    pub data: String,
278    /// A handle of the stream that holds resulting PDF data.
279    pub stream: Option<String>,
280}
281
282// ============================================================================
283// Navigation History
284// ============================================================================
285
286/// Result of Page.goBack / Page.goForward.
287#[derive(Debug, Clone, Deserialize)]
288pub struct NavigationHistoryResult {}
289
290/// Result of Page.getNavigationHistory.
291#[derive(Debug, Clone, Deserialize)]
292#[serde(rename_all = "camelCase")]
293pub struct GetNavigationHistoryResult {
294    /// Index of the current navigation history entry.
295    pub current_index: i32,
296    /// Array of navigation history entries.
297    pub entries: Vec<NavigationEntry>,
298}
299
300/// Navigation history entry.
301#[derive(Debug, Clone, Deserialize)]
302#[serde(rename_all = "camelCase")]
303pub struct NavigationEntry {
304    /// Unique id of the navigation history entry.
305    pub id: i32,
306    /// URL of the navigation history entry.
307    pub url: String,
308    /// URL that the user typed in the URL bar.
309    #[serde(default)]
310    pub user_typed_url: String,
311    /// Title of the navigation history entry.
312    pub title: String,
313    /// Transition type.
314    #[serde(default)]
315    pub transition_type: String,
316}
317
318/// Parameters for Page.navigateToHistoryEntry.
319#[derive(Debug, Clone, Serialize)]
320#[serde(rename_all = "camelCase")]
321pub struct NavigateToHistoryEntryParams {
322    /// Unique id of the entry to navigate to.
323    pub entry_id: i32,
324}
325
326// ============================================================================
327// Init Scripts
328// ============================================================================
329
330/// Parameters for Page.addScriptToEvaluateOnNewDocument.
331#[derive(Debug, Clone, Serialize)]
332#[serde(rename_all = "camelCase")]
333pub struct AddScriptToEvaluateOnNewDocumentParams {
334    /// JavaScript source code to evaluate.
335    pub source: String,
336    /// If specified, creates an isolated world and evaluates given script in it.
337    #[serde(skip_serializing_if = "Option::is_none")]
338    pub world_name: Option<String>,
339    /// Whether this script should be injected into all frames.
340    #[serde(skip_serializing_if = "Option::is_none")]
341    pub include_command_line_api: Option<bool>,
342    /// If true, this script will run in utility world.
343    #[serde(skip_serializing_if = "Option::is_none")]
344    pub run_immediately: Option<bool>,
345}
346
347/// Result of Page.addScriptToEvaluateOnNewDocument.
348#[derive(Debug, Clone, Deserialize)]
349pub struct AddScriptToEvaluateOnNewDocumentResult {
350    /// Identifier of the added script.
351    pub identifier: String,
352}
353
354/// Parameters for Page.removeScriptToEvaluateOnNewDocument.
355#[derive(Debug, Clone, Serialize)]
356pub struct RemoveScriptToEvaluateOnNewDocumentParams {
357    /// Identifier of the script to remove.
358    pub identifier: String,
359}
360
361// ============================================================================
362// Page State
363// ============================================================================
364
365/// Parameters for Page.bringToFront (empty).
366#[derive(Debug, Clone, Serialize, Default)]
367pub struct BringToFrontParams {}
368
369/// Parameters for Page.setDocumentContent.
370#[derive(Debug, Clone, Serialize)]
371#[serde(rename_all = "camelCase")]
372pub struct SetDocumentContentParams {
373    /// Frame id to set HTML for.
374    pub frame_id: String,
375    /// HTML content to set.
376    pub html: String,
377}
378
379/// Event: Page.windowOpen
380#[derive(Debug, Clone, Deserialize)]
381#[serde(rename_all = "camelCase")]
382pub struct WindowOpenEvent {
383    /// The URL for the new window.
384    pub url: String,
385    /// Window name.
386    pub window_name: String,
387    /// An array of enabled window features.
388    pub window_features: Vec<String>,
389    /// Whether or not it was triggered by user gesture.
390    pub user_gesture: bool,
391}
392
393// ============================================================================
394// Frame Events
395// ============================================================================
396
397/// Event: Page.frameAttached
398///
399/// Fired when a frame has been attached to its parent.
400#[derive(Debug, Clone, Deserialize)]
401#[serde(rename_all = "camelCase")]
402pub struct FrameAttachedEvent {
403    /// Id of the frame that has been attached.
404    pub frame_id: String,
405    /// Parent frame identifier.
406    pub parent_frame_id: String,
407    /// JavaScript stack trace of when frame was attached, only set if frame initiated from script.
408    pub stack: Option<serde_json::Value>,
409}
410
411/// Event: Page.frameDetached
412///
413/// Fired when a frame has been detached from its parent.
414#[derive(Debug, Clone, Deserialize)]
415#[serde(rename_all = "camelCase")]
416pub struct FrameDetachedEvent {
417    /// Id of the frame that has been detached.
418    pub frame_id: String,
419    /// Reason for the frame being detached.
420    pub reason: Option<FrameDetachedReason>,
421}
422
423/// Reason for frame being detached.
424#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
425#[serde(rename_all = "camelCase")]
426pub enum FrameDetachedReason {
427    /// Frame was removed from the DOM.
428    Remove,
429    /// Frame was swapped (e.g., for out-of-process iframe).
430    Swap,
431}
432
433/// Event: Page.navigatedWithinDocument
434///
435/// Fired when a frame navigation happened within the same document.
436#[derive(Debug, Clone, Deserialize)]
437#[serde(rename_all = "camelCase")]
438pub struct NavigatedWithinDocumentEvent {
439    /// Id of the frame.
440    pub frame_id: String,
441    /// Frame's new url.
442    pub url: String,
443}
444
445// ============================================================================
446// File Chooser Events
447// ============================================================================
448
449/// Event: Page.fileChooserOpened
450///
451/// Emitted only when `page.setInterceptFileChooserDialog` is enabled.
452#[derive(Debug, Clone, Deserialize)]
453#[serde(rename_all = "camelCase")]
454pub struct FileChooserOpenedEvent {
455    /// Id of the frame containing input node.
456    pub frame_id: String,
457    /// Input mode.
458    pub mode: FileChooserMode,
459    /// Input node id. Only present for file choosers opened via an input element
460    /// with webkitdirectory attribute (directory picker).
461    pub backend_node_id: Option<i32>,
462}
463
464/// File chooser mode.
465#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
466#[serde(rename_all = "camelCase")]
467pub enum FileChooserMode {
468    /// Select a single file.
469    SelectSingle,
470    /// Select multiple files.
471    SelectMultiple,
472}
473
474/// Parameters for Page.setInterceptFileChooserDialog.
475#[derive(Debug, Clone, Serialize)]
476pub struct SetInterceptFileChooserDialogParams {
477    /// Whether to intercept file chooser dialogs.
478    pub enabled: bool,
479}
480
481