Emulation
set_viewport
Overrides device screen dimensions and emulates viewport. When :mobile is
true, this also enables touch emulation (navigator.maxTouchPoints,
ontouchstart) alongside the mobile viewport metrics.
- options
Hash- :width
Integer, viewport width.0by default - :height
Integer, viewport height.0by default - :scale_factor
Float, device scale factor.0by default - :mobile
Boolean, whether to emulate mobile device and enable touch.falseby default
- :width
page.set_viewport(width: 1000, height: 600, scale_factor: 3)
:width, :height, and :scale_factor all default to 0, which per the
DevTools protocol
disables overriding that particular value. This means mobile: can be
enabled on its own, at the page's current size, without specifying a device
size preset:
page.set_viewport(mobile: true)