Skip to main content

browser_protocol/browser/
mod.rs

1//! The Browser domain defines methods and events for browser managing.
2use serde::{Serialize, Deserialize};
3use serde_json::Value as JsonValue;
4
5
6pub type BrowserContextID = String;
7
8
9pub type WindowID = i64;
10
11/// The state of the browser window.
12
13#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
14pub enum WindowState {
15    #[default]
16    Normal,
17    Minimized,
18    Maximized,
19    Fullscreen,
20}
21
22/// Browser window bounds information
23
24#[derive(Debug, Clone, Serialize, Deserialize, Default)]
25#[serde(rename_all = "camelCase")]
26pub struct Bounds {
27    /// The offset from the left edge of the screen to the window in pixels.
28
29    #[serde(skip_serializing_if = "Option::is_none")]
30    pub left: Option<i64>,
31    /// The offset from the top edge of the screen to the window in pixels.
32
33    #[serde(skip_serializing_if = "Option::is_none")]
34    pub top: Option<i64>,
35    /// The window width in pixels.
36
37    #[serde(skip_serializing_if = "Option::is_none")]
38    pub width: Option<u64>,
39    /// The window height in pixels.
40
41    #[serde(skip_serializing_if = "Option::is_none")]
42    pub height: Option<i64>,
43    /// The window state. Default to normal.
44
45    #[serde(skip_serializing_if = "Option::is_none")]
46    pub windowState: Option<WindowState>,
47}
48
49
50#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
51pub enum PermissionType {
52    #[default]
53    Ar,
54    AudioCapture,
55    AutomaticFullscreen,
56    BackgroundFetch,
57    BackgroundSync,
58    CameraPanTiltZoom,
59    CapturedSurfaceControl,
60    ClipboardReadWrite,
61    ClipboardSanitizedWrite,
62    DisplayCapture,
63    DurableStorage,
64    Geolocation,
65    HandTracking,
66    IdleDetection,
67    KeyboardLock,
68    LocalFonts,
69    LocalNetwork,
70    LocalNetworkAccess,
71    LoopbackNetwork,
72    Midi,
73    MidiSysex,
74    Nfc,
75    Notifications,
76    PaymentHandler,
77    PeriodicBackgroundSync,
78    PointerLock,
79    ProtectedMediaIdentifier,
80    Sensors,
81    SmartCard,
82    SpeakerSelection,
83    StorageAccess,
84    TopLevelStorageAccess,
85    VideoCapture,
86    Vr,
87    WakeLockScreen,
88    WakeLockSystem,
89    WebAppInstallation,
90    WebPrinting,
91    WindowManagement,
92}
93
94
95#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
96pub enum PermissionSetting {
97    #[default]
98    Granted,
99    Denied,
100    Prompt,
101}
102
103/// Definition of PermissionDescriptor defined in the Permissions API:
104/// https://w3c.github.io/permissions/#dom-permissiondescriptor.
105
106#[derive(Debug, Clone, Serialize, Deserialize, Default)]
107#[serde(rename_all = "camelCase")]
108pub struct PermissionDescriptor {
109    /// Name of permission.
110    /// See https://cs.chromium.org/chromium/src/third_party/blink/renderer/modules/permissions/permission_descriptor.idl for valid permission names.
111
112    pub name: String,
113    /// For "midi" permission, may also specify sysex control.
114
115    #[serde(skip_serializing_if = "Option::is_none")]
116    pub sysex: Option<bool>,
117    /// For "push" permission, may specify userVisibleOnly.
118    /// Note that userVisibleOnly = true is the only currently supported type.
119
120    #[serde(skip_serializing_if = "Option::is_none")]
121    pub userVisibleOnly: Option<bool>,
122    /// For "clipboard" permission, may specify allowWithoutSanitization.
123
124    #[serde(skip_serializing_if = "Option::is_none")]
125    pub allowWithoutSanitization: Option<bool>,
126    /// For "fullscreen" permission, must specify allowWithoutGesture:true.
127
128    #[serde(skip_serializing_if = "Option::is_none")]
129    pub allowWithoutGesture: Option<bool>,
130    /// For "camera" permission, may specify panTiltZoom.
131
132    #[serde(skip_serializing_if = "Option::is_none")]
133    pub panTiltZoom: Option<bool>,
134}
135
136/// Browser command ids used by executeBrowserCommand.
137
138#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
139pub enum BrowserCommandId {
140    #[default]
141    OpenTabSearch,
142    CloseTabSearch,
143    OpenGlic,
144}
145
146/// Chrome histogram bucket.
147
148#[derive(Debug, Clone, Serialize, Deserialize, Default)]
149#[serde(rename_all = "camelCase")]
150pub struct Bucket {
151    /// Minimum value (inclusive).
152
153    pub low: i64,
154    /// Maximum value (exclusive).
155
156    pub high: i64,
157    /// Number of samples.
158
159    pub count: u64,
160}
161
162/// Chrome histogram.
163
164#[derive(Debug, Clone, Serialize, Deserialize, Default)]
165#[serde(rename_all = "camelCase")]
166pub struct Histogram {
167    /// Name.
168
169    pub name: String,
170    /// Sum of sample values.
171
172    pub sum: i64,
173    /// Total number of samples.
174
175    pub count: u64,
176    /// Buckets.
177
178    pub buckets: Vec<Bucket>,
179}
180
181
182#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
183pub enum PrivacySandboxAPI {
184    #[default]
185    BiddingAndAuctionServices,
186    TrustedKeyValue,
187}
188
189/// Set permission settings for given embedding and embedded origins.
190
191#[derive(Debug, Clone, Serialize, Deserialize, Default)]
192#[serde(rename_all = "camelCase")]
193pub struct SetPermissionParams {
194    /// Descriptor of permission to override.
195
196    pub permission: PermissionDescriptor,
197    /// Setting of the permission.
198
199    pub setting: PermissionSetting,
200    /// Embedding origin the permission applies to, all origins if not specified.
201
202    #[serde(skip_serializing_if = "Option::is_none")]
203    pub origin: Option<String>,
204    /// Embedded origin the permission applies to. It is ignored unless the embedding origin is
205    /// present and valid. If the embedding origin is provided but the embedded origin isn't, the
206    /// embedding origin is used as the embedded origin.
207
208    #[serde(skip_serializing_if = "Option::is_none")]
209    pub embeddedOrigin: Option<String>,
210    /// Context to override. When omitted, default browser context is used.
211
212    #[serde(skip_serializing_if = "Option::is_none")]
213    pub browserContextId: Option<BrowserContextID>,
214}
215
216impl SetPermissionParams { pub const METHOD: &'static str = "Browser.setPermission"; }
217
218impl crate::CdpCommand for SetPermissionParams {
219    const METHOD: &'static str = "Browser.setPermission";
220    type Response = crate::EmptyReturns;
221}
222
223/// Grant specific permissions to the given origin and reject all others. Deprecated. Use
224/// setPermission instead.
225
226#[derive(Debug, Clone, Serialize, Deserialize, Default)]
227#[serde(rename_all = "camelCase")]
228pub struct GrantPermissionsParams {
229
230    pub permissions: Vec<PermissionType>,
231    /// Origin the permission applies to, all origins if not specified.
232
233    #[serde(skip_serializing_if = "Option::is_none")]
234    pub origin: Option<String>,
235    /// BrowserContext to override permissions. When omitted, default browser context is used.
236
237    #[serde(skip_serializing_if = "Option::is_none")]
238    pub browserContextId: Option<BrowserContextID>,
239}
240
241impl GrantPermissionsParams { pub const METHOD: &'static str = "Browser.grantPermissions"; }
242
243impl crate::CdpCommand for GrantPermissionsParams {
244    const METHOD: &'static str = "Browser.grantPermissions";
245    type Response = crate::EmptyReturns;
246}
247
248/// Reset all permission management for all origins.
249
250#[derive(Debug, Clone, Serialize, Deserialize, Default)]
251#[serde(rename_all = "camelCase")]
252pub struct ResetPermissionsParams {
253    /// BrowserContext to reset permissions. When omitted, default browser context is used.
254
255    #[serde(skip_serializing_if = "Option::is_none")]
256    pub browserContextId: Option<BrowserContextID>,
257}
258
259impl ResetPermissionsParams { pub const METHOD: &'static str = "Browser.resetPermissions"; }
260
261impl crate::CdpCommand for ResetPermissionsParams {
262    const METHOD: &'static str = "Browser.resetPermissions";
263    type Response = crate::EmptyReturns;
264}
265
266/// Set the behavior when downloading a file.
267
268#[derive(Debug, Clone, Serialize, Deserialize, Default)]
269#[serde(rename_all = "camelCase")]
270pub struct SetDownloadBehaviorParams {
271    /// Whether to allow all or deny all download requests, or use default Chrome behavior if
272    /// available (otherwise deny). |allowAndName| allows download and names files according to
273    /// their download guids.
274
275    pub behavior: String,
276    /// BrowserContext to set download behavior. When omitted, default browser context is used.
277
278    #[serde(skip_serializing_if = "Option::is_none")]
279    pub browserContextId: Option<BrowserContextID>,
280    /// The default path to save downloaded files to. This is required if behavior is set to 'allow'
281    /// or 'allowAndName'.
282
283    #[serde(skip_serializing_if = "Option::is_none")]
284    pub downloadPath: Option<String>,
285    /// Whether to emit download events (defaults to false).
286
287    #[serde(skip_serializing_if = "Option::is_none")]
288    pub eventsEnabled: Option<bool>,
289}
290
291impl SetDownloadBehaviorParams { pub const METHOD: &'static str = "Browser.setDownloadBehavior"; }
292
293impl crate::CdpCommand for SetDownloadBehaviorParams {
294    const METHOD: &'static str = "Browser.setDownloadBehavior";
295    type Response = crate::EmptyReturns;
296}
297
298/// Cancel a download if in progress
299
300#[derive(Debug, Clone, Serialize, Deserialize, Default)]
301#[serde(rename_all = "camelCase")]
302pub struct CancelDownloadParams {
303    /// Global unique identifier of the download.
304
305    pub guid: String,
306    /// BrowserContext to perform the action in. When omitted, default browser context is used.
307
308    #[serde(skip_serializing_if = "Option::is_none")]
309    pub browserContextId: Option<BrowserContextID>,
310}
311
312impl CancelDownloadParams { pub const METHOD: &'static str = "Browser.cancelDownload"; }
313
314impl crate::CdpCommand for CancelDownloadParams {
315    const METHOD: &'static str = "Browser.cancelDownload";
316    type Response = crate::EmptyReturns;
317}
318
319#[derive(Debug, Clone, Serialize, Deserialize, Default)]
320pub struct CloseParams {}
321
322impl CloseParams { pub const METHOD: &'static str = "Browser.close"; }
323
324impl crate::CdpCommand for CloseParams {
325    const METHOD: &'static str = "Browser.close";
326    type Response = crate::EmptyReturns;
327}
328
329#[derive(Debug, Clone, Serialize, Deserialize, Default)]
330pub struct CrashParams {}
331
332impl CrashParams { pub const METHOD: &'static str = "Browser.crash"; }
333
334impl crate::CdpCommand for CrashParams {
335    const METHOD: &'static str = "Browser.crash";
336    type Response = crate::EmptyReturns;
337}
338
339#[derive(Debug, Clone, Serialize, Deserialize, Default)]
340pub struct CrashGpuProcessParams {}
341
342impl CrashGpuProcessParams { pub const METHOD: &'static str = "Browser.crashGpuProcess"; }
343
344impl crate::CdpCommand for CrashGpuProcessParams {
345    const METHOD: &'static str = "Browser.crashGpuProcess";
346    type Response = crate::EmptyReturns;
347}
348
349/// Returns version information.
350
351#[derive(Debug, Clone, Serialize, Deserialize, Default)]
352#[serde(rename_all = "camelCase")]
353pub struct GetVersionReturns {
354    /// Protocol version.
355
356    pub protocolVersion: String,
357    /// Product name.
358
359    pub product: String,
360    /// Product revision.
361
362    pub revision: String,
363    /// User-Agent.
364
365    pub userAgent: String,
366    /// V8 version.
367
368    pub jsVersion: String,
369}
370
371#[derive(Debug, Clone, Serialize, Deserialize, Default)]
372pub struct GetVersionParams {}
373
374impl GetVersionParams { pub const METHOD: &'static str = "Browser.getVersion"; }
375
376impl crate::CdpCommand for GetVersionParams {
377    const METHOD: &'static str = "Browser.getVersion";
378    type Response = GetVersionReturns;
379}
380
381/// Returns the command line switches for the browser process if, and only if
382/// --enable-automation is on the commandline.
383
384#[derive(Debug, Clone, Serialize, Deserialize, Default)]
385#[serde(rename_all = "camelCase")]
386pub struct GetBrowserCommandLineReturns {
387    /// Commandline parameters
388
389    pub arguments: Vec<String>,
390}
391
392#[derive(Debug, Clone, Serialize, Deserialize, Default)]
393pub struct GetBrowserCommandLineParams {}
394
395impl GetBrowserCommandLineParams { pub const METHOD: &'static str = "Browser.getBrowserCommandLine"; }
396
397impl crate::CdpCommand for GetBrowserCommandLineParams {
398    const METHOD: &'static str = "Browser.getBrowserCommandLine";
399    type Response = GetBrowserCommandLineReturns;
400}
401
402/// Get Chrome histograms.
403
404#[derive(Debug, Clone, Serialize, Deserialize, Default)]
405#[serde(rename_all = "camelCase")]
406pub struct GetHistogramsParams {
407    /// Requested substring in name. Only histograms which have query as a
408    /// substring in their name are extracted. An empty or absent query returns
409    /// all histograms.
410
411    #[serde(skip_serializing_if = "Option::is_none")]
412    pub query: Option<String>,
413    /// If true, retrieve delta since last delta call.
414
415    #[serde(skip_serializing_if = "Option::is_none")]
416    pub delta: Option<bool>,
417}
418
419/// Get Chrome histograms.
420
421#[derive(Debug, Clone, Serialize, Deserialize, Default)]
422#[serde(rename_all = "camelCase")]
423pub struct GetHistogramsReturns {
424    /// Histograms.
425
426    pub histograms: Vec<Histogram>,
427}
428
429impl GetHistogramsParams { pub const METHOD: &'static str = "Browser.getHistograms"; }
430
431impl crate::CdpCommand for GetHistogramsParams {
432    const METHOD: &'static str = "Browser.getHistograms";
433    type Response = GetHistogramsReturns;
434}
435
436/// Get a Chrome histogram by name.
437
438#[derive(Debug, Clone, Serialize, Deserialize, Default)]
439#[serde(rename_all = "camelCase")]
440pub struct GetHistogramParams {
441    /// Requested histogram name.
442
443    pub name: String,
444    /// If true, retrieve delta since last delta call.
445
446    #[serde(skip_serializing_if = "Option::is_none")]
447    pub delta: Option<bool>,
448}
449
450/// Get a Chrome histogram by name.
451
452#[derive(Debug, Clone, Serialize, Deserialize, Default)]
453#[serde(rename_all = "camelCase")]
454pub struct GetHistogramReturns {
455    /// Histogram.
456
457    pub histogram: Histogram,
458}
459
460impl GetHistogramParams { pub const METHOD: &'static str = "Browser.getHistogram"; }
461
462impl crate::CdpCommand for GetHistogramParams {
463    const METHOD: &'static str = "Browser.getHistogram";
464    type Response = GetHistogramReturns;
465}
466
467/// Get position and size of the browser window.
468
469#[derive(Debug, Clone, Serialize, Deserialize, Default)]
470#[serde(rename_all = "camelCase")]
471pub struct GetWindowBoundsParams {
472    /// Browser window id.
473
474    pub windowId: WindowID,
475}
476
477/// Get position and size of the browser window.
478
479#[derive(Debug, Clone, Serialize, Deserialize, Default)]
480#[serde(rename_all = "camelCase")]
481pub struct GetWindowBoundsReturns {
482    /// Bounds information of the window. When window state is 'minimized', the restored window
483    /// position and size are returned.
484
485    pub bounds: Bounds,
486}
487
488impl GetWindowBoundsParams { pub const METHOD: &'static str = "Browser.getWindowBounds"; }
489
490impl crate::CdpCommand for GetWindowBoundsParams {
491    const METHOD: &'static str = "Browser.getWindowBounds";
492    type Response = GetWindowBoundsReturns;
493}
494
495/// Get the browser window that contains the devtools target.
496
497#[derive(Debug, Clone, Serialize, Deserialize, Default)]
498#[serde(rename_all = "camelCase")]
499pub struct GetWindowForTargetParams {
500    /// Devtools agent host id. If called as a part of the session, associated targetId is used.
501
502    #[serde(skip_serializing_if = "Option::is_none")]
503    pub targetId: Option<crate::target::TargetID>,
504}
505
506/// Get the browser window that contains the devtools target.
507
508#[derive(Debug, Clone, Serialize, Deserialize, Default)]
509#[serde(rename_all = "camelCase")]
510pub struct GetWindowForTargetReturns {
511    /// Browser window id.
512
513    pub windowId: WindowID,
514    /// Bounds information of the window. When window state is 'minimized', the restored window
515    /// position and size are returned.
516
517    pub bounds: Bounds,
518}
519
520impl GetWindowForTargetParams { pub const METHOD: &'static str = "Browser.getWindowForTarget"; }
521
522impl crate::CdpCommand for GetWindowForTargetParams {
523    const METHOD: &'static str = "Browser.getWindowForTarget";
524    type Response = GetWindowForTargetReturns;
525}
526
527/// Set position and/or size of the browser window.
528
529#[derive(Debug, Clone, Serialize, Deserialize, Default)]
530#[serde(rename_all = "camelCase")]
531pub struct SetWindowBoundsParams {
532    /// Browser window id.
533
534    pub windowId: WindowID,
535    /// New window bounds. The 'minimized', 'maximized' and 'fullscreen' states cannot be combined
536    /// with 'left', 'top', 'width' or 'height'. Leaves unspecified fields unchanged.
537
538    pub bounds: Bounds,
539}
540
541impl SetWindowBoundsParams { pub const METHOD: &'static str = "Browser.setWindowBounds"; }
542
543impl crate::CdpCommand for SetWindowBoundsParams {
544    const METHOD: &'static str = "Browser.setWindowBounds";
545    type Response = crate::EmptyReturns;
546}
547
548/// Set size of the browser contents resizing browser window as necessary.
549
550#[derive(Debug, Clone, Serialize, Deserialize, Default)]
551#[serde(rename_all = "camelCase")]
552pub struct SetContentsSizeParams {
553    /// Browser window id.
554
555    pub windowId: WindowID,
556    /// The window contents width in DIP. Assumes current width if omitted.
557    /// Must be specified if 'height' is omitted.
558
559    #[serde(skip_serializing_if = "Option::is_none")]
560    pub width: Option<u64>,
561    /// The window contents height in DIP. Assumes current height if omitted.
562    /// Must be specified if 'width' is omitted.
563
564    #[serde(skip_serializing_if = "Option::is_none")]
565    pub height: Option<i64>,
566}
567
568impl SetContentsSizeParams { pub const METHOD: &'static str = "Browser.setContentsSize"; }
569
570impl crate::CdpCommand for SetContentsSizeParams {
571    const METHOD: &'static str = "Browser.setContentsSize";
572    type Response = crate::EmptyReturns;
573}
574
575/// Set dock tile details, platform-specific.
576
577#[derive(Debug, Clone, Serialize, Deserialize, Default)]
578#[serde(rename_all = "camelCase")]
579pub struct SetDockTileParams {
580
581    #[serde(skip_serializing_if = "Option::is_none")]
582    pub badgeLabel: Option<String>,
583    /// Png encoded image. (Encoded as a base64 string when passed over JSON)
584
585    #[serde(skip_serializing_if = "Option::is_none")]
586    pub image: Option<String>,
587}
588
589impl SetDockTileParams { pub const METHOD: &'static str = "Browser.setDockTile"; }
590
591impl crate::CdpCommand for SetDockTileParams {
592    const METHOD: &'static str = "Browser.setDockTile";
593    type Response = crate::EmptyReturns;
594}
595
596/// Invoke custom browser commands used by telemetry.
597
598#[derive(Debug, Clone, Serialize, Deserialize, Default)]
599#[serde(rename_all = "camelCase")]
600pub struct ExecuteBrowserCommandParams {
601
602    pub commandId: BrowserCommandId,
603}
604
605impl ExecuteBrowserCommandParams { pub const METHOD: &'static str = "Browser.executeBrowserCommand"; }
606
607impl crate::CdpCommand for ExecuteBrowserCommandParams {
608    const METHOD: &'static str = "Browser.executeBrowserCommand";
609    type Response = crate::EmptyReturns;
610}
611
612/// Allows a site to use privacy sandbox features that require enrollment
613/// without the site actually being enrolled. Only supported on page targets.
614
615#[derive(Debug, Clone, Serialize, Deserialize, Default)]
616#[serde(rename_all = "camelCase")]
617pub struct AddPrivacySandboxEnrollmentOverrideParams {
618
619    pub url: String,
620}
621
622impl AddPrivacySandboxEnrollmentOverrideParams { pub const METHOD: &'static str = "Browser.addPrivacySandboxEnrollmentOverride"; }
623
624impl crate::CdpCommand for AddPrivacySandboxEnrollmentOverrideParams {
625    const METHOD: &'static str = "Browser.addPrivacySandboxEnrollmentOverride";
626    type Response = crate::EmptyReturns;
627}
628
629/// Configures encryption keys used with a given privacy sandbox API to talk
630/// to a trusted coordinator.  Since this is intended for test automation only,
631/// coordinatorOrigin must be a .test domain. No existing coordinator
632/// configuration for the origin may exist.
633
634#[derive(Debug, Clone, Serialize, Deserialize, Default)]
635#[serde(rename_all = "camelCase")]
636pub struct AddPrivacySandboxCoordinatorKeyConfigParams {
637
638    pub api: PrivacySandboxAPI,
639
640    pub coordinatorOrigin: String,
641
642    pub keyConfig: String,
643    /// BrowserContext to perform the action in. When omitted, default browser
644    /// context is used.
645
646    #[serde(skip_serializing_if = "Option::is_none")]
647    pub browserContextId: Option<BrowserContextID>,
648}
649
650impl AddPrivacySandboxCoordinatorKeyConfigParams { pub const METHOD: &'static str = "Browser.addPrivacySandboxCoordinatorKeyConfig"; }
651
652impl crate::CdpCommand for AddPrivacySandboxCoordinatorKeyConfigParams {
653    const METHOD: &'static str = "Browser.addPrivacySandboxCoordinatorKeyConfig";
654    type Response = crate::EmptyReturns;
655}