Class: Puppeteer::TouchScreen

Inherits:
Object
  • Object
show all
Defined in:
lib/puppeteer/touch_screen.rb

Instance Method Summary collapse

Constructor Details

#initialize(client, keyboard) ⇒ TouchScreen

Returns a new instance of TouchScreen.

Parameters:



6
7
8
9
# File 'lib/puppeteer/touch_screen.rb', line 6

def initialize(client, keyboard)
  @client = client
  @keyboard = keyboard
end

Instance Method Details

#tap(x, y) ⇒ Object

Parameters:

  • x (number)
  • y (number)


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/puppeteer/touch_screen.rb', line 13

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