Skip to main content

browser_protocol/browser/
mod.rs

1//! The Browser domain defines methods and events for browser managing.
2
3use serde::{Serialize, Deserialize};
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
216/// Grant specific permissions to the given origin and reject all others. Deprecated. Use
217/// setPermission instead.
218
219#[derive(Debug, Clone, Serialize, Deserialize, Default)]
220#[serde(rename_all = "camelCase")]
221pub struct GrantPermissionsParams {
222
223    pub permissions: Vec<PermissionType>,
224    /// Origin the permission applies to, all origins if not specified.
225
226    #[serde(skip_serializing_if = "Option::is_none")]
227    pub origin: Option<String>,
228    /// BrowserContext to override permissions. When omitted, default browser context is used.
229
230    #[serde(skip_serializing_if = "Option::is_none")]
231    pub browserContextId: Option<BrowserContextID>,
232}
233
234/// Reset all permission management for all origins.
235
236#[derive(Debug, Clone, Serialize, Deserialize, Default)]
237#[serde(rename_all = "camelCase")]
238pub struct ResetPermissionsParams {
239    /// BrowserContext to reset permissions. When omitted, default browser context is used.
240
241    #[serde(skip_serializing_if = "Option::is_none")]
242    pub browserContextId: Option<BrowserContextID>,
243}
244
245/// Set the behavior when downloading a file.
246
247#[derive(Debug, Clone, Serialize, Deserialize, Default)]
248#[serde(rename_all = "camelCase")]
249pub struct SetDownloadBehaviorParams {
250    /// Whether to allow all or deny all download requests, or use default Chrome behavior if
251    /// available (otherwise deny). |allowAndName| allows download and names files according to
252    /// their download guids.
253
254    pub behavior: String,
255    /// BrowserContext to set download behavior. When omitted, default browser context is used.
256
257    #[serde(skip_serializing_if = "Option::is_none")]
258    pub browserContextId: Option<BrowserContextID>,
259    /// The default path to save downloaded files to. This is required if behavior is set to 'allow'
260    /// or 'allowAndName'.
261
262    #[serde(skip_serializing_if = "Option::is_none")]
263    pub downloadPath: Option<String>,
264    /// Whether to emit download events (defaults to false).
265
266    #[serde(skip_serializing_if = "Option::is_none")]
267    pub eventsEnabled: Option<bool>,
268}
269
270/// Cancel a download if in progress
271
272#[derive(Debug, Clone, Serialize, Deserialize, Default)]
273#[serde(rename_all = "camelCase")]
274pub struct CancelDownloadParams {
275    /// Global unique identifier of the download.
276
277    pub guid: String,
278    /// BrowserContext to perform the action in. When omitted, default browser context is used.
279
280    #[serde(skip_serializing_if = "Option::is_none")]
281    pub browserContextId: Option<BrowserContextID>,
282}
283
284/// Returns version information.
285
286#[derive(Debug, Clone, Serialize, Deserialize, Default)]
287#[serde(rename_all = "camelCase")]
288pub struct GetVersionReturns {
289    /// Protocol version.
290
291    pub protocolVersion: String,
292    /// Product name.
293
294    pub product: String,
295    /// Product revision.
296
297    pub revision: String,
298    /// User-Agent.
299
300    pub userAgent: String,
301    /// V8 version.
302
303    pub jsVersion: String,
304}
305
306/// Returns the command line switches for the browser process if, and only if
307/// --enable-automation is on the commandline.
308
309#[derive(Debug, Clone, Serialize, Deserialize, Default)]
310#[serde(rename_all = "camelCase")]
311pub struct GetBrowserCommandLineReturns {
312    /// Commandline parameters
313
314    pub arguments: Vec<String>,
315}
316
317/// Get Chrome histograms.
318
319#[derive(Debug, Clone, Serialize, Deserialize, Default)]
320#[serde(rename_all = "camelCase")]
321pub struct GetHistogramsParams {
322    /// Requested substring in name. Only histograms which have query as a
323    /// substring in their name are extracted. An empty or absent query returns
324    /// all histograms.
325
326    #[serde(skip_serializing_if = "Option::is_none")]
327    pub query: Option<String>,
328    /// If true, retrieve delta since last delta call.
329
330    #[serde(skip_serializing_if = "Option::is_none")]
331    pub delta: Option<bool>,
332}
333
334/// Get Chrome histograms.
335
336#[derive(Debug, Clone, Serialize, Deserialize, Default)]
337#[serde(rename_all = "camelCase")]
338pub struct GetHistogramsReturns {
339    /// Histograms.
340
341    pub histograms: Vec<Histogram>,
342}
343
344/// Get a Chrome histogram by name.
345
346#[derive(Debug, Clone, Serialize, Deserialize, Default)]
347#[serde(rename_all = "camelCase")]
348pub struct GetHistogramParams {
349    /// Requested histogram name.
350
351    pub name: String,
352    /// If true, retrieve delta since last delta call.
353
354    #[serde(skip_serializing_if = "Option::is_none")]
355    pub delta: Option<bool>,
356}
357
358/// Get a Chrome histogram by name.
359
360#[derive(Debug, Clone, Serialize, Deserialize, Default)]
361#[serde(rename_all = "camelCase")]
362pub struct GetHistogramReturns {
363    /// Histogram.
364
365    pub histogram: Histogram,
366}
367
368/// Get position and size of the browser window.
369
370#[derive(Debug, Clone, Serialize, Deserialize, Default)]
371#[serde(rename_all = "camelCase")]
372pub struct GetWindowBoundsParams {
373    /// Browser window id.
374
375    pub windowId: WindowID,
376}
377
378/// Get position and size of the browser window.
379
380#[derive(Debug, Clone, Serialize, Deserialize, Default)]
381#[serde(rename_all = "camelCase")]
382pub struct GetWindowBoundsReturns {
383    /// Bounds information of the window. When window state is 'minimized', the restored window
384    /// position and size are returned.
385
386    pub bounds: Bounds,
387}
388
389/// Get the browser window that contains the devtools target.
390
391#[derive(Debug, Clone, Serialize, Deserialize, Default)]
392#[serde(rename_all = "camelCase")]
393pub struct GetWindowForTargetParams {
394    /// Devtools agent host id. If called as a part of the session, associated targetId is used.
395
396    #[serde(skip_serializing_if = "Option::is_none")]
397    pub targetId: Option<crate::target::TargetID>,
398}
399
400/// Get the browser window that contains the devtools target.
401
402#[derive(Debug, Clone, Serialize, Deserialize, Default)]
403#[serde(rename_all = "camelCase")]
404pub struct GetWindowForTargetReturns {
405    /// Browser window id.
406
407    pub windowId: WindowID,
408    /// Bounds information of the window. When window state is 'minimized', the restored window
409    /// position and size are returned.
410
411    pub bounds: Bounds,
412}
413
414/// Set position and/or size of the browser window.
415
416#[derive(Debug, Clone, Serialize, Deserialize, Default)]
417#[serde(rename_all = "camelCase")]
418pub struct SetWindowBoundsParams {
419    /// Browser window id.
420
421    pub windowId: WindowID,
422    /// New window bounds. The 'minimized', 'maximized' and 'fullscreen' states cannot be combined
423    /// with 'left', 'top', 'width' or 'height'. Leaves unspecified fields unchanged.
424
425    pub bounds: Bounds,
426}
427
428/// Set size of the browser contents resizing browser window as necessary.
429
430#[derive(Debug, Clone, Serialize, Deserialize, Default)]
431#[serde(rename_all = "camelCase")]
432pub struct SetContentsSizeParams {
433    /// Browser window id.
434
435    pub windowId: WindowID,
436    /// The window contents width in DIP. Assumes current width if omitted.
437    /// Must be specified if 'height' is omitted.
438
439    #[serde(skip_serializing_if = "Option::is_none")]
440    pub width: Option<u64>,
441    /// The window contents height in DIP. Assumes current height if omitted.
442    /// Must be specified if 'width' is omitted.
443
444    #[serde(skip_serializing_if = "Option::is_none")]
445    pub height: Option<i64>,
446}
447
448/// Set dock tile details, platform-specific.
449
450#[derive(Debug, Clone, Serialize, Deserialize, Default)]
451#[serde(rename_all = "camelCase")]
452pub struct SetDockTileParams {
453
454    #[serde(skip_serializing_if = "Option::is_none")]
455    pub badgeLabel: Option<String>,
456    /// Png encoded image. (Encoded as a base64 string when passed over JSON)
457
458    #[serde(skip_serializing_if = "Option::is_none")]
459    pub image: Option<String>,
460}
461
462/// Invoke custom browser commands used by telemetry.
463
464#[derive(Debug, Clone, Serialize, Deserialize, Default)]
465#[serde(rename_all = "camelCase")]
466pub struct ExecuteBrowserCommandParams {
467
468    pub commandId: BrowserCommandId,
469}
470
471/// Allows a site to use privacy sandbox features that require enrollment
472/// without the site actually being enrolled. Only supported on page targets.
473
474#[derive(Debug, Clone, Serialize, Deserialize, Default)]
475#[serde(rename_all = "camelCase")]
476pub struct AddPrivacySandboxEnrollmentOverrideParams {
477
478    pub url: String,
479}
480
481/// Configures encryption keys used with a given privacy sandbox API to talk
482/// to a trusted coordinator.  Since this is intended for test automation only,
483/// coordinatorOrigin must be a .test domain. No existing coordinator
484/// configuration for the origin may exist.
485
486#[derive(Debug, Clone, Serialize, Deserialize, Default)]
487#[serde(rename_all = "camelCase")]
488pub struct AddPrivacySandboxCoordinatorKeyConfigParams {
489
490    pub api: PrivacySandboxAPI,
491
492    pub coordinatorOrigin: String,
493
494    pub keyConfig: String,
495    /// BrowserContext to perform the action in. When omitted, default browser
496    /// context is used.
497
498    #[serde(skip_serializing_if = "Option::is_none")]
499    pub browserContextId: Option<BrowserContextID>,
500}