Sha256: e128b3ccb6c203feb70f5913a0f5dc6aafa30a28dc203703a717f268cc4b4fff

Contents?: true

Size: 1.25 KB

Versions: 24

Compression:

Stored size: 1.25 KB

Contents

class Puppeteer::EmulationManager
  using Puppeteer::DefineAsyncMethod

  # @param {!Puppeteer.CDPSession} client
  def initialize(client)
    @client = client
    @emulating_mobile = false
    @has_touch = false
  end

  # @param viewport [Puppeteer::Viewport]
  # @return [true|false]
  def emulate_viewport(viewport)
    mobile = viewport.mobile?
    width = viewport.width
    height = viewport.height
    device_scale_factor = viewport.device_scale_factor
    # /** @type {Protocol.Emulation.ScreenOrientation} */
    # const screenOrientation = viewport.isLandscape ? { angle: 90, type: 'landscapePrimary' } : { angle: 0, type: 'portraitPrimary' };
    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 || @hasTouch != has_touch
    @emulating_mobile = mobile
    @has_touch = has_touch
    reload_needed
  end

  define_async_method :async_emulate_viewport
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
puppeteer-ruby-0.32.1 lib/puppeteer/emulation_manager.rb
puppeteer-ruby-0.32.0 lib/puppeteer/emulation_manager.rb
puppeteer-ruby-0.31.6 lib/puppeteer/emulation_manager.rb
puppeteer-ruby-0.31.5 lib/puppeteer/emulation_manager.rb
puppeteer-ruby-0.31.4 lib/puppeteer/emulation_manager.rb
puppeteer-ruby-0.31.3 lib/puppeteer/emulation_manager.rb
puppeteer-ruby-0.31.1 lib/puppeteer/emulation_manager.rb
puppeteer-ruby-0.31.0 lib/puppeteer/emulation_manager.rb
puppeteer-ruby-0.30.0 lib/puppeteer/emulation_manager.rb
puppeteer-ruby-0.29.0 lib/puppeteer/emulation_manager.rb
puppeteer-ruby-0.28.1 lib/puppeteer/emulation_manager.rb
puppeteer-ruby-0.0.27 lib/puppeteer/emulation_manager.rb
puppeteer-ruby-0.0.26 lib/puppeteer/emulation_manager.rb
puppeteer-ruby-0.0.25 lib/puppeteer/emulation_manager.rb
puppeteer-ruby-0.0.23 lib/puppeteer/emulation_manager.rb
puppeteer-ruby-0.0.22 lib/puppeteer/emulation_manager.rb
puppeteer-ruby-0.0.21 lib/puppeteer/emulation_manager.rb
puppeteer-ruby-0.0.20 lib/puppeteer/emulation_manager.rb
puppeteer-ruby-0.0.19 lib/puppeteer/emulation_manager.rb
puppeteer-ruby-0.0.18 lib/puppeteer/emulation_manager.rb