Sha256: 7980f958a073d88985a7acd234b6ee518d63390b87f50f138ad9c6ac7a3271aa

Contents?: true

Size: 1.01 KB

Versions: 67

Compression:

Stored size: 1.01 KB

Contents

class Puppeteer::TouchScreen
  using Puppeteer::DefineAsyncMethod

  # @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

  define_async_method :async_tap
end

Version data entries

67 entries across 67 versions & 1 rubygems

Version Path
puppeteer-ruby-0.45.6 lib/puppeteer/touch_screen.rb
puppeteer-ruby-0.45.5 lib/puppeteer/touch_screen.rb
puppeteer-ruby-0.45.4 lib/puppeteer/touch_screen.rb
puppeteer-ruby-0.45.3 lib/puppeteer/touch_screen.rb
puppeteer-ruby-0.45.2 lib/puppeteer/touch_screen.rb
puppeteer-ruby-0.45.2.alpha2 lib/puppeteer/touch_screen.rb
puppeteer-ruby-0.45.2.alpha1 lib/puppeteer/touch_screen.rb
puppeteer-ruby-0.45.1 lib/puppeteer/touch_screen.rb
puppeteer-ruby-0.45.0 lib/puppeteer/touch_screen.rb
puppeteer-ruby-0.44.3 lib/puppeteer/touch_screen.rb
puppeteer-ruby-0.44.2 lib/puppeteer/touch_screen.rb
puppeteer-ruby-0.44.1 lib/puppeteer/touch_screen.rb
puppeteer-ruby-0.44.0 lib/puppeteer/touch_screen.rb
puppeteer-ruby-0.43.1 lib/puppeteer/touch_screen.rb
puppeteer-ruby-0.43.0 lib/puppeteer/touch_screen.rb
puppeteer-ruby-0.42.0 lib/puppeteer/touch_screen.rb
puppeteer-ruby-0.41.0 lib/puppeteer/touch_screen.rb
puppeteer-ruby-0.40.7 lib/puppeteer/touch_screen.rb
puppeteer-ruby-0.40.6 lib/puppeteer/touch_screen.rb
puppeteer-ruby-0.40.5 lib/puppeteer/touch_screen.rb