-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathemulation.py
More file actions
1779 lines (1455 loc) · 56 KB
/
emulation.py
File metadata and controls
1779 lines (1455 loc) · 56 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
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# 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: Emulation
from __future__ import annotations
from cdp.util import event_class, T_JSON_DICT
from dataclasses import dataclass
import enum
import typing
from . import dom
from . import network
from . import page
from deprecated.sphinx import deprecated # type: ignore
@dataclass
class SafeAreaInsets:
#: Overrides safe-area-inset-top.
top: typing.Optional[int] = None
#: Overrides safe-area-max-inset-top.
top_max: typing.Optional[int] = None
#: Overrides safe-area-inset-left.
left: typing.Optional[int] = None
#: Overrides safe-area-max-inset-left.
left_max: typing.Optional[int] = None
#: Overrides safe-area-inset-bottom.
bottom: typing.Optional[int] = None
#: Overrides safe-area-max-inset-bottom.
bottom_max: typing.Optional[int] = None
#: Overrides safe-area-inset-right.
right: typing.Optional[int] = None
#: Overrides safe-area-max-inset-right.
right_max: typing.Optional[int] = None
def to_json(self) -> T_JSON_DICT:
json: T_JSON_DICT = dict()
if self.top is not None:
json['top'] = self.top
if self.top_max is not None:
json['topMax'] = self.top_max
if self.left is not None:
json['left'] = self.left
if self.left_max is not None:
json['leftMax'] = self.left_max
if self.bottom is not None:
json['bottom'] = self.bottom
if self.bottom_max is not None:
json['bottomMax'] = self.bottom_max
if self.right is not None:
json['right'] = self.right
if self.right_max is not None:
json['rightMax'] = self.right_max
return json
@classmethod
def from_json(cls, json: T_JSON_DICT) -> SafeAreaInsets:
return cls(
top=int(json['top']) if 'top' in json else None,
top_max=int(json['topMax']) if 'topMax' in json else None,
left=int(json['left']) if 'left' in json else None,
left_max=int(json['leftMax']) if 'leftMax' in json else None,
bottom=int(json['bottom']) if 'bottom' in json else None,
bottom_max=int(json['bottomMax']) if 'bottomMax' in json else None,
right=int(json['right']) if 'right' in json else None,
right_max=int(json['rightMax']) if 'rightMax' in json else None,
)
@dataclass
class ScreenOrientation:
r'''
Screen orientation.
'''
#: Orientation type.
type_: str
#: Orientation angle.
angle: int
def to_json(self) -> T_JSON_DICT:
json: T_JSON_DICT = dict()
json['type'] = self.type_
json['angle'] = self.angle
return json
@classmethod
def from_json(cls, json: T_JSON_DICT) -> ScreenOrientation:
return cls(
type_=str(json['type']),
angle=int(json['angle']),
)
@dataclass
class DisplayFeature:
#: Orientation of a display feature in relation to screen
orientation: str
#: The offset from the screen origin in either the x (for vertical
#: orientation) or y (for horizontal orientation) direction.
offset: int
#: A display feature may mask content such that it is not physically
#: displayed - this length along with the offset describes this area.
#: A display feature that only splits content will have a 0 mask_length.
mask_length: int
def to_json(self) -> T_JSON_DICT:
json: T_JSON_DICT = dict()
json['orientation'] = self.orientation
json['offset'] = self.offset
json['maskLength'] = self.mask_length
return json
@classmethod
def from_json(cls, json: T_JSON_DICT) -> DisplayFeature:
return cls(
orientation=str(json['orientation']),
offset=int(json['offset']),
mask_length=int(json['maskLength']),
)
@dataclass
class DevicePosture:
#: Current posture of the device
type_: str
def to_json(self) -> T_JSON_DICT:
json: T_JSON_DICT = dict()
json['type'] = self.type_
return json
@classmethod
def from_json(cls, json: T_JSON_DICT) -> DevicePosture:
return cls(
type_=str(json['type']),
)
@dataclass
class MediaFeature:
name: str
value: str
def to_json(self) -> T_JSON_DICT:
json: T_JSON_DICT = dict()
json['name'] = self.name
json['value'] = self.value
return json
@classmethod
def from_json(cls, json: T_JSON_DICT) -> MediaFeature:
return cls(
name=str(json['name']),
value=str(json['value']),
)
class VirtualTimePolicy(enum.Enum):
r'''
advance: If the scheduler runs out of immediate work, the virtual time base may fast forward to
allow the next delayed task (if any) to run; pause: The virtual time base may not advance;
pauseIfNetworkFetchesPending: The virtual time base may not advance if there are any pending
resource fetches.
'''
ADVANCE = "advance"
PAUSE = "pause"
PAUSE_IF_NETWORK_FETCHES_PENDING = "pauseIfNetworkFetchesPending"
def to_json(self) -> str:
return self.value
@classmethod
def from_json(cls, json: str) -> VirtualTimePolicy:
return cls(json)
@dataclass
class UserAgentBrandVersion:
r'''
Used to specify User Agent Client Hints to emulate. See https://wicg.github.io/ua-client-hints
'''
brand: str
version: str
def to_json(self) -> T_JSON_DICT:
json: T_JSON_DICT = dict()
json['brand'] = self.brand
json['version'] = self.version
return json
@classmethod
def from_json(cls, json: T_JSON_DICT) -> UserAgentBrandVersion:
return cls(
brand=str(json['brand']),
version=str(json['version']),
)
@dataclass
class UserAgentMetadata:
r'''
Used to specify User Agent Client Hints to emulate. See https://wicg.github.io/ua-client-hints
Missing optional values will be filled in by the target with what it would normally use.
'''
platform: str
platform_version: str
architecture: str
model: str
mobile: bool
#: Brands appearing in Sec-CH-UA.
brands: typing.Optional[typing.List[UserAgentBrandVersion]] = None
#: Brands appearing in Sec-CH-UA-Full-Version-List.
full_version_list: typing.Optional[typing.List[UserAgentBrandVersion]] = None
full_version: typing.Optional[str] = None
bitness: typing.Optional[str] = None
wow64: typing.Optional[bool] = None
#: Used to specify User Agent form-factor values.
#: See https://wicg.github.io/ua-client-hints/#sec-ch-ua-form-factors
form_factors: typing.Optional[typing.List[str]] = None
def to_json(self) -> T_JSON_DICT:
json: T_JSON_DICT = dict()
json['platform'] = self.platform
json['platformVersion'] = self.platform_version
json['architecture'] = self.architecture
json['model'] = self.model
json['mobile'] = self.mobile
if self.brands is not None:
json['brands'] = [i.to_json() for i in self.brands]
if self.full_version_list is not None:
json['fullVersionList'] = [i.to_json() for i in self.full_version_list]
if self.full_version is not None:
json['fullVersion'] = self.full_version
if self.bitness is not None:
json['bitness'] = self.bitness
if self.wow64 is not None:
json['wow64'] = self.wow64
if self.form_factors is not None:
json['formFactors'] = [i for i in self.form_factors]
return json
@classmethod
def from_json(cls, json: T_JSON_DICT) -> UserAgentMetadata:
return cls(
platform=str(json['platform']),
platform_version=str(json['platformVersion']),
architecture=str(json['architecture']),
model=str(json['model']),
mobile=bool(json['mobile']),
brands=[UserAgentBrandVersion.from_json(i) for i in json['brands']] if 'brands' in json else None,
full_version_list=[UserAgentBrandVersion.from_json(i) for i in json['fullVersionList']] if 'fullVersionList' in json else None,
full_version=str(json['fullVersion']) if 'fullVersion' in json else None,
bitness=str(json['bitness']) if 'bitness' in json else None,
wow64=bool(json['wow64']) if 'wow64' in json else None,
form_factors=[str(i) for i in json['formFactors']] if 'formFactors' in json else None,
)
class SensorType(enum.Enum):
r'''
Used to specify sensor types to emulate.
See https://w3c.github.io/sensors/#automation for more information.
'''
ABSOLUTE_ORIENTATION = "absolute-orientation"
ACCELEROMETER = "accelerometer"
AMBIENT_LIGHT = "ambient-light"
GRAVITY = "gravity"
GYROSCOPE = "gyroscope"
LINEAR_ACCELERATION = "linear-acceleration"
MAGNETOMETER = "magnetometer"
RELATIVE_ORIENTATION = "relative-orientation"
def to_json(self) -> str:
return self.value
@classmethod
def from_json(cls, json: str) -> SensorType:
return cls(json)
@dataclass
class SensorMetadata:
available: typing.Optional[bool] = None
minimum_frequency: typing.Optional[float] = None
maximum_frequency: typing.Optional[float] = None
def to_json(self) -> T_JSON_DICT:
json: T_JSON_DICT = dict()
if self.available is not None:
json['available'] = self.available
if self.minimum_frequency is not None:
json['minimumFrequency'] = self.minimum_frequency
if self.maximum_frequency is not None:
json['maximumFrequency'] = self.maximum_frequency
return json
@classmethod
def from_json(cls, json: T_JSON_DICT) -> SensorMetadata:
return cls(
available=bool(json['available']) if 'available' in json else None,
minimum_frequency=float(json['minimumFrequency']) if 'minimumFrequency' in json else None,
maximum_frequency=float(json['maximumFrequency']) if 'maximumFrequency' in json else None,
)
@dataclass
class SensorReadingSingle:
value: float
def to_json(self) -> T_JSON_DICT:
json: T_JSON_DICT = dict()
json['value'] = self.value
return json
@classmethod
def from_json(cls, json: T_JSON_DICT) -> SensorReadingSingle:
return cls(
value=float(json['value']),
)
@dataclass
class SensorReadingXYZ:
x: float
y: float
z: float
def to_json(self) -> T_JSON_DICT:
json: T_JSON_DICT = dict()
json['x'] = self.x
json['y'] = self.y
json['z'] = self.z
return json
@classmethod
def from_json(cls, json: T_JSON_DICT) -> SensorReadingXYZ:
return cls(
x=float(json['x']),
y=float(json['y']),
z=float(json['z']),
)
@dataclass
class SensorReadingQuaternion:
x: float
y: float
z: float
w: float
def to_json(self) -> T_JSON_DICT:
json: T_JSON_DICT = dict()
json['x'] = self.x
json['y'] = self.y
json['z'] = self.z
json['w'] = self.w
return json
@classmethod
def from_json(cls, json: T_JSON_DICT) -> SensorReadingQuaternion:
return cls(
x=float(json['x']),
y=float(json['y']),
z=float(json['z']),
w=float(json['w']),
)
@dataclass
class SensorReading:
single: typing.Optional[SensorReadingSingle] = None
xyz: typing.Optional[SensorReadingXYZ] = None
quaternion: typing.Optional[SensorReadingQuaternion] = None
def to_json(self) -> T_JSON_DICT:
json: T_JSON_DICT = dict()
if self.single is not None:
json['single'] = self.single.to_json()
if self.xyz is not None:
json['xyz'] = self.xyz.to_json()
if self.quaternion is not None:
json['quaternion'] = self.quaternion.to_json()
return json
@classmethod
def from_json(cls, json: T_JSON_DICT) -> SensorReading:
return cls(
single=SensorReadingSingle.from_json(json['single']) if 'single' in json else None,
xyz=SensorReadingXYZ.from_json(json['xyz']) if 'xyz' in json else None,
quaternion=SensorReadingQuaternion.from_json(json['quaternion']) if 'quaternion' in json else None,
)
class PressureSource(enum.Enum):
CPU = "cpu"
def to_json(self) -> str:
return self.value
@classmethod
def from_json(cls, json: str) -> PressureSource:
return cls(json)
class PressureState(enum.Enum):
NOMINAL = "nominal"
FAIR = "fair"
SERIOUS = "serious"
CRITICAL = "critical"
def to_json(self) -> str:
return self.value
@classmethod
def from_json(cls, json: str) -> PressureState:
return cls(json)
@dataclass
class PressureMetadata:
available: typing.Optional[bool] = None
def to_json(self) -> T_JSON_DICT:
json: T_JSON_DICT = dict()
if self.available is not None:
json['available'] = self.available
return json
@classmethod
def from_json(cls, json: T_JSON_DICT) -> PressureMetadata:
return cls(
available=bool(json['available']) if 'available' in json else None,
)
@dataclass
class WorkAreaInsets:
#: Work area top inset in pixels. Default is 0;
top: typing.Optional[int] = None
#: Work area left inset in pixels. Default is 0;
left: typing.Optional[int] = None
#: Work area bottom inset in pixels. Default is 0;
bottom: typing.Optional[int] = None
#: Work area right inset in pixels. Default is 0;
right: typing.Optional[int] = None
def to_json(self) -> T_JSON_DICT:
json: T_JSON_DICT = dict()
if self.top is not None:
json['top'] = self.top
if self.left is not None:
json['left'] = self.left
if self.bottom is not None:
json['bottom'] = self.bottom
if self.right is not None:
json['right'] = self.right
return json
@classmethod
def from_json(cls, json: T_JSON_DICT) -> WorkAreaInsets:
return cls(
top=int(json['top']) if 'top' in json else None,
left=int(json['left']) if 'left' in json else None,
bottom=int(json['bottom']) if 'bottom' in json else None,
right=int(json['right']) if 'right' in json else None,
)
class ScreenId(str):
def to_json(self) -> str:
return self
@classmethod
def from_json(cls, json: str) -> ScreenId:
return cls(json)
def __repr__(self):
return 'ScreenId({})'.format(super().__repr__())
@dataclass
class ScreenInfo:
r'''
Screen information similar to the one returned by window.getScreenDetails() method,
see https://w3c.github.io/window-management/#screendetailed.
'''
#: Offset of the left edge of the screen.
left: int
#: Offset of the top edge of the screen.
top: int
#: Width of the screen.
width: int
#: Height of the screen.
height: int
#: Offset of the left edge of the available screen area.
avail_left: int
#: Offset of the top edge of the available screen area.
avail_top: int
#: Width of the available screen area.
avail_width: int
#: Height of the available screen area.
avail_height: int
#: Specifies the screen's device pixel ratio.
device_pixel_ratio: float
#: Specifies the screen's orientation.
orientation: ScreenOrientation
#: Specifies the screen's color depth in bits.
color_depth: int
#: Indicates whether the device has multiple screens.
is_extended: bool
#: Indicates whether the screen is internal to the device or external, attached to the device.
is_internal: bool
#: Indicates whether the screen is set as the the operating system primary screen.
is_primary: bool
#: Specifies the descriptive label for the screen.
label: str
#: Specifies the unique identifier of the screen.
id_: ScreenId
def to_json(self) -> T_JSON_DICT:
json: T_JSON_DICT = dict()
json['left'] = self.left
json['top'] = self.top
json['width'] = self.width
json['height'] = self.height
json['availLeft'] = self.avail_left
json['availTop'] = self.avail_top
json['availWidth'] = self.avail_width
json['availHeight'] = self.avail_height
json['devicePixelRatio'] = self.device_pixel_ratio
json['orientation'] = self.orientation.to_json()
json['colorDepth'] = self.color_depth
json['isExtended'] = self.is_extended
json['isInternal'] = self.is_internal
json['isPrimary'] = self.is_primary
json['label'] = self.label
json['id'] = self.id_.to_json()
return json
@classmethod
def from_json(cls, json: T_JSON_DICT) -> ScreenInfo:
return cls(
left=int(json['left']),
top=int(json['top']),
width=int(json['width']),
height=int(json['height']),
avail_left=int(json['availLeft']),
avail_top=int(json['availTop']),
avail_width=int(json['availWidth']),
avail_height=int(json['availHeight']),
device_pixel_ratio=float(json['devicePixelRatio']),
orientation=ScreenOrientation.from_json(json['orientation']),
color_depth=int(json['colorDepth']),
is_extended=bool(json['isExtended']),
is_internal=bool(json['isInternal']),
is_primary=bool(json['isPrimary']),
label=str(json['label']),
id_=ScreenId.from_json(json['id']),
)
class DisabledImageType(enum.Enum):
r'''
Enum of image types that can be disabled.
'''
AVIF = "avif"
JXL = "jxl"
WEBP = "webp"
def to_json(self) -> str:
return self.value
@classmethod
def from_json(cls, json: str) -> DisabledImageType:
return cls(json)
@deprecated(version="1.3")
def can_emulate() -> typing.Generator[T_JSON_DICT,T_JSON_DICT,bool]:
r'''
Tells whether emulation is supported.
.. deprecated:: 1.3
:returns: True if emulation is supported.
'''
cmd_dict: T_JSON_DICT = {
'method': 'Emulation.canEmulate',
}
json = yield cmd_dict
return bool(json['result'])
def clear_device_metrics_override() -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
r'''
Clears the overridden device metrics.
'''
cmd_dict: T_JSON_DICT = {
'method': 'Emulation.clearDeviceMetricsOverride',
}
json = yield cmd_dict
def clear_geolocation_override() -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
r'''
Clears the overridden Geolocation Position and Error.
'''
cmd_dict: T_JSON_DICT = {
'method': 'Emulation.clearGeolocationOverride',
}
json = yield cmd_dict
def reset_page_scale_factor() -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
r'''
Requests that page scale factor is reset to initial values.
**EXPERIMENTAL**
'''
cmd_dict: T_JSON_DICT = {
'method': 'Emulation.resetPageScaleFactor',
}
json = yield cmd_dict
def set_focus_emulation_enabled(
enabled: bool
) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
r'''
Enables or disables simulating a focused and active page.
**EXPERIMENTAL**
:param enabled: Whether to enable to disable focus emulation.
'''
params: T_JSON_DICT = dict()
params['enabled'] = enabled
cmd_dict: T_JSON_DICT = {
'method': 'Emulation.setFocusEmulationEnabled',
'params': params,
}
json = yield cmd_dict
def set_auto_dark_mode_override(
enabled: typing.Optional[bool] = None
) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
r'''
Automatically render all web contents using a dark theme.
**EXPERIMENTAL**
:param enabled: *(Optional)* Whether to enable or disable automatic dark mode. If not specified, any existing override will be cleared.
'''
params: T_JSON_DICT = dict()
if enabled is not None:
params['enabled'] = enabled
cmd_dict: T_JSON_DICT = {
'method': 'Emulation.setAutoDarkModeOverride',
'params': params,
}
json = yield cmd_dict
def set_cpu_throttling_rate(
rate: float
) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
r'''
Enables CPU throttling to emulate slow CPUs.
:param rate: Throttling rate as a slowdown factor (1 is no throttle, 2 is 2x slowdown, etc).
'''
params: T_JSON_DICT = dict()
params['rate'] = rate
cmd_dict: T_JSON_DICT = {
'method': 'Emulation.setCPUThrottlingRate',
'params': params,
}
json = yield cmd_dict
def set_default_background_color_override(
color: typing.Optional[dom.RGBA] = None
) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
r'''
Sets or clears an override of the default background color of the frame. This override is used
if the content does not specify one.
:param color: *(Optional)* RGBA of the default background color. If not specified, any existing override will be cleared.
'''
params: T_JSON_DICT = dict()
if color is not None:
params['color'] = color.to_json()
cmd_dict: T_JSON_DICT = {
'method': 'Emulation.setDefaultBackgroundColorOverride',
'params': params,
}
json = yield cmd_dict
def set_safe_area_insets_override(
insets: SafeAreaInsets
) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
r'''
Overrides the values for env(safe-area-inset-*) and env(safe-area-max-inset-*). Unset values will cause the
respective variables to be undefined, even if previously overridden.
**EXPERIMENTAL**
:param insets:
'''
params: T_JSON_DICT = dict()
params['insets'] = insets.to_json()
cmd_dict: T_JSON_DICT = {
'method': 'Emulation.setSafeAreaInsetsOverride',
'params': params,
}
json = yield cmd_dict
def set_device_metrics_override(
width: int,
height: int,
device_scale_factor: float,
mobile: bool,
scale: typing.Optional[float] = None,
screen_width: typing.Optional[int] = None,
screen_height: typing.Optional[int] = None,
position_x: typing.Optional[int] = None,
position_y: typing.Optional[int] = None,
dont_set_visible_size: typing.Optional[bool] = None,
screen_orientation: typing.Optional[ScreenOrientation] = None,
viewport: typing.Optional[page.Viewport] = None,
display_feature: typing.Optional[DisplayFeature] = None,
device_posture: typing.Optional[DevicePosture] = None,
scrollbar_type: typing.Optional[str] = None,
screen_orientation_lock_emulation: typing.Optional[bool] = None
) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
r'''
Overrides the values of device screen dimensions (window.screen.width, window.screen.height,
window.innerWidth, window.innerHeight, and "device-width"/"device-height"-related CSS media
query results).
:param width: Overriding width value in pixels (minimum 0, maximum 10000000). 0 disables the override.
:param height: Overriding height value in pixels (minimum 0, maximum 10000000). 0 disables the override.
:param device_scale_factor: Overriding device scale factor value. 0 disables the override.
:param mobile: Whether to emulate mobile device. This includes viewport meta tag, overlay scrollbars, text autosizing and more.
:param scale: **(EXPERIMENTAL)** *(Optional)* Scale to apply to resulting view image.
:param screen_width: **(EXPERIMENTAL)** *(Optional)* Overriding screen width value in pixels (minimum 0, maximum 10000000).
:param screen_height: **(EXPERIMENTAL)** *(Optional)* Overriding screen height value in pixels (minimum 0, maximum 10000000).
:param position_x: **(EXPERIMENTAL)** *(Optional)* Overriding view X position on screen in pixels (minimum 0, maximum 10000000).
:param position_y: **(EXPERIMENTAL)** *(Optional)* Overriding view Y position on screen in pixels (minimum 0, maximum 10000000).
:param dont_set_visible_size: **(EXPERIMENTAL)** *(Optional)* Do not set visible view size, rely upon explicit setVisibleSize call.
:param screen_orientation: *(Optional)* Screen orientation override.
:param viewport: **(EXPERIMENTAL)** *(Optional)* If set, the visible area of the page will be overridden to this viewport. This viewport change is not observed by the page, e.g. viewport-relative elements do not change positions.
:param display_feature: **(DEPRECATED)** **(EXPERIMENTAL)** *(Optional)* If set, the display feature of a multi-segment screen. If not set, multi-segment support is turned-off. Deprecated, use Emulation.setDisplayFeaturesOverride.
:param device_posture: **(DEPRECATED)** **(EXPERIMENTAL)** *(Optional)* If set, the posture of a foldable device. If not set the posture is set to continuous. Deprecated, use Emulation.setDevicePostureOverride.
:param scrollbar_type: **(EXPERIMENTAL)** *(Optional)* Scrollbar type. Default: ```default```.
:param screen_orientation_lock_emulation: **(EXPERIMENTAL)** *(Optional)* If set to true, enables screen orientation lock emulation, which intercepts screen.orientation.lock() calls from the page and reports orientation changes via screenOrientationLockChanged events. This is useful for emulating mobile device orientation lock behavior in responsive design mode.
'''
params: T_JSON_DICT = dict()
params['width'] = width
params['height'] = height
params['deviceScaleFactor'] = device_scale_factor
params['mobile'] = mobile
if scale is not None:
params['scale'] = scale
if screen_width is not None:
params['screenWidth'] = screen_width
if screen_height is not None:
params['screenHeight'] = screen_height
if position_x is not None:
params['positionX'] = position_x
if position_y is not None:
params['positionY'] = position_y
if dont_set_visible_size is not None:
params['dontSetVisibleSize'] = dont_set_visible_size
if screen_orientation is not None:
params['screenOrientation'] = screen_orientation.to_json()
if viewport is not None:
params['viewport'] = viewport.to_json()
if display_feature is not None:
params['displayFeature'] = display_feature.to_json()
if device_posture is not None:
params['devicePosture'] = device_posture.to_json()
if scrollbar_type is not None:
params['scrollbarType'] = scrollbar_type
if screen_orientation_lock_emulation is not None:
params['screenOrientationLockEmulation'] = screen_orientation_lock_emulation
cmd_dict: T_JSON_DICT = {
'method': 'Emulation.setDeviceMetricsOverride',
'params': params,
}
json = yield cmd_dict
def set_device_posture_override(
posture: DevicePosture
) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
r'''
Start reporting the given posture value to the Device Posture API.
This override can also be set in setDeviceMetricsOverride().
**EXPERIMENTAL**
:param posture:
'''
params: T_JSON_DICT = dict()
params['posture'] = posture.to_json()
cmd_dict: T_JSON_DICT = {
'method': 'Emulation.setDevicePostureOverride',
'params': params,
}
json = yield cmd_dict
def clear_device_posture_override() -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
r'''
Clears a device posture override set with either setDeviceMetricsOverride()
or setDevicePostureOverride() and starts using posture information from the
platform again.
Does nothing if no override is set.
**EXPERIMENTAL**
'''
cmd_dict: T_JSON_DICT = {
'method': 'Emulation.clearDevicePostureOverride',
}
json = yield cmd_dict
def set_display_features_override(
features: typing.List[DisplayFeature]
) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
r'''
Start using the given display features to pupulate the Viewport Segments API.
This override can also be set in setDeviceMetricsOverride().
**EXPERIMENTAL**
:param features:
'''
params: T_JSON_DICT = dict()
params['features'] = [i.to_json() for i in features]
cmd_dict: T_JSON_DICT = {
'method': 'Emulation.setDisplayFeaturesOverride',
'params': params,
}
json = yield cmd_dict
def clear_display_features_override() -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
r'''
Clears the display features override set with either setDeviceMetricsOverride()
or setDisplayFeaturesOverride() and starts using display features from the
platform again.
Does nothing if no override is set.
**EXPERIMENTAL**
'''
cmd_dict: T_JSON_DICT = {
'method': 'Emulation.clearDisplayFeaturesOverride',
}
json = yield cmd_dict
def set_scrollbars_hidden(
hidden: bool
) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
r'''
**EXPERIMENTAL**
:param hidden: Whether scrollbars should be always hidden.
'''
params: T_JSON_DICT = dict()
params['hidden'] = hidden
cmd_dict: T_JSON_DICT = {
'method': 'Emulation.setScrollbarsHidden',
'params': params,
}
json = yield cmd_dict
def set_document_cookie_disabled(
disabled: bool
) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
r'''
**EXPERIMENTAL**
:param disabled: Whether document.coookie API should be disabled.
'''
params: T_JSON_DICT = dict()
params['disabled'] = disabled
cmd_dict: T_JSON_DICT = {
'method': 'Emulation.setDocumentCookieDisabled',
'params': params,
}
json = yield cmd_dict
def set_emit_touch_events_for_mouse(
enabled: bool,
configuration: typing.Optional[str] = None
) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
r'''
**EXPERIMENTAL**
:param enabled: Whether touch emulation based on mouse input should be enabled.
:param configuration: *(Optional)* Touch/gesture events configuration. Default: current platform.
'''
params: T_JSON_DICT = dict()
params['enabled'] = enabled
if configuration is not None:
params['configuration'] = configuration
cmd_dict: T_JSON_DICT = {
'method': 'Emulation.setEmitTouchEventsForMouse',
'params': params,
}
json = yield cmd_dict
def set_emulated_media(
media: typing.Optional[str] = None,
features: typing.Optional[typing.List[MediaFeature]] = None
) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
r'''
Emulates the given media type or media feature for CSS media queries.
:param media: *(Optional)* Media type to emulate. Empty string disables the override.
:param features: *(Optional)* Media features to emulate.
'''
params: T_JSON_DICT = dict()
if media is not None:
params['media'] = media
if features is not None:
params['features'] = [i.to_json() for i in features]
cmd_dict: T_JSON_DICT = {
'method': 'Emulation.setEmulatedMedia',
'params': params,
}
json = yield cmd_dict