puppeteer-ruby 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/docs/Puppeteer.html +2 -2
  3. data/docs/Puppeteer/AsyncAwaitBehavior.html +1 -1
  4. data/docs/Puppeteer/Browser.html +254 -144
  5. data/docs/Puppeteer/BrowserContext.html +1 -1
  6. data/docs/Puppeteer/BrowserFetcher.html +1 -1
  7. data/docs/Puppeteer/BrowserRunner.html +1 -1
  8. data/docs/Puppeteer/BrowserRunner/BrowserProcess.html +1 -1
  9. data/docs/Puppeteer/CDPSession.html +1 -1
  10. data/docs/Puppeteer/CDPSession/Error.html +1 -1
  11. data/docs/Puppeteer/ConcurrentRubyUtils.html +1 -1
  12. data/docs/Puppeteer/Connection.html +65 -61
  13. data/docs/Puppeteer/Connection/MessageCallback.html +1 -1
  14. data/docs/Puppeteer/Connection/ProtocolError.html +1 -1
  15. data/docs/Puppeteer/Connection/RequestDebugPrinter.html +5 -5
  16. data/docs/Puppeteer/Connection/ResponseDebugPrinter.html +12 -12
  17. data/docs/Puppeteer/ConsoleMessage.html +1 -1
  18. data/docs/Puppeteer/ConsoleMessage/Location.html +1 -1
  19. data/docs/Puppeteer/DOMWorld.html +32 -32
  20. data/docs/Puppeteer/DOMWorld/DetachedError.html +1 -1
  21. data/docs/Puppeteer/DebugPrint.html +1 -1
  22. data/docs/Puppeteer/Device.html +1 -1
  23. data/docs/Puppeteer/Devices.html +1 -1
  24. data/docs/Puppeteer/ElementHandle.html +1 -1
  25. data/docs/Puppeteer/ElementHandle/BoundingBox.html +507 -0
  26. data/docs/Puppeteer/ElementHandle/BoxModel.html +404 -0
  27. data/docs/Puppeteer/ElementHandle/ElementNotFoundError.html +1 -1
  28. data/docs/Puppeteer/ElementHandle/ElementNotVisibleError.html +1 -1
  29. data/docs/Puppeteer/ElementHandle/Point.html +1 -1
  30. data/docs/Puppeteer/ElementHandle/ScrollIntoViewError.html +1 -1
  31. data/docs/Puppeteer/EmulationManager.html +1 -1
  32. data/docs/Puppeteer/EventCallbackable.html +1 -1
  33. data/docs/Puppeteer/EventCallbackable/EventListeners.html +1 -1
  34. data/docs/Puppeteer/ExecutionContext.html +1 -1
  35. data/docs/Puppeteer/ExecutionContext/EvaluationError.html +1 -1
  36. data/docs/Puppeteer/ExecutionContext/JavaScriptExpression.html +1 -1
  37. data/docs/Puppeteer/ExecutionContext/JavaScriptFunction.html +1 -1
  38. data/docs/Puppeteer/FileChooser.html +1 -1
  39. data/docs/Puppeteer/Frame.html +425 -289
  40. data/docs/Puppeteer/FrameManager.html +1 -1
  41. data/docs/Puppeteer/FrameManager/NavigationError.html +1 -1
  42. data/docs/Puppeteer/IfPresent.html +1 -1
  43. data/docs/Puppeteer/JSHandle.html +1 -1
  44. data/docs/Puppeteer/Keyboard.html +1 -1
  45. data/docs/Puppeteer/Keyboard/KeyDefinition.html +1 -1
  46. data/docs/Puppeteer/Keyboard/KeyDescription.html +1 -1
  47. data/docs/Puppeteer/Launcher.html +1 -1
  48. data/docs/Puppeteer/Launcher/Base.html +1 -1
  49. data/docs/Puppeteer/Launcher/Base/ExecutablePathNotFound.html +1 -1
  50. data/docs/Puppeteer/Launcher/BrowserOptions.html +1 -1
  51. data/docs/Puppeteer/Launcher/Chrome.html +1 -1
  52. data/docs/Puppeteer/Launcher/Chrome/DefaultArgs.html +1 -1
  53. data/docs/Puppeteer/Launcher/ChromeArgOptions.html +1 -1
  54. data/docs/Puppeteer/Launcher/LaunchOptions.html +1 -1
  55. data/docs/Puppeteer/LifecycleWatcher.html +1 -1
  56. data/docs/Puppeteer/LifecycleWatcher/ExpectedLifecycle.html +1 -1
  57. data/docs/Puppeteer/LifecycleWatcher/FrameDetachedError.html +1 -1
  58. data/docs/Puppeteer/LifecycleWatcher/TerminatedError.html +1 -1
  59. data/docs/Puppeteer/Mouse.html +31 -41
  60. data/docs/Puppeteer/Mouse/Button.html +1 -1
  61. data/docs/Puppeteer/NetworkManager.html +1 -1
  62. data/docs/Puppeteer/NetworkManager/Credentials.html +1 -1
  63. data/docs/Puppeteer/Page.html +1 -1
  64. data/docs/Puppeteer/Page/FileChooserTimeoutError.html +1 -1
  65. data/docs/Puppeteer/Page/ScreenshotOptions.html +1 -1
  66. data/docs/Puppeteer/Page/ScriptTag.html +1 -1
  67. data/docs/Puppeteer/Page/StyleTag.html +1 -1
  68. data/docs/Puppeteer/Page/TargetCrashedError.html +1 -1
  69. data/docs/Puppeteer/RemoteObject.html +1 -1
  70. data/docs/Puppeteer/Target.html +1 -1
  71. data/docs/Puppeteer/Target/InitializeFailure.html +1 -1
  72. data/docs/Puppeteer/Target/TargetInfo.html +1 -1
  73. data/docs/Puppeteer/TimeoutError.html +1 -1
  74. data/docs/Puppeteer/TimeoutSettings.html +1 -1
  75. data/docs/Puppeteer/TouchScreen.html +1 -1
  76. data/docs/Puppeteer/Viewport.html +1 -1
  77. data/docs/Puppeteer/WaitTask.html +1 -1
  78. data/docs/Puppeteer/WaitTask/TerminatedError.html +1 -1
  79. data/docs/Puppeteer/WaitTask/TimeoutError.html +1 -1
  80. data/docs/Puppeteer/WebSocket.html +1 -1
  81. data/docs/Puppeteer/WebSocket/DriverImpl.html +1 -1
  82. data/docs/Puppeteer/WebSocket/TransportError.html +124 -0
  83. data/docs/Puppeteer/WebSocketTransport.html +1 -1
  84. data/docs/_index.html +5 -12
  85. data/docs/class_list.html +1 -1
  86. data/docs/file.README.html +1 -1
  87. data/docs/index.html +1 -1
  88. data/docs/method_list.html +402 -386
  89. data/docs/top-level-namespace.html +1 -1
  90. data/lib/puppeteer/browser.rb +17 -1
  91. data/lib/puppeteer/connection.rb +13 -1
  92. data/lib/puppeteer/dom_world.rb +7 -6
  93. data/lib/puppeteer/frame.rb +19 -1
  94. data/lib/puppeteer/mouse.rb +3 -8
  95. data/lib/puppeteer/page.rb +1 -1
  96. data/lib/puppeteer/version.rb +1 -1
  97. metadata +5 -2
@@ -116,7 +116,7 @@
116
116
  </div>
117
117
 
118
118
  <div id="footer">
119
- Generated on Fri Jun 12 12:38:32 2020 by
119
+ Generated on Sat Jun 20 17:15:05 2020 by
120
120
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
121
121
  0.9.24 (ruby-2.6.3).
122
122
  </div>
@@ -46,7 +46,7 @@ class Puppeteer::Browser
46
46
  @contexts[context_id] = Puppeteer::BrowserContext.new(@connection, self. context_id)
47
47
  end
48
48
  @targets = {}
49
- @connection.on_event 'Events.CDPSession.Disconnected' do
49
+ @connection.on_event 'Events.Connection.Disconnected' do
50
50
  emit_event 'Events.Browser.Disconnected'
51
51
  end
52
52
  @connection.on_event 'Target.targetCreated', &method(:handle_target_created)
@@ -54,6 +54,22 @@ class Puppeteer::Browser
54
54
  @connection.on_event 'Target.targetInfoChanged', &method(:handle_target_info_changed)
55
55
  end
56
56
 
57
+ EVENT_MAPPINGS = {
58
+ disconnected: 'Events.Browser.Disconnected',
59
+ targetcreated: 'Events.Browser.TargetCreated',
60
+ targetchanged: 'Events.Browser.TargetChanged',
61
+ targetdestroyed: 'Events.Browser.TargetDestroyed',
62
+ }
63
+
64
+ # @param event_name [Symbol] either of :disconnected, :targetcreated, :targetchanged, :targetdestroyed
65
+ def on(event_name, &block)
66
+ unless EVENT_MAPPINGS.has_key?(event_name.to_sym)
67
+ raise ArgumentError.new("Unknown event name: #{event_name}. Known events are #{EVENT_MAPPINGS.keys.join(", ")}")
68
+ end
69
+
70
+ add_event_listener(EVENT_MAPPINGS[event_name.to_sym], &block)
71
+ end
72
+
57
73
  # @return [Puppeteer::BrowserRunner::BrowserProcess]
58
74
  def process
59
75
  @process
@@ -44,7 +44,9 @@ class Puppeteer::Connection
44
44
 
45
45
  @transport = transport
46
46
  @transport.on_message do |data|
47
- async_handle_message(JSON.parse(data))
47
+ message = JSON.parse(data)
48
+ sleep_before_handling_message(message)
49
+ async_handle_message(message)
48
50
  end
49
51
  @transport.on_close do |reason, code|
50
52
  handle_close(reason, code)
@@ -54,6 +56,16 @@ class Puppeteer::Connection
54
56
  @closed = false
55
57
  end
56
58
 
59
+ private def sleep_before_handling_message(message)
60
+ # Puppeteer doesn't handle any Network monitoring responses.
61
+ # So we don't have to sleep.
62
+ return if message['method']&.start_with?('Network.')
63
+
64
+ # For some reasons, sleeping a bit reduces trivial errors...
65
+ # 4ms is an interval of internal shared timer of WebKit.
66
+ sleep 0.004
67
+ end
68
+
57
69
  def self.from_session(session)
58
70
  session.connection
59
71
  end
@@ -97,17 +97,18 @@ class Puppeteer::DOMWorld
97
97
  document.S(selector)
98
98
  end
99
99
 
100
- class DocumentEvaluationError < StandardError; end
101
-
102
100
  private def evaluate_document
103
101
  # sometimes execution_context.evaluate_handle('document') returns null object.
104
102
  # D, [2020-04-24T02:17:51.023631 #220] DEBUG -- : RECV << {"id"=>20, "result"=>{"result"=>{"type"=>"object", "subtype"=>"null", "value"=>nil}}, "sessionId"=>"78E9CF1E14D81294E320E7C20E5CDE06"}
105
103
  # retry if so.
106
- 5.times do
107
- handle = execution_context.evaluate_handle('document')
108
- return handle if handle.is_a?(Puppeteer::ElementHandle)
104
+ Timeout.timeout(3) do
105
+ loop do
106
+ handle = execution_context.evaluate_handle('document')
107
+ return handle if handle.is_a?(Puppeteer::ElementHandle)
108
+ end
109
109
  end
110
- raise DocumentEvaluationError.new("'document' object cannot be evaluated as an Element")
110
+ rescue Timeout::Error
111
+ raise 'Bug of puppeteer-ruby...'
111
112
  end
112
113
 
113
114
  private def document
@@ -1,4 +1,6 @@
1
1
  class Puppeteer::Frame
2
+ using Puppeteer::AsyncAwaitBehavior
3
+
2
4
  # @param {!FrameManager} frameManager
3
5
  # @param {!Puppeteer.CDPSession} client
4
6
  # @param {?Frame} parentFrame
@@ -33,10 +35,17 @@ class Puppeteer::Frame
33
35
 
34
36
  # @param timeout [number|nil]
35
37
  # @param wait_until [string|nil] 'load' | 'domcontentloaded' | 'networkidle0' | 'networkidle2'
36
- def wait_for_navigation(timeout: nil, wait_until: nil)
38
+ private def wait_for_navigation(timeout: nil, wait_until: nil)
37
39
  @frame_manager.wait_for_frame_navigation(self, timeout: timeout, wait_until: wait_until)
38
40
  end
39
41
 
42
+ # @param timeout [number|nil]
43
+ # @param wait_until [string|nil] 'load' | 'domcontentloaded' | 'networkidle0' | 'networkidle2'
44
+ # @return [Future]
45
+ async def async_wait_for_navigation(timeout: nil, wait_until: nil)
46
+ wait_for_navigation(timeout: timeout, wait_until: wait_until)
47
+ end
48
+
40
49
  def execution_context
41
50
  @main_world.execution_context
42
51
  end
@@ -143,6 +152,15 @@ class Puppeteer::Frame
143
152
  @main_world.add_style_tag(style_tag)
144
153
  end
145
154
 
155
+ # @param selector [String]
156
+ # @param delay [Number]
157
+ # @param button [String] "left"|"right"|"middle"
158
+ # @param click_count [Number]
159
+ # @return [Future]
160
+ async def async_click(selector, delay: nil, button: nil, click_count: nil)
161
+ click(selector, delay: delay, button: button, click_count: click_count)
162
+ end
163
+
146
164
  # @param selector [String]
147
165
  # @param delay [Number]
148
166
  # @param button [String] "left"|"right"|"middle"
@@ -61,18 +61,13 @@ class Puppeteer::Mouse
61
61
  # D, [2020-04-15T17:09:47.898422 #88683] DEBUG -- : SEND >> {"sessionId":"0B09EA5E18DEE403E525B3E7FCD7E225","method":"Input.dispatchMouseEvent","params":{"type":"mouseReleased","button":"left","x":0,"y":0,"modifiers":0,"clickCount":1},"id":24}
62
62
  # D, [2020-04-15T17:09:47.899711 #88683] DEBUG -- : SEND >> {"sessionId":"0B09EA5E18DEE403E525B3E7FCD7E225","method":"Input.dispatchMouseEvent","params":{"type":"mousePressed","button":"left","x":0,"y":0,"modifiers":0,"clickCount":1},"id":25}
63
63
  # D, [2020-04-15T17:09:47.900237 #88683] DEBUG -- : SEND >> {"sessionId":"0B09EA5E18DEE403E525B3E7FCD7E225","method":"Input.dispatchMouseEvent","params":{"type":"mouseMoved","button":"left","x":187,"y":283,"modifiers":0},"id":26}
64
- # So we execute move in advance.
64
+ # So we execute them sequential
65
65
  move(x, y)
66
+ down(button: button, click_count: click_count)
66
67
  if delay
67
- down(button: button, click_count: click_count)
68
68
  sleep(delay / 1000.0)
69
- up(button: button, click_count: click_count)
70
- else
71
- await_all(
72
- async_down(button: button, click_count: click_count),
73
- async_up(button: button, click_count: click_count),
74
- )
75
69
  end
70
+ up(button: button, click_count: click_count)
76
71
  end
77
72
 
78
73
  # @param x [number]
@@ -651,7 +651,7 @@ class Puppeteer::Page
651
651
  # @param timeout [number|nil]
652
652
  # @param wait_until [string|nil] 'load' | 'domcontentloaded' | 'networkidle0' | 'networkidle2'
653
653
  private def wait_for_navigation(timeout: nil, wait_until: nil)
654
- main_frame.wait_for_navigation(timeout: timeout, wait_until: wait_until)
654
+ main_frame.send(:wait_for_navigation, timeout: timeout, wait_until: wait_until)
655
655
  end
656
656
 
657
657
  # @param timeout [number|nil]
@@ -1,3 +1,3 @@
1
1
  class Puppeteer
2
- VERSION = '0.0.10'
2
+ VERSION = '0.0.11'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppeteer-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - YusukeIwaki
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-12 00:00:00.000000000 Z
11
+ date: 2020-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -208,6 +208,8 @@ files:
208
208
  - docs/Puppeteer/Device.html
209
209
  - docs/Puppeteer/Devices.html
210
210
  - docs/Puppeteer/ElementHandle.html
211
+ - docs/Puppeteer/ElementHandle/BoundingBox.html
212
+ - docs/Puppeteer/ElementHandle/BoxModel.html
211
213
  - docs/Puppeteer/ElementHandle/ElementNotFoundError.html
212
214
  - docs/Puppeteer/ElementHandle/ElementNotVisibleError.html
213
215
  - docs/Puppeteer/ElementHandle/Point.html
@@ -263,6 +265,7 @@ files:
263
265
  - docs/Puppeteer/WaitTask/TimeoutError.html
264
266
  - docs/Puppeteer/WebSocket.html
265
267
  - docs/Puppeteer/WebSocket/DriverImpl.html
268
+ - docs/Puppeteer/WebSocket/TransportError.html
266
269
  - docs/Puppeteer/WebSocketTransport.html
267
270
  - docs/Puppeteer/WebSocktTransportError.html
268
271
  - docs/_index.html