viewpoint-cdp 0.2.10

Low-level Chrome DevTools Protocol implementation over WebSocket
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
//! Page domain types.
//!
//! The Page domain provides actions and events related to the inspected page.

use serde::{Deserialize, Serialize};

/// Frame information.
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Frame {
    /// Frame unique identifier.
    pub id: String,
    /// Parent frame identifier.
    pub parent_id: Option<String>,
    /// Identifier of the loader associated with this frame.
    pub loader_id: String,
    /// Frame's name as specified in the tag.
    pub name: Option<String>,
    /// Frame document's URL.
    pub url: String,
    /// Frame document's security origin.
    pub security_origin: Option<String>,
    /// Frame document's mimeType.
    pub mime_type: Option<String>,
}

/// Parameters for Page.navigate.
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct NavigateParams {
    /// URL to navigate the page to.
    pub url: String,
    /// Referrer URL.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub referrer: Option<String>,
    /// Intended transition type.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub transition_type: Option<String>,
    /// Frame id to navigate.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub frame_id: Option<String>,
}

/// Result of Page.navigate.
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct NavigateResult {
    /// Frame id that has navigated (or failed to navigate).
    pub frame_id: String,
    /// Loader identifier.
    pub loader_id: Option<String>,
    /// User friendly error message if navigation failed.
    pub error_text: Option<String>,
}

/// Parameters for Page.reload.
#[derive(Debug, Clone, Serialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct ReloadParams {
    /// If true, browser cache is ignored.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub ignore_cache: Option<bool>,
    /// Script to inject into all frames.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub script_to_evaluate_on_load: Option<String>,
}

/// Result of Page.getFrameTree.
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct GetFrameTreeResult {
    /// Frame tree structure.
    pub frame_tree: FrameTree,
}

/// Frame tree structure.
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct FrameTree {
    /// Frame information.
    pub frame: Frame,
    /// Child frames.
    pub child_frames: Option<Vec<FrameTree>>,
}

/// Event: Page.loadEventFired
#[derive(Debug, Clone, Deserialize)]
pub struct LoadEventFiredEvent {
    /// Monotonic time.
    pub timestamp: f64,
}

/// Event: Page.domContentEventFired
#[derive(Debug, Clone, Deserialize)]
pub struct DomContentEventFiredEvent {
    /// Monotonic time.
    pub timestamp: f64,
}

/// Event: Page.frameNavigated
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct FrameNavigatedEvent {
    /// Frame object.
    pub frame: Frame,
    /// Navigation type.
    #[serde(rename = "type")]
    pub navigation_type: Option<String>,
}

/// Event: Page.frameStartedLoading
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct FrameStartedLoadingEvent {
    /// Frame ID.
    pub frame_id: String,
}

/// Event: Page.frameStoppedLoading
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct FrameStoppedLoadingEvent {
    /// Frame ID.
    pub frame_id: String,
}

/// Event: Page.lifecycleEvent
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct LifecycleEvent {
    /// Frame ID.
    pub frame_id: String,
    /// Loader identifier.
    pub loader_id: String,
    /// Lifecycle event name.
    pub name: String,
    /// Timestamp.
    pub timestamp: f64,
}

/// Parameters for Page.setLifecycleEventsEnabled.
#[derive(Debug, Clone, Serialize)]
pub struct SetLifecycleEventsEnabledParams {
    /// Whether to enable lifecycle events.
    pub enabled: bool,
}

// ============================================================================
// Screenshot
// ============================================================================

/// Image format for screenshots.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Default)]
#[serde(rename_all = "lowercase")]
pub enum ScreenshotFormat {
    /// PNG format (default).
    #[default]
    Png,
    /// JPEG format.
    Jpeg,
    /// WebP format.
    Webp,
}

/// Viewport for capturing a screenshot.
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Viewport {
    /// X offset in device independent pixels.
    pub x: f64,
    /// Y offset in device independent pixels.
    pub y: f64,
    /// Rectangle width in device independent pixels.
    pub width: f64,
    /// Rectangle height in device independent pixels.
    pub height: f64,
    /// Page scale factor.
    pub scale: f64,
}

/// Parameters for Page.captureScreenshot.
#[derive(Debug, Clone, Serialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct CaptureScreenshotParams {
    /// Image compression format.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub format: Option<ScreenshotFormat>,
    /// Compression quality from range [0..100] (jpeg/webp only).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub quality: Option<u8>,
    /// Capture the screenshot of a given region only.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub clip: Option<Viewport>,
    /// Capture the screenshot from the surface, rather than the view.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub from_surface: Option<bool>,
    /// Capture the screenshot beyond the viewport.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub capture_beyond_viewport: Option<bool>,
    /// Optimize image encoding for speed, not for resulting size.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub optimize_for_speed: Option<bool>,
}

/// Result of Page.captureScreenshot.
#[derive(Debug, Clone, Deserialize)]
pub struct CaptureScreenshotResult {
    /// Base64-encoded image data.
    pub data: String,
}

// ============================================================================
// PDF
// ============================================================================

/// Parameters for Page.printToPDF.
#[derive(Debug, Clone, Serialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct PrintToPdfParams {
    /// Paper orientation (default: false = portrait).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub landscape: Option<bool>,
    /// Display header and footer (default: false).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub display_header_footer: Option<bool>,
    /// Print background graphics (default: false).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub print_background: Option<bool>,
    /// Scale of the webpage rendering (default: 1).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub scale: Option<f64>,
    /// Paper width in inches (default: 8.5).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub paper_width: Option<f64>,
    /// Paper height in inches (default: 11).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub paper_height: Option<f64>,
    /// Top margin in inches (default: 0.4).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub margin_top: Option<f64>,
    /// Bottom margin in inches (default: 0.4).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub margin_bottom: Option<f64>,
    /// Left margin in inches (default: 0.4).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub margin_left: Option<f64>,
    /// Right margin in inches (default: 0.4).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub margin_right: Option<f64>,
    /// Paper ranges to print, e.g., '1-5, 8, 11-13'.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub page_ranges: Option<String>,
    /// HTML template for the print header.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub header_template: Option<String>,
    /// HTML template for the print footer.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub footer_template: Option<String>,
    /// Whether or not to prefer page size as defined by css.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub prefer_css_page_size: Option<bool>,
    /// Return as stream (experimental).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub transfer_mode: Option<String>,
    /// Whether to generate tagged PDF. Default: true.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub generate_tagged_pdf: Option<bool>,
    /// Whether to generate document outline. Default: false.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub generate_document_outline: Option<bool>,
}

/// Result of Page.printToPDF.
#[derive(Debug, Clone, Deserialize)]
pub struct PrintToPdfResult {
    /// Base64-encoded pdf data.
    pub data: String,
    /// A handle of the stream that holds resulting PDF data.
    pub stream: Option<String>,
}

// ============================================================================
// Navigation History
// ============================================================================

/// Result of Page.goBack / Page.goForward.
#[derive(Debug, Clone, Deserialize)]
pub struct NavigationHistoryResult {}

/// Result of Page.getNavigationHistory.
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct GetNavigationHistoryResult {
    /// Index of the current navigation history entry.
    pub current_index: i32,
    /// Array of navigation history entries.
    pub entries: Vec<NavigationEntry>,
}

/// Navigation history entry.
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct NavigationEntry {
    /// Unique id of the navigation history entry.
    pub id: i32,
    /// URL of the navigation history entry.
    pub url: String,
    /// URL that the user typed in the URL bar.
    #[serde(default)]
    pub user_typed_url: String,
    /// Title of the navigation history entry.
    pub title: String,
    /// Transition type.
    #[serde(default)]
    pub transition_type: String,
}

/// Parameters for Page.navigateToHistoryEntry.
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct NavigateToHistoryEntryParams {
    /// Unique id of the entry to navigate to.
    pub entry_id: i32,
}

// ============================================================================
// Init Scripts
// ============================================================================

/// Parameters for Page.addScriptToEvaluateOnNewDocument.
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct AddScriptToEvaluateOnNewDocumentParams {
    /// JavaScript source code to evaluate.
    pub source: String,
    /// If specified, creates an isolated world and evaluates given script in it.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub world_name: Option<String>,
    /// Whether this script should be injected into all frames.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub include_command_line_api: Option<bool>,
    /// If true, this script will run in utility world.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub run_immediately: Option<bool>,
}

/// Result of Page.addScriptToEvaluateOnNewDocument.
#[derive(Debug, Clone, Deserialize)]
pub struct AddScriptToEvaluateOnNewDocumentResult {
    /// Identifier of the added script.
    pub identifier: String,
}

/// Parameters for Page.removeScriptToEvaluateOnNewDocument.
#[derive(Debug, Clone, Serialize)]
pub struct RemoveScriptToEvaluateOnNewDocumentParams {
    /// Identifier of the script to remove.
    pub identifier: String,
}

// ============================================================================
// Page State
// ============================================================================

/// Parameters for Page.bringToFront (empty).
#[derive(Debug, Clone, Serialize, Default)]
pub struct BringToFrontParams {}

/// Parameters for Page.setDocumentContent.
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SetDocumentContentParams {
    /// Frame id to set HTML for.
    pub frame_id: String,
    /// HTML content to set.
    pub html: String,
}

/// Event: Page.windowOpen
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct WindowOpenEvent {
    /// The URL for the new window.
    pub url: String,
    /// Window name.
    pub window_name: String,
    /// An array of enabled window features.
    pub window_features: Vec<String>,
    /// Whether or not it was triggered by user gesture.
    pub user_gesture: bool,
}

// ============================================================================
// Frame Events
// ============================================================================

/// Event: Page.frameAttached
///
/// Fired when a frame has been attached to its parent.
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct FrameAttachedEvent {
    /// Id of the frame that has been attached.
    pub frame_id: String,
    /// Parent frame identifier.
    pub parent_frame_id: String,
    /// JavaScript stack trace of when frame was attached, only set if frame initiated from script.
    pub stack: Option<serde_json::Value>,
}

/// Event: Page.frameDetached
///
/// Fired when a frame has been detached from its parent.
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct FrameDetachedEvent {
    /// Id of the frame that has been detached.
    pub frame_id: String,
    /// Reason for the frame being detached.
    pub reason: Option<FrameDetachedReason>,
}

/// Reason for frame being detached.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum FrameDetachedReason {
    /// Frame was removed from the DOM.
    Remove,
    /// Frame was swapped (e.g., for out-of-process iframe).
    Swap,
}

/// Event: Page.navigatedWithinDocument
///
/// Fired when a frame navigation happened within the same document.
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct NavigatedWithinDocumentEvent {
    /// Id of the frame.
    pub frame_id: String,
    /// Frame's new url.
    pub url: String,
}

// ============================================================================
// File Chooser Events
// ============================================================================

/// Event: Page.fileChooserOpened
///
/// Emitted only when `page.setInterceptFileChooserDialog` is enabled.
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct FileChooserOpenedEvent {
    /// Id of the frame containing input node.
    pub frame_id: String,
    /// Input mode.
    pub mode: FileChooserMode,
    /// Input node id. Only present for file choosers opened via an input element
    /// with webkitdirectory attribute (directory picker).
    pub backend_node_id: Option<i32>,
}

/// File chooser mode.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum FileChooserMode {
    /// Select a single file.
    SelectSingle,
    /// Select multiple files.
    SelectMultiple,
}

/// Parameters for Page.setInterceptFileChooserDialog.
#[derive(Debug, Clone, Serialize)]
pub struct SetInterceptFileChooserDialogParams {
    /// Whether to intercept file chooser dialogs.
    pub enabled: bool,
}