Class: Puppeteer::EmulationManager
- Inherits:
-
Object
- Object
- Puppeteer::EmulationManager
- Defined in:
- lib/puppeteer/emulation_manager.rb
Instance Method Summary collapse
- #emulate_viewport(viewport) ⇒ true|false
-
#initialize(client) ⇒ EmulationManager
constructor
A new instance of EmulationManager.
Constructor Details
#initialize(client) ⇒ EmulationManager
Returns a new instance of EmulationManager.
5 6 7 8 9 |
# File 'lib/puppeteer/emulation_manager.rb', line 5 def initialize(client) @client = client @emulating_mobile = false @has_touch = false end |
Instance Method Details
#emulate_viewport(viewport) ⇒ true|false
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 () mobile = .mobile? width = .width height = .height device_scale_factor = .device_scale_factor screen_orientation = if .landscape? { angle: 90, type: 'landscapePrimary' } else { angle: 0, type: 'portraitPrimary' } end has_touch = .has_touch? await_all( @client.('Emulation.setDeviceMetricsOverride', mobile: mobile, width: width, height: height, deviceScaleFactor: device_scale_factor, screenOrientation: screen_orientation, ), @client.('Emulation.setTouchEmulationEnabled', enabled: has_touch, ), ) reload_needed = @emulating_mobile != mobile || @has_touch != has_touch @emulating_mobile = mobile @has_touch = has_touch reload_needed end |