-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathbrowser.py
More file actions
821 lines (678 loc) · 25.3 KB
/
browser.py
File metadata and controls
821 lines (678 loc) · 25.3 KB
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
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
# DO NOT EDIT THIS FILE!
#
# This file is generated from the CDP specification. If you need to make
# changes, edit the generator and regenerate all of the modules.
#
# CDP domain: Browser
from __future__ import annotations
from cdp.util import event_class, T_JSON_DICT
from dataclasses import dataclass
import enum
import typing
from . import page
from . import target
from deprecated.sphinx import deprecated # type: ignore
class BrowserContextID(str):
def to_json(self) -> str:
return self
@classmethod
def from_json(cls, json: str) -> BrowserContextID:
return cls(json)
def __repr__(self):
return 'BrowserContextID({})'.format(super().__repr__())
class WindowID(int):
def to_json(self) -> int:
return self
@classmethod
def from_json(cls, json: int) -> WindowID:
return cls(json)
def __repr__(self):
return 'WindowID({})'.format(super().__repr__())
class WindowState(enum.Enum):
r'''
The state of the browser window.
'''
NORMAL = "normal"
MINIMIZED = "minimized"
MAXIMIZED = "maximized"
FULLSCREEN = "fullscreen"
def to_json(self) -> str:
return self.value
@classmethod
def from_json(cls, json: str) -> WindowState:
return cls(json)
@dataclass
class Bounds:
r'''
Browser window bounds information
'''
#: The offset from the left edge of the screen to the window in pixels.
left: typing.Optional[int] = None
#: The offset from the top edge of the screen to the window in pixels.
top: typing.Optional[int] = None
#: The window width in pixels.
width: typing.Optional[int] = None
#: The window height in pixels.
height: typing.Optional[int] = None
#: The window state. Default to normal.
window_state: typing.Optional[WindowState] = None
def to_json(self) -> T_JSON_DICT:
json: T_JSON_DICT = dict()
if self.left is not None:
json['left'] = self.left
if self.top is not None:
json['top'] = self.top
if self.width is not None:
json['width'] = self.width
if self.height is not None:
json['height'] = self.height
if self.window_state is not None:
json['windowState'] = self.window_state.to_json()
return json
@classmethod
def from_json(cls, json: T_JSON_DICT) -> Bounds:
return cls(
left=int(json['left']) if 'left' in json else None,
top=int(json['top']) if 'top' in json else None,
width=int(json['width']) if 'width' in json else None,
height=int(json['height']) if 'height' in json else None,
window_state=WindowState.from_json(json['windowState']) if 'windowState' in json else None,
)
class PermissionType(enum.Enum):
AR = "ar"
AUDIO_CAPTURE = "audioCapture"
AUTOMATIC_FULLSCREEN = "automaticFullscreen"
BACKGROUND_FETCH = "backgroundFetch"
BACKGROUND_SYNC = "backgroundSync"
CAMERA_PAN_TILT_ZOOM = "cameraPanTiltZoom"
CAPTURED_SURFACE_CONTROL = "capturedSurfaceControl"
CLIPBOARD_READ_WRITE = "clipboardReadWrite"
CLIPBOARD_SANITIZED_WRITE = "clipboardSanitizedWrite"
DISPLAY_CAPTURE = "displayCapture"
DURABLE_STORAGE = "durableStorage"
GEOLOCATION = "geolocation"
HAND_TRACKING = "handTracking"
IDLE_DETECTION = "idleDetection"
KEYBOARD_LOCK = "keyboardLock"
LOCAL_FONTS = "localFonts"
LOCAL_NETWORK = "localNetwork"
LOCAL_NETWORK_ACCESS = "localNetworkAccess"
LOOPBACK_NETWORK = "loopbackNetwork"
MIDI = "midi"
MIDI_SYSEX = "midiSysex"
NFC = "nfc"
NOTIFICATIONS = "notifications"
PAYMENT_HANDLER = "paymentHandler"
PERIODIC_BACKGROUND_SYNC = "periodicBackgroundSync"
POINTER_LOCK = "pointerLock"
PROTECTED_MEDIA_IDENTIFIER = "protectedMediaIdentifier"
SENSORS = "sensors"
SMART_CARD = "smartCard"
SPEAKER_SELECTION = "speakerSelection"
STORAGE_ACCESS = "storageAccess"
TOP_LEVEL_STORAGE_ACCESS = "topLevelStorageAccess"
VIDEO_CAPTURE = "videoCapture"
VR = "vr"
WAKE_LOCK_SCREEN = "wakeLockScreen"
WAKE_LOCK_SYSTEM = "wakeLockSystem"
WEB_APP_INSTALLATION = "webAppInstallation"
WEB_PRINTING = "webPrinting"
WINDOW_MANAGEMENT = "windowManagement"
def to_json(self) -> str:
return self.value
@classmethod
def from_json(cls, json: str) -> PermissionType:
return cls(json)
class PermissionSetting(enum.Enum):
GRANTED = "granted"
DENIED = "denied"
PROMPT = "prompt"
def to_json(self) -> str:
return self.value
@classmethod
def from_json(cls, json: str) -> PermissionSetting:
return cls(json)
@dataclass
class PermissionDescriptor:
r'''
Definition of PermissionDescriptor defined in the Permissions API:
https://w3c.github.io/permissions/#dom-permissiondescriptor.
'''
#: Name of permission.
#: See https://cs.chromium.org/chromium/src/third_party/blink/renderer/modules/permissions/permission_descriptor.idl for valid permission names.
name: str
#: For "midi" permission, may also specify sysex control.
sysex: typing.Optional[bool] = None
#: For "push" permission, may specify userVisibleOnly.
#: Note that userVisibleOnly = true is the only currently supported type.
user_visible_only: typing.Optional[bool] = None
#: For "clipboard" permission, may specify allowWithoutSanitization.
allow_without_sanitization: typing.Optional[bool] = None
#: For "fullscreen" permission, must specify allowWithoutGesture:true.
allow_without_gesture: typing.Optional[bool] = None
#: For "camera" permission, may specify panTiltZoom.
pan_tilt_zoom: typing.Optional[bool] = None
def to_json(self) -> T_JSON_DICT:
json: T_JSON_DICT = dict()
json['name'] = self.name
if self.sysex is not None:
json['sysex'] = self.sysex
if self.user_visible_only is not None:
json['userVisibleOnly'] = self.user_visible_only
if self.allow_without_sanitization is not None:
json['allowWithoutSanitization'] = self.allow_without_sanitization
if self.allow_without_gesture is not None:
json['allowWithoutGesture'] = self.allow_without_gesture
if self.pan_tilt_zoom is not None:
json['panTiltZoom'] = self.pan_tilt_zoom
return json
@classmethod
def from_json(cls, json: T_JSON_DICT) -> PermissionDescriptor:
return cls(
name=str(json['name']),
sysex=bool(json['sysex']) if 'sysex' in json else None,
user_visible_only=bool(json['userVisibleOnly']) if 'userVisibleOnly' in json else None,
allow_without_sanitization=bool(json['allowWithoutSanitization']) if 'allowWithoutSanitization' in json else None,
allow_without_gesture=bool(json['allowWithoutGesture']) if 'allowWithoutGesture' in json else None,
pan_tilt_zoom=bool(json['panTiltZoom']) if 'panTiltZoom' in json else None,
)
class BrowserCommandId(enum.Enum):
r'''
Browser command ids used by executeBrowserCommand.
'''
OPEN_TAB_SEARCH = "openTabSearch"
CLOSE_TAB_SEARCH = "closeTabSearch"
OPEN_GLIC = "openGlic"
def to_json(self) -> str:
return self.value
@classmethod
def from_json(cls, json: str) -> BrowserCommandId:
return cls(json)
@dataclass
class Bucket:
r'''
Chrome histogram bucket.
'''
#: Minimum value (inclusive).
low: int
#: Maximum value (exclusive).
high: int
#: Number of samples.
count: int
def to_json(self) -> T_JSON_DICT:
json: T_JSON_DICT = dict()
json['low'] = self.low
json['high'] = self.high
json['count'] = self.count
return json
@classmethod
def from_json(cls, json: T_JSON_DICT) -> Bucket:
return cls(
low=int(json['low']),
high=int(json['high']),
count=int(json['count']),
)
@dataclass
class Histogram:
r'''
Chrome histogram.
'''
#: Name.
name: str
#: Sum of sample values.
sum_: int
#: Total number of samples.
count: int
#: Buckets.
buckets: typing.List[Bucket]
def to_json(self) -> T_JSON_DICT:
json: T_JSON_DICT = dict()
json['name'] = self.name
json['sum'] = self.sum_
json['count'] = self.count
json['buckets'] = [i.to_json() for i in self.buckets]
return json
@classmethod
def from_json(cls, json: T_JSON_DICT) -> Histogram:
return cls(
name=str(json['name']),
sum_=int(json['sum']),
count=int(json['count']),
buckets=[Bucket.from_json(i) for i in json['buckets']],
)
class PrivacySandboxAPI(enum.Enum):
BIDDING_AND_AUCTION_SERVICES = "BiddingAndAuctionServices"
TRUSTED_KEY_VALUE = "TrustedKeyValue"
def to_json(self) -> str:
return self.value
@classmethod
def from_json(cls, json: str) -> PrivacySandboxAPI:
return cls(json)
def set_permission(
permission: PermissionDescriptor,
setting: PermissionSetting,
origin: typing.Optional[str] = None,
embedded_origin: typing.Optional[str] = None,
browser_context_id: typing.Optional[BrowserContextID] = None
) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
r'''
Set permission settings for given embedding and embedded origins.
**EXPERIMENTAL**
:param permission: Descriptor of permission to override.
:param setting: Setting of the permission.
:param origin: *(Optional)* Embedding origin the permission applies to, all origins if not specified.
:param embedded_origin: *(Optional)* Embedded origin the permission applies to. It is ignored unless the embedding origin is present and valid. If the embedding origin is provided but the embedded origin isn't, the embedding origin is used as the embedded origin.
:param browser_context_id: *(Optional)* Context to override. When omitted, default browser context is used.
'''
params: T_JSON_DICT = dict()
params['permission'] = permission.to_json()
params['setting'] = setting.to_json()
if origin is not None:
params['origin'] = origin
if embedded_origin is not None:
params['embeddedOrigin'] = embedded_origin
if browser_context_id is not None:
params['browserContextId'] = browser_context_id.to_json()
cmd_dict: T_JSON_DICT = {
'method': 'Browser.setPermission',
'params': params,
}
json = yield cmd_dict
@deprecated(version="1.3")
def grant_permissions(
permissions: typing.List[PermissionType],
origin: typing.Optional[str] = None,
browser_context_id: typing.Optional[BrowserContextID] = None
) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
r'''
Grant specific permissions to the given origin and reject all others. Deprecated. Use
setPermission instead.
.. deprecated:: 1.3
**EXPERIMENTAL**
:param permissions:
:param origin: *(Optional)* Origin the permission applies to, all origins if not specified.
:param browser_context_id: *(Optional)* BrowserContext to override permissions. When omitted, default browser context is used.
'''
params: T_JSON_DICT = dict()
params['permissions'] = [i.to_json() for i in permissions]
if origin is not None:
params['origin'] = origin
if browser_context_id is not None:
params['browserContextId'] = browser_context_id.to_json()
cmd_dict: T_JSON_DICT = {
'method': 'Browser.grantPermissions',
'params': params,
}
json = yield cmd_dict
def reset_permissions(
browser_context_id: typing.Optional[BrowserContextID] = None
) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
r'''
Reset all permission management for all origins.
:param browser_context_id: *(Optional)* BrowserContext to reset permissions. When omitted, default browser context is used.
'''
params: T_JSON_DICT = dict()
if browser_context_id is not None:
params['browserContextId'] = browser_context_id.to_json()
cmd_dict: T_JSON_DICT = {
'method': 'Browser.resetPermissions',
'params': params,
}
json = yield cmd_dict
def set_download_behavior(
behavior: str,
browser_context_id: typing.Optional[BrowserContextID] = None,
download_path: typing.Optional[str] = None,
events_enabled: typing.Optional[bool] = None
) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
r'''
Set the behavior when downloading a file.
**EXPERIMENTAL**
:param behavior: Whether to allow all or deny all download requests, or use default Chrome behavior if available (otherwise deny). ``allowAndName`` allows download and names files according to their download guids.
:param browser_context_id: *(Optional)* BrowserContext to set download behavior. When omitted, default browser context is used.
:param download_path: *(Optional)* The default path to save downloaded files to. This is required if behavior is set to 'allow' or 'allowAndName'.
:param events_enabled: *(Optional)* Whether to emit download events (defaults to false).
'''
params: T_JSON_DICT = dict()
params['behavior'] = behavior
if browser_context_id is not None:
params['browserContextId'] = browser_context_id.to_json()
if download_path is not None:
params['downloadPath'] = download_path
if events_enabled is not None:
params['eventsEnabled'] = events_enabled
cmd_dict: T_JSON_DICT = {
'method': 'Browser.setDownloadBehavior',
'params': params,
}
json = yield cmd_dict
def cancel_download(
guid: str,
browser_context_id: typing.Optional[BrowserContextID] = None
) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
r'''
Cancel a download if in progress
**EXPERIMENTAL**
:param guid: Global unique identifier of the download.
:param browser_context_id: *(Optional)* BrowserContext to perform the action in. When omitted, default browser context is used.
'''
params: T_JSON_DICT = dict()
params['guid'] = guid
if browser_context_id is not None:
params['browserContextId'] = browser_context_id.to_json()
cmd_dict: T_JSON_DICT = {
'method': 'Browser.cancelDownload',
'params': params,
}
json = yield cmd_dict
def close() -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
r'''
Close browser gracefully.
'''
cmd_dict: T_JSON_DICT = {
'method': 'Browser.close',
}
json = yield cmd_dict
def crash() -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
r'''
Crashes browser on the main thread.
**EXPERIMENTAL**
'''
cmd_dict: T_JSON_DICT = {
'method': 'Browser.crash',
}
json = yield cmd_dict
def crash_gpu_process() -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
r'''
Crashes GPU process.
**EXPERIMENTAL**
'''
cmd_dict: T_JSON_DICT = {
'method': 'Browser.crashGpuProcess',
}
json = yield cmd_dict
def get_version() -> typing.Generator[T_JSON_DICT,T_JSON_DICT,typing.Tuple[str, str, str, str, str]]:
r'''
Returns version information.
:returns: A tuple with the following items:
0. **protocolVersion** - Protocol version.
1. **product** - Product name.
2. **revision** - Product revision.
3. **userAgent** - User-Agent.
4. **jsVersion** - V8 version.
'''
cmd_dict: T_JSON_DICT = {
'method': 'Browser.getVersion',
}
json = yield cmd_dict
return (
str(json['protocolVersion']),
str(json['product']),
str(json['revision']),
str(json['userAgent']),
str(json['jsVersion'])
)
def get_browser_command_line() -> typing.Generator[T_JSON_DICT,T_JSON_DICT,typing.List[str]]:
r'''
Returns the command line switches for the browser process if, and only if
--enable-automation is on the commandline.
**EXPERIMENTAL**
:returns: Commandline parameters
'''
cmd_dict: T_JSON_DICT = {
'method': 'Browser.getBrowserCommandLine',
}
json = yield cmd_dict
return [str(i) for i in json['arguments']]
def get_histograms(
query: typing.Optional[str] = None,
delta: typing.Optional[bool] = None
) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,typing.List[Histogram]]:
r'''
Get Chrome histograms.
**EXPERIMENTAL**
:param query: *(Optional)* Requested substring in name. Only histograms which have query as a substring in their name are extracted. An empty or absent query returns all histograms.
:param delta: *(Optional)* If true, retrieve delta since last delta call.
:returns: Histograms.
'''
params: T_JSON_DICT = dict()
if query is not None:
params['query'] = query
if delta is not None:
params['delta'] = delta
cmd_dict: T_JSON_DICT = {
'method': 'Browser.getHistograms',
'params': params,
}
json = yield cmd_dict
return [Histogram.from_json(i) for i in json['histograms']]
def get_histogram(
name: str,
delta: typing.Optional[bool] = None
) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,Histogram]:
r'''
Get a Chrome histogram by name.
**EXPERIMENTAL**
:param name: Requested histogram name.
:param delta: *(Optional)* If true, retrieve delta since last delta call.
:returns: Histogram.
'''
params: T_JSON_DICT = dict()
params['name'] = name
if delta is not None:
params['delta'] = delta
cmd_dict: T_JSON_DICT = {
'method': 'Browser.getHistogram',
'params': params,
}
json = yield cmd_dict
return Histogram.from_json(json['histogram'])
def get_window_bounds(
window_id: WindowID
) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,Bounds]:
r'''
Get position and size of the browser window.
**EXPERIMENTAL**
:param window_id: Browser window id.
:returns: Bounds information of the window. When window state is 'minimized', the restored window position and size are returned.
'''
params: T_JSON_DICT = dict()
params['windowId'] = window_id.to_json()
cmd_dict: T_JSON_DICT = {
'method': 'Browser.getWindowBounds',
'params': params,
}
json = yield cmd_dict
return Bounds.from_json(json['bounds'])
def get_window_for_target(
target_id: typing.Optional[target.TargetID] = None
) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,typing.Tuple[WindowID, Bounds]]:
r'''
Get the browser window that contains the devtools target.
**EXPERIMENTAL**
:param target_id: *(Optional)* Devtools agent host id. If called as a part of the session, associated targetId is used.
:returns: A tuple with the following items:
0. **windowId** - Browser window id.
1. **bounds** - Bounds information of the window. When window state is 'minimized', the restored window position and size are returned.
'''
params: T_JSON_DICT = dict()
if target_id is not None:
params['targetId'] = target_id.to_json()
cmd_dict: T_JSON_DICT = {
'method': 'Browser.getWindowForTarget',
'params': params,
}
json = yield cmd_dict
return (
WindowID.from_json(json['windowId']),
Bounds.from_json(json['bounds'])
)
def set_window_bounds(
window_id: WindowID,
bounds: Bounds
) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
r'''
Set position and/or size of the browser window.
**EXPERIMENTAL**
:param window_id: Browser window id.
:param bounds: New window bounds. The 'minimized', 'maximized' and 'fullscreen' states cannot be combined with 'left', 'top', 'width' or 'height'. Leaves unspecified fields unchanged.
'''
params: T_JSON_DICT = dict()
params['windowId'] = window_id.to_json()
params['bounds'] = bounds.to_json()
cmd_dict: T_JSON_DICT = {
'method': 'Browser.setWindowBounds',
'params': params,
}
json = yield cmd_dict
def set_contents_size(
window_id: WindowID,
width: typing.Optional[int] = None,
height: typing.Optional[int] = None
) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
r'''
Set size of the browser contents resizing browser window as necessary.
**EXPERIMENTAL**
:param window_id: Browser window id.
:param width: *(Optional)* The window contents width in DIP. Assumes current width if omitted. Must be specified if 'height' is omitted.
:param height: *(Optional)* The window contents height in DIP. Assumes current height if omitted. Must be specified if 'width' is omitted.
'''
params: T_JSON_DICT = dict()
params['windowId'] = window_id.to_json()
if width is not None:
params['width'] = width
if height is not None:
params['height'] = height
cmd_dict: T_JSON_DICT = {
'method': 'Browser.setContentsSize',
'params': params,
}
json = yield cmd_dict
def set_dock_tile(
badge_label: typing.Optional[str] = None,
image: typing.Optional[str] = None
) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
r'''
Set dock tile details, platform-specific.
**EXPERIMENTAL**
:param badge_label: *(Optional)*
:param image: *(Optional)* Png encoded image. (Encoded as a base64 string when passed over JSON)
'''
params: T_JSON_DICT = dict()
if badge_label is not None:
params['badgeLabel'] = badge_label
if image is not None:
params['image'] = image
cmd_dict: T_JSON_DICT = {
'method': 'Browser.setDockTile',
'params': params,
}
json = yield cmd_dict
def execute_browser_command(
command_id: BrowserCommandId
) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
r'''
Invoke custom browser commands used by telemetry.
**EXPERIMENTAL**
:param command_id:
'''
params: T_JSON_DICT = dict()
params['commandId'] = command_id.to_json()
cmd_dict: T_JSON_DICT = {
'method': 'Browser.executeBrowserCommand',
'params': params,
}
json = yield cmd_dict
def add_privacy_sandbox_enrollment_override(
url: str
) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
r'''
Allows a site to use privacy sandbox features that require enrollment
without the site actually being enrolled. Only supported on page targets.
:param url:
'''
params: T_JSON_DICT = dict()
params['url'] = url
cmd_dict: T_JSON_DICT = {
'method': 'Browser.addPrivacySandboxEnrollmentOverride',
'params': params,
}
json = yield cmd_dict
def add_privacy_sandbox_coordinator_key_config(
api: PrivacySandboxAPI,
coordinator_origin: str,
key_config: str,
browser_context_id: typing.Optional[BrowserContextID] = None
) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
r'''
Configures encryption keys used with a given privacy sandbox API to talk
to a trusted coordinator. Since this is intended for test automation only,
coordinatorOrigin must be a .test domain. No existing coordinator
configuration for the origin may exist.
:param api:
:param coordinator_origin:
:param key_config:
:param browser_context_id: *(Optional)* BrowserContext to perform the action in. When omitted, default browser context is used.
'''
params: T_JSON_DICT = dict()
params['api'] = api.to_json()
params['coordinatorOrigin'] = coordinator_origin
params['keyConfig'] = key_config
if browser_context_id is not None:
params['browserContextId'] = browser_context_id.to_json()
cmd_dict: T_JSON_DICT = {
'method': 'Browser.addPrivacySandboxCoordinatorKeyConfig',
'params': params,
}
json = yield cmd_dict
@event_class('Browser.downloadWillBegin')
@dataclass
class DownloadWillBegin:
r'''
**EXPERIMENTAL**
Fired when page is about to start a download.
'''
#: Id of the frame that caused the download to begin.
frame_id: page.FrameId
#: Global unique identifier of the download.
guid: str
#: URL of the resource being downloaded.
url: str
#: Suggested file name of the resource (the actual name of the file saved on disk may differ).
suggested_filename: str
@classmethod
def from_json(cls, json: T_JSON_DICT) -> DownloadWillBegin:
return cls(
frame_id=page.FrameId.from_json(json['frameId']),
guid=str(json['guid']),
url=str(json['url']),
suggested_filename=str(json['suggestedFilename'])
)
@event_class('Browser.downloadProgress')
@dataclass
class DownloadProgress:
r'''
**EXPERIMENTAL**
Fired when download makes progress. Last call has ``done`` == true.
'''
#: Global unique identifier of the download.
guid: str
#: Total expected bytes to download.
total_bytes: float
#: Total bytes received.
received_bytes: float
#: Download status.
state: str
#: If download is "completed", provides the path of the downloaded file.
#: Depending on the platform, it is not guaranteed to be set, nor the file
#: is guaranteed to exist.
file_path: typing.Optional[str]
@classmethod
def from_json(cls, json: T_JSON_DICT) -> DownloadProgress:
return cls(
guid=str(json['guid']),
total_bytes=float(json['totalBytes']),
received_bytes=float(json['receivedBytes']),
state=str(json['state']),
file_path=str(json['filePath']) if 'filePath' in json else None
)