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
|
# File 'lib/puppeteer/emulation_manager.rb', line 13
def emulate_viewport(viewport)
mobile = viewport.mobile?
width = viewport.width
height = viewport.height
device_scale_factor = viewport.device_scale_factor
screen_orientation =
if viewport.landscape?
{ angle: 90, type: 'landscapePrimary' }
else
{ angle: 0, type: 'portraitPrimary' }
end
has_touch = viewport.has_touch?
await_all(
@client.async_send_message('Emulation.setDeviceMetricsOverride',
mobile: mobile,
width: width,
height: height,
deviceScaleFactor: device_scale_factor,
screenOrientation: screen_orientation,
),
@client.async_send_message('Emulation.setTouchEmulationEnabled',
enabled: has_touch,
),
)
reload_needed = @emulating_mobile != mobile || @has_touch != has_touch
@emulating_mobile = mobile
@has_touch = has_touch
reload_needed
end
|