-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemulation.v
90 lines (78 loc) · 2 KB
/
emulation.v
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
module cdv
import x.json2 as json
@[params]
pub struct EmulationViewportParams {
pub:
width int
height int
device_scale_factor f64
is_mobile bool
}
pub fn (mut page Page) set_viewport(params EmulationViewportParams) {
page.send_or_noop('Emulation.setDeviceMetricsOverride',
params: {
'width': params.width
'height': params.height
'deviceScaleFactor': params.device_scale_factor
'mobile': params.is_mobile
}
)
}
pub fn (mut page Page) clear_viewport() {
page.send_or_noop('Emulation.clearDeviceMetricsOverride')
}
@[params]
pub struct UserAgentParams {
pub:
accept_language ?string
platform ?string
metadata ?map[string]json.Any
}
pub fn (mut page Page) set_user_agent(name string, params UserAgentParams) {
mut obj := map[string]json.Any{}
obj['userAgent'] = name
if accept_language := params.accept_language {
obj['acceptLanguage'] = accept_language
}
if platform := params.platform {
obj['platform'] = platform
}
if metadata := params.metadata {
obj['userAgentMetadata'] = metadata
}
page.send_or_noop('Emulation.setUserAgentOverride', params: obj)
}
pub fn (mut page Page) set_timezone(timezone_id string) {
page.send_or_noop('Emulation.setTimezoneOverride',
params: {
'timezoneId': timezone_id
}
)
}
@[params]
pub struct MediaParams {
pub:
features ?[]json.Any
}
pub fn (mut page Page) set_media(media string, params MediaParams) {
mut obj := map[string]json.Any{}
obj['media'] = media
if features := params.features {
obj['features'] = features
}
page.send_or_noop('Emulation.setEmulatedMedia', params: obj)
}
@[params]
pub struct GeolocationParams {
pub:
latitude ?f64
longitude ?f64
accuracy ?f64
}
pub fn (mut page Page) set_geolocation(params GeolocationParams) {
obj := page.struct_to_json_any(params).as_map()
page.send_or_noop('Emulation.setEmulatedMedia', params: obj)
}
pub fn (mut page Page) clear_geolocation() {
page.send_or_noop('Emulation.clearGeolocationOverride')
}