Sha256: 68e56cbe7be52c5e66a349cb1270b72c6d420c55e20d303eec630971e9b10926

Contents?: true

Size: 1.09 KB

Versions: 11

Compression:

Stored size: 1.09 KB

Contents

class Puppeteer::TouchScreen
  using Puppeteer::AsyncAwaitBehavior

  # @param {Puppeteer.CDPSession} client
  # @param keyboard [Puppeteer::Keyboard]
  def initialize(client, keyboard)
    @client = client
    @keyboard = keyboard
  end

  # @param x [number]
  # @param y [number]
  def tap(x, y)
    # Touches appear to be lost during the first frame after navigation.
    # This waits a frame before sending the tap.
    # @see https://crbug.com/613219
    @client.send_message('Runtime.evaluate',
      expression: 'new Promise(x => requestAnimationFrame(() => requestAnimationFrame(x)))',
      awaitPromise: true,
    )

    touch_points = [
      { x: x.round, y: y.round },
    ]
    @client.send_message('Input.dispatchTouchEvent',
      type: 'touchStart',
      touchPoints: touch_points,
      modifiers: @keyboard.modifiers,
    )
    @client.send_message('Input.dispatchTouchEvent',
      type: 'touchEnd',
      touchPoints: [],
      modifiers: @keyboard.modifiers,
    )
  end

  # @param x [number]
  # @param y [number]
  # @return [Future]
  async def async_tap(x, y)
    tap(x, y)
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
puppeteer-ruby-0.0.13 lib/puppeteer/touch_screen.rb
puppeteer-ruby-0.0.12 lib/puppeteer/touch_screen.rb
puppeteer-ruby-0.0.11 lib/puppeteer/touch_screen.rb
puppeteer-ruby-0.0.10 lib/puppeteer/touch_screen.rb
puppeteer-ruby-0.0.9 lib/puppeteer/touch_screen.rb
puppeteer-ruby-0.0.8 lib/puppeteer/touch_screen.rb
puppeteer-ruby-0.0.6 lib/puppeteer/touch_screen.rb
puppeteer-ruby-0.0.5 lib/puppeteer/touch_screen.rb
puppeteer-ruby-0.0.4 lib/puppeteer/touch_screen.rb
puppeteer-ruby-0.0.3 lib/puppeteer/touch_screen.rb
puppeteer-ruby-0.0.2 lib/puppeteer/touch_screen.rb