puppeteer-ruby 0.0.13 → 0.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +0 -12
  3. data/.github/workflows/docs.yml +45 -0
  4. data/.github/workflows/reviewdog.yml +15 -0
  5. data/README.md +52 -1
  6. data/lib/puppeteer.rb +1 -1
  7. data/lib/puppeteer/browser.rb +17 -25
  8. data/lib/puppeteer/cdp_session.rb +3 -19
  9. data/lib/puppeteer/concurrent_ruby_utils.rb +6 -0
  10. data/lib/puppeteer/connection.rb +3 -15
  11. data/lib/puppeteer/define_async_method.rb +23 -0
  12. data/lib/puppeteer/dom_world.rb +6 -21
  13. data/lib/puppeteer/element_handle.rb +15 -44
  14. data/lib/puppeteer/emulation_manager.rb +2 -6
  15. data/lib/puppeteer/execution_context.rb +1 -6
  16. data/lib/puppeteer/frame.rb +30 -16
  17. data/lib/puppeteer/frame_manager.rb +7 -25
  18. data/lib/puppeteer/js_handle.rb +3 -12
  19. data/lib/puppeteer/keyboard.rb +6 -27
  20. data/lib/puppeteer/mouse.rb +5 -25
  21. data/lib/puppeteer/page.rb +39 -63
  22. data/lib/puppeteer/remote_object.rb +2 -5
  23. data/lib/puppeteer/touch_screen.rb +2 -7
  24. data/lib/puppeteer/version.rb +1 -1
  25. data/lib/puppeteer/wait_task.rb +2 -4
  26. data/puppeteer-ruby.gemspec +1 -1
  27. metadata +7 -103
  28. data/docs/Puppeteer.html +0 -2338
  29. data/docs/Puppeteer/AsyncAwaitBehavior.html +0 -105
  30. data/docs/Puppeteer/Browser.html +0 -2258
  31. data/docs/Puppeteer/BrowserContext.html +0 -809
  32. data/docs/Puppeteer/BrowserFetcher.html +0 -214
  33. data/docs/Puppeteer/BrowserRunner.html +0 -914
  34. data/docs/Puppeteer/BrowserRunner/BrowserProcess.html +0 -477
  35. data/docs/Puppeteer/CDPSession.html +0 -813
  36. data/docs/Puppeteer/CDPSession/Error.html +0 -124
  37. data/docs/Puppeteer/ConcurrentRubyUtils.html +0 -438
  38. data/docs/Puppeteer/Connection.html +0 -964
  39. data/docs/Puppeteer/Connection/MessageCallback.html +0 -434
  40. data/docs/Puppeteer/Connection/ProtocolError.html +0 -216
  41. data/docs/Puppeteer/Connection/RequestDebugPrinter.html +0 -217
  42. data/docs/Puppeteer/Connection/ResponseDebugPrinter.html +0 -244
  43. data/docs/Puppeteer/ConsoleMessage.html +0 -565
  44. data/docs/Puppeteer/ConsoleMessage/Location.html +0 -433
  45. data/docs/Puppeteer/DOMWorld.html +0 -2293
  46. data/docs/Puppeteer/DOMWorld/DetachedError.html +0 -124
  47. data/docs/Puppeteer/DOMWorld/DocumentEvaluationError.html +0 -124
  48. data/docs/Puppeteer/DebugPrint.html +0 -233
  49. data/docs/Puppeteer/Device.html +0 -470
  50. data/docs/Puppeteer/Devices.html +0 -139
  51. data/docs/Puppeteer/ElementHandle.html +0 -2542
  52. data/docs/Puppeteer/ElementHandle/BoundingBox.html +0 -507
  53. data/docs/Puppeteer/ElementHandle/BoxModel.html +0 -404
  54. data/docs/Puppeteer/ElementHandle/ElementNotFoundError.html +0 -206
  55. data/docs/Puppeteer/ElementHandle/ElementNotVisibleError.html +0 -206
  56. data/docs/Puppeteer/ElementHandle/Point.html +0 -492
  57. data/docs/Puppeteer/ElementHandle/ScrollIntoViewError.html +0 -124
  58. data/docs/Puppeteer/EmulationManager.html +0 -454
  59. data/docs/Puppeteer/EventCallbackable.html +0 -499
  60. data/docs/Puppeteer/EventCallbackable/EventListeners.html +0 -435
  61. data/docs/Puppeteer/ExecutionContext.html +0 -998
  62. data/docs/Puppeteer/ExecutionContext/EvaluationError.html +0 -124
  63. data/docs/Puppeteer/ExecutionContext/JavaScriptExpression.html +0 -357
  64. data/docs/Puppeteer/ExecutionContext/JavaScriptFunction.html +0 -389
  65. data/docs/Puppeteer/FileChooser.html +0 -455
  66. data/docs/Puppeteer/Frame.html +0 -3835
  67. data/docs/Puppeteer/FrameManager.html +0 -2410
  68. data/docs/Puppeteer/FrameManager/NavigationError.html +0 -124
  69. data/docs/Puppeteer/IfPresent.html +0 -222
  70. data/docs/Puppeteer/JSHandle.html +0 -1352
  71. data/docs/Puppeteer/Keyboard.html +0 -1557
  72. data/docs/Puppeteer/Keyboard/KeyDefinition.html +0 -831
  73. data/docs/Puppeteer/Keyboard/KeyDescription.html +0 -603
  74. data/docs/Puppeteer/Launcher.html +0 -237
  75. data/docs/Puppeteer/Launcher/Base.html +0 -385
  76. data/docs/Puppeteer/Launcher/Base/ExecutablePathNotFound.html +0 -124
  77. data/docs/Puppeteer/Launcher/BrowserOptions.html +0 -441
  78. data/docs/Puppeteer/Launcher/Chrome.html +0 -674
  79. data/docs/Puppeteer/Launcher/Chrome/DefaultArgs.html +0 -382
  80. data/docs/Puppeteer/Launcher/ChromeArgOptions.html +0 -531
  81. data/docs/Puppeteer/Launcher/LaunchOptions.html +0 -893
  82. data/docs/Puppeteer/LifecycleWatcher.html +0 -834
  83. data/docs/Puppeteer/LifecycleWatcher/ExpectedLifecycle.html +0 -363
  84. data/docs/Puppeteer/LifecycleWatcher/FrameDetachedError.html +0 -206
  85. data/docs/Puppeteer/LifecycleWatcher/TerminatedError.html +0 -124
  86. data/docs/Puppeteer/Mouse.html +0 -1095
  87. data/docs/Puppeteer/Mouse/Button.html +0 -136
  88. data/docs/Puppeteer/NetworkManager.html +0 -901
  89. data/docs/Puppeteer/NetworkManager/Credentials.html +0 -385
  90. data/docs/Puppeteer/Page.html +0 -6173
  91. data/docs/Puppeteer/Page/FileChooserTimeoutError.html +0 -206
  92. data/docs/Puppeteer/Page/ScreenshotOptions.html +0 -845
  93. data/docs/Puppeteer/Page/ScriptTag.html +0 -555
  94. data/docs/Puppeteer/Page/StyleTag.html +0 -448
  95. data/docs/Puppeteer/Page/TargetCrashedError.html +0 -124
  96. data/docs/Puppeteer/RemoteObject.html +0 -1087
  97. data/docs/Puppeteer/Target.html +0 -1336
  98. data/docs/Puppeteer/Target/InitializeFailure.html +0 -124
  99. data/docs/Puppeteer/Target/TargetInfo.html +0 -729
  100. data/docs/Puppeteer/TimeoutError.html +0 -135
  101. data/docs/Puppeteer/TimeoutSettings.html +0 -496
  102. data/docs/Puppeteer/TouchScreen.html +0 -464
  103. data/docs/Puppeteer/Viewport.html +0 -837
  104. data/docs/Puppeteer/WaitTask.html +0 -637
  105. data/docs/Puppeteer/WaitTask/TerminatedError.html +0 -124
  106. data/docs/Puppeteer/WaitTask/TimeoutError.html +0 -206
  107. data/docs/Puppeteer/WebSocket.html +0 -673
  108. data/docs/Puppeteer/WebSocket/DriverImpl.html +0 -412
  109. data/docs/Puppeteer/WebSocket/TransportError.html +0 -124
  110. data/docs/Puppeteer/WebSocketTransport.html +0 -600
  111. data/docs/Puppeteer/WebSocktTransportError.html +0 -124
  112. data/docs/_index.html +0 -816
  113. data/docs/class_list.html +0 -51
  114. data/docs/css/common.css +0 -1
  115. data/docs/css/full_list.css +0 -58
  116. data/docs/css/style.css +0 -496
  117. data/docs/file.README.html +0 -125
  118. data/docs/file_list.html +0 -56
  119. data/docs/frames.html +0 -17
  120. data/docs/index.html +0 -125
  121. data/docs/js/app.js +0 -314
  122. data/docs/js/full_list.js +0 -216
  123. data/docs/js/jquery.js +0 -4
  124. data/docs/method_list.html +0 -4123
  125. data/docs/top-level-namespace.html +0 -126
  126. data/lib/puppeteer/async_await_behavior.rb +0 -38
@@ -4,7 +4,7 @@ require_relative './element_handle/point'
4
4
 
5
5
  class Puppeteer::ElementHandle < Puppeteer::JSHandle
6
6
  include Puppeteer::IfPresent
7
- using Puppeteer::AsyncAwaitBehavior
7
+ using Puppeteer::DefineAsyncMethod
8
8
 
9
9
  # @param context [Puppeteer::ExecutionContext]
10
10
  # @param client [Puppeteer::CDPSession]
@@ -105,11 +105,11 @@ class Puppeteer::ElementHandle < Puppeteer::JSHandle
105
105
  end
106
106
  end
107
107
 
108
- # async hover() {
109
- # await this._scrollIntoViewIfNeeded();
110
- # const {x, y} = await this._clickablePoint();
111
- # await this._page.mouse.move(x, y);
112
- # }
108
+ def hover
109
+ scroll_into_view_if_needed
110
+ point = clickable_point
111
+ @page.mouse.move(point.x, point.y)
112
+ end
113
113
 
114
114
  # @param delay [Number]
115
115
  # @param button [String] "left"|"right"|"middle"
@@ -120,12 +120,7 @@ class Puppeteer::ElementHandle < Puppeteer::JSHandle
120
120
  @page.mouse.click(point.x, point.y, delay: delay, button: button, click_count: click_count)
121
121
  end
122
122
 
123
- # @param delay [Number]
124
- # @param button [String] "left"|"right"|"middle"
125
- # @param click_count [Number]
126
- async def async_click(delay: nil, button: nil, click_count: nil)
127
- click(delay: delay, button: button, click_count: click_count)
128
- end
123
+ define_async_method :async_click
129
124
 
130
125
  # @return [Array<String>]
131
126
  def select(*values)
@@ -195,17 +190,13 @@ class Puppeteer::ElementHandle < Puppeteer::JSHandle
195
190
  @page.touchscreen.tap(point.x, point.y)
196
191
  end
197
192
 
198
- async def async_tap
199
- tap
200
- end
193
+ define_async_method :async_tap
201
194
 
202
195
  def focus
203
196
  evaluate('element => element.focus()')
204
197
  end
205
198
 
206
- async def async_focus
207
- focus
208
- end
199
+ define_async_method :async_focus
209
200
 
210
201
  # @param text [String]
211
202
  # @param delay [number|nil]
@@ -214,12 +205,7 @@ class Puppeteer::ElementHandle < Puppeteer::JSHandle
214
205
  @page.keyboard.type_text(text, delay: delay)
215
206
  end
216
207
 
217
- # @param text [String]
218
- # @param delay [number|nil]
219
- # @return [Future]
220
- async def async_type_text(text, delay: nil)
221
- type_text(text, delay: delay)
222
- end
208
+ define_async_method :async_type_text
223
209
 
224
210
  # @param key [String]
225
211
  # @param delay [number|nil]
@@ -228,12 +214,7 @@ class Puppeteer::ElementHandle < Puppeteer::JSHandle
228
214
  @page.keyboard.press(key, delay: delay)
229
215
  end
230
216
 
231
- # @param key [String]
232
- # @param delay [number|nil]
233
- # @return [Future]
234
- async def async_press(key, delay: nil)
235
- press(key, delay: delay)
236
- end
217
+ define_async_method :async_press
237
218
 
238
219
  # @return [BoundingBox|nil]
239
220
  def bounding_box
@@ -356,13 +337,7 @@ class Puppeteer::ElementHandle < Puppeteer::JSHandle
356
337
  result
357
338
  end
358
339
 
359
- # `$eval()` in JavaScript. $ is not allowed to use as a method name in Ruby.
360
- # @param selector [String]
361
- # @param page_function [String]
362
- # @return [Object]
363
- async def async_Seval(selector, page_function, *args)
364
- Seval(selector, page_function, *args)
365
- end
340
+ define_async_method :async_Seval
366
341
 
367
342
  # `$$eval()` in JavaScript. $ is not allowed to use as a method name in Ruby.
368
343
  # @param selector [String]
@@ -379,13 +354,7 @@ class Puppeteer::ElementHandle < Puppeteer::JSHandle
379
354
  result
380
355
  end
381
356
 
382
- # `$$eval()` in JavaScript. $ is not allowed to use as a method name in Ruby.
383
- # @param selector [String]
384
- # @param page_function [String]
385
- # @return [Object]
386
- async def async_SSeval(selector, page_function, *args)
387
- SSeval(selector, page_function, *args)
388
- end
357
+ define_async_method :async_SSeval
389
358
 
390
359
  # `$x()` in JavaScript. $ is not allowed to use as a method name in Ruby.
391
360
  # @param expression [String]
@@ -408,6 +377,8 @@ class Puppeteer::ElementHandle < Puppeteer::JSHandle
408
377
  properties.values.map(&:as_element).compact
409
378
  end
410
379
 
380
+ define_async_method :async_Sx
381
+
411
382
  # /**
412
383
  # * @returns {!Promise<boolean>}
413
384
  # */
@@ -1,5 +1,5 @@
1
1
  class Puppeteer::EmulationManager
2
- using Puppeteer::AsyncAwaitBehavior
2
+ using Puppeteer::DefineAsyncMethod
3
3
 
4
4
  # @param {!Puppeteer.CDPSession} client
5
5
  def initialize(client)
@@ -38,9 +38,5 @@ class Puppeteer::EmulationManager
38
38
  reload_needed
39
39
  end
40
40
 
41
- # @param viewport [Puppeteer::Viewport]
42
- # @return [Future<true|false>]
43
- async def async_emulate_viewport(viewport)
44
- emulate_viewport(viewport)
45
- end
41
+ define_async_method :async_emulate_viewport
46
42
  end
@@ -1,6 +1,6 @@
1
1
  class Puppeteer::ExecutionContext
2
2
  include Puppeteer::IfPresent
3
- using Puppeteer::AsyncAwaitBehavior
3
+ using Puppeteer::DefineAsyncMethod
4
4
 
5
5
  EVALUATION_SCRIPT_URL = '__puppeteer_evaluation_script__'
6
6
  SOURCE_URL_REGEX = /^[\040\t]*\/\/[@#] sourceURL=\s*(\S*?)\s*$/m
@@ -16,11 +16,6 @@ class Puppeteer::ExecutionContext
16
16
 
17
17
  attr_reader :client, :world
18
18
 
19
- # only used in DomWorld#delete_context
20
- def _context_id
21
- @context_id
22
- end
23
-
24
19
  # @return [Puppeteer::Frame]
25
20
  def frame
26
21
  if_present(@world) do |world|
@@ -1,5 +1,5 @@
1
1
  class Puppeteer::Frame
2
- using Puppeteer::AsyncAwaitBehavior
2
+ using Puppeteer::DefineAsyncMethod
3
3
 
4
4
  # @param {!FrameManager} frameManager
5
5
  # @param {!Puppeteer.CDPSession} client
@@ -39,12 +39,7 @@ class Puppeteer::Frame
39
39
  @frame_manager.wait_for_frame_navigation(self, timeout: timeout, wait_until: wait_until)
40
40
  end
41
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
42
+ define_async_method :async_wait_for_navigation
48
43
 
49
44
  def execution_context
50
45
  @main_world.execution_context
@@ -56,12 +51,16 @@ class Puppeteer::Frame
56
51
  @main_world.evaluate_handle(page_function, *args)
57
52
  end
58
53
 
54
+ define_async_method :async_evaluate_handle
55
+
59
56
  # @param {Function|string} pageFunction
60
57
  # @param {!Array<*>} args
61
58
  def evaluate(page_function, *args)
62
59
  @main_world.evaluate(page_function, *args)
63
60
  end
64
61
 
62
+ define_async_method :async_evaluate
63
+
65
64
  # `$()` in JavaScript. $ is not allowed to use as a method name in Ruby.
66
65
  # @param {string} selector
67
66
  # @return {!Promise<?Puppeteer.ElementHandle>}
@@ -69,6 +68,7 @@ class Puppeteer::Frame
69
68
  @main_world.S(selector)
70
69
  end
71
70
 
71
+ define_async_method :async_S
72
72
 
73
73
  # `$x()` in JavaScript. $ is not allowed to use as a method name in Ruby.
74
74
  # @param {string} expression
@@ -77,6 +77,7 @@ class Puppeteer::Frame
77
77
  @main_world.Sx(expression)
78
78
  end
79
79
 
80
+ define_async_method :async_Sx
80
81
 
81
82
  # `$eval()` in JavaScript. $ is not allowed to use as a method name in Ruby.
82
83
  # @param {string} selector
@@ -87,6 +88,8 @@ class Puppeteer::Frame
87
88
  @main_world.Seval(selector, page_function, *args)
88
89
  end
89
90
 
91
+ define_async_method :async_Seval
92
+
90
93
  # `$$eval()` in JavaScript. $ is not allowed to use as a method name in Ruby.
91
94
  # @param {string} selector
92
95
  # @param {Function|string} pageFunction
@@ -96,6 +99,8 @@ class Puppeteer::Frame
96
99
  @main_world.SSeval(selector, page_function, *args)
97
100
  end
98
101
 
102
+ define_async_method :async_SSeval
103
+
99
104
  # `$$()` in JavaScript. $ is not allowed to use as a method name in Ruby.
100
105
  # @param {string} selector
101
106
  # @return {!Promise<!Array<!Puppeteer.ElementHandle>>}
@@ -103,6 +108,8 @@ class Puppeteer::Frame
103
108
  @main_world.SS(selector)
104
109
  end
105
110
 
111
+ define_async_method :async_SS
112
+
106
113
  def content
107
114
  @secondary_world.content
108
115
  end
@@ -152,15 +159,6 @@ class Puppeteer::Frame
152
159
  @main_world.add_style_tag(style_tag)
153
160
  end
154
161
 
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
-
164
162
  # @param selector [String]
165
163
  # @param delay [Number]
166
164
  # @param button [String] "left"|"right"|"middle"
@@ -169,11 +167,15 @@ class Puppeteer::Frame
169
167
  @secondary_world.click(selector, delay: delay, button: button, click_count: click_count)
170
168
  end
171
169
 
170
+ define_async_method :async_click
171
+
172
172
  # @param {string} selector
173
173
  def focus(selector)
174
174
  @secondary_world.focus(selector)
175
175
  end
176
176
 
177
+ define_async_method :async_focus
178
+
177
179
  # @param {string} selector
178
180
  def hover(selector)
179
181
  @secondary_world.hover(selector)
@@ -186,11 +188,15 @@ class Puppeteer::Frame
186
188
  @secondary_world.select(selector, *values)
187
189
  end
188
190
 
191
+ define_async_method :async_select
192
+
189
193
  # @param {string} selector
190
194
  def tap(selector)
191
195
  @secondary_world.tap(selector)
192
196
  end
193
197
 
198
+ define_async_method :async_tap
199
+
194
200
  # @param selector [String]
195
201
  # @param text [String]
196
202
  # @param delay [Number]
@@ -198,6 +204,8 @@ class Puppeteer::Frame
198
204
  @main_world.type_text(selector, text, delay: delay)
199
205
  end
200
206
 
207
+ define_async_method :async_type_text
208
+
201
209
  # /**
202
210
  # * @param {(string|number|Function)} selectorOrFunctionOrTimeout
203
211
  # * @param {!Object=} options
@@ -235,6 +243,8 @@ class Puppeteer::Frame
235
243
  result
236
244
  end
237
245
 
246
+ define_async_method :async_wait_for_selector
247
+
238
248
  # @param xpath [String]
239
249
  # @param visible [Boolean] Wait for element visible (not 'display: none' nor 'visibility: hidden') on true. default to false.
240
250
  # @param hidden [Boolean] Wait for element invisible ('display: none' nor 'visibility: hidden') on true. default to false.
@@ -250,6 +260,8 @@ class Puppeteer::Frame
250
260
  result
251
261
  end
252
262
 
263
+ define_async_method :async_wait_for_xpath
264
+
253
265
  # @param {Function|string} pageFunction
254
266
  # @param {!{polling?: string|number, timeout?: number}=} options
255
267
  # @param {!Array<*>} args
@@ -258,6 +270,8 @@ class Puppeteer::Frame
258
270
  @main_world.wait_for_function(page_function, options, *args)
259
271
  end
260
272
 
273
+ define_async_method :async_wait_for_function
274
+
261
275
  # @return [String]
262
276
  def title
263
277
  @secondary_world.title
@@ -4,7 +4,7 @@ class Puppeteer::FrameManager
4
4
  include Puppeteer::DebugPrint
5
5
  include Puppeteer::IfPresent
6
6
  include Puppeteer::EventCallbackable
7
- using Puppeteer::AsyncAwaitBehavior
7
+ using Puppeteer::DefineAsyncMethod
8
8
 
9
9
  UTILITY_WORLD_NAME = '__puppeteer_utility_world__'
10
10
 
@@ -23,7 +23,6 @@ class Puppeteer::FrameManager
23
23
 
24
24
  # @type {!Map<number, !ExecutionContext>}
25
25
  @context_id_to_context = {}
26
- @context_id_created = {}
27
26
 
28
27
  # @type {!Set<string>}
29
28
  @isolated_worlds = Set.new
@@ -74,9 +73,7 @@ class Puppeteer::FrameManager
74
73
  @network_manager.init
75
74
  end
76
75
 
77
- async def async_init
78
- init
79
- end
76
+ define_async_method :async_init
80
77
 
81
78
  attr_reader :network_manager
82
79
 
@@ -281,7 +278,7 @@ class Puppeteer::FrameManager
281
278
  # @param url [String]
282
279
  def handle_frame_navigated_within_document(frame_id, url)
283
280
  frame = @frames[frame_id]
284
- return if !frame
281
+ return unless frame
285
282
  frame.navigated_within_document(url)
286
283
  emit_event 'Events.FrameManager.FrameNavigatedWithinDocument', frame
287
284
  emit_event 'Events.FrameManager.FrameNavigated', frame
@@ -320,44 +317,29 @@ class Puppeteer::FrameManager
320
317
  world.context = context
321
318
  end
322
319
  @context_id_to_context[context_payload['id']] = context
323
- @context_id_created[context_payload['id']] = Time.now
324
320
  end
325
321
 
326
322
  # @param {number} executionContextId
327
323
  def handle_execution_context_destroyed(execution_context_id)
328
324
  context = @context_id_to_context[execution_context_id]
329
- return if !context
325
+ return unless context
330
326
  @context_id_to_context.delete(execution_context_id)
331
- @context_id_created.delete(execution_context_id)
332
327
  if context.world
333
328
  context.world.delete_context(execution_context_id)
334
329
  end
335
330
  end
336
331
 
337
332
  def handle_execution_contexts_cleared
338
- # executionContextsCleared is often notified after executionContextCreated.
339
- # D, [2020-04-06T01:47:03.101227 #13823] DEBUG -- : RECV << {"method"=>"Runtime.executionContextCreated", "params"=>{"context"=>{"id"=>5, "origin"=>"https://github.com", "name"=>"", "auxData"=>{"isDefault"=>true, "type"=>"default", "frameId"=>"71C347B70848B89DDDEFAA8AB5B0BC92"}}}, "sessionId"=>"53F088EED260C28001D26A019F95D9E3"}
340
- # D, [2020-04-06T01:47:03.101439 #13823] DEBUG -- : RECV << {"method"=>"Page.frameNavigated", "params"=>{"frame"=>{"id"=>"71C347B70848B89DDDEFAA8AB5B0BC92", "loaderId"=>"80338225D035AC96BAE8F6D4E81C7D51", "url"=>"https://github.com/search?q=puppeteer", "securityOrigin"=>"https://github.com", "mimeType"=>"text/html"}}, "sessionId"=>"53F088EED260C28001D26A019F95D9E3"}
341
- # D, [2020-04-06T01:47:03.101325 #13823] DEBUG -- : RECV << {"method"=>"Target.targetInfoChanged", "params"=>{"targetInfo"=>{"targetId"=>"71C347B70848B89DDDEFAA8AB5B0BC92", "type"=>"page", "title"=>"https://github.com/search?q=puppeteer", "url"=>"https://github.com/search?q=puppeteer", "attached"=>true, "browserContextId"=>"AF37BC660284CE1552B4ECB147BE9305"}}}
342
- # D, [2020-04-06T01:47:03.101269 #13823] DEBUG -- : RECV << {"method"=>"Runtime.executionContextsCleared", "params"=>{}, "sessionId"=>"53F088EED260C28001D26A019F95D9E3"}
343
- # it unexpectedly clears the created execution context.
344
- # To avoid the problem, just skip recent created ids.
345
- now = Time.now
346
- context_ids_to_skip = @context_id_created.select { |k, v| now - v < 1 }.keys
347
- @context_id_to_context.reject { |k, v| context_ids_to_skip.include?(k) }.each do |execution_context_id, context|
333
+ @context_id_to_context.each do |execution_context_id, context|
348
334
  if context.world
349
335
  context.world.delete_context(execution_context_id)
350
336
  end
351
337
  end
352
- @context_id_to_context.select! { |k, v| context_ids_to_skip.include?(k) }
338
+ @context_id_to_context.clear
353
339
  end
354
340
 
355
341
  def execution_context_by_id(context_id)
356
- context = @context_id_to_context[context_id]
357
- if !context
358
- raise "INTERNAL ERROR: missing context with id = #{context_id}"
359
- end
360
- context
342
+ @context_id_to_context[context_id] or raise "INTERNAL ERROR: missing context with id = #{context_id}"
361
343
  end
362
344
 
363
345
  # @param {!Frame} frame
@@ -1,5 +1,5 @@
1
1
  class Puppeteer::JSHandle
2
- using Puppeteer::AsyncAwaitBehavior
2
+ using Puppeteer::DefineAsyncMethod
3
3
 
4
4
  # @param context [Puppeteer::ExecutionContext]
5
5
  # @param remote_object [Puppeteer::RemoteObject]
@@ -46,11 +46,7 @@ class Puppeteer::JSHandle
46
46
  execution_context.evaluate(page_function, self, *args)
47
47
  end
48
48
 
49
- # @param page_function [String]
50
- # @return [Future<Object>]
51
- async def async_evaluate(page_function, *args)
52
- evaluate(page_function, *args)
53
- end
49
+ define_async_method :async_evaluate
54
50
 
55
51
  # @param page_function [String]
56
52
  # @param args {Array<*>}
@@ -59,12 +55,7 @@ class Puppeteer::JSHandle
59
55
  execution_context.evaluate_handle(page_function, self, *args)
60
56
  end
61
57
 
62
- # @param page_function [String]
63
- # @param args {Array<*>}
64
- # @return [Future<Puppeteer::JSHandle>]
65
- async def async_evaluate_handle(page_function, *args)
66
- evaluate_handle(page_function, *args)
67
- end
58
+ define_async_method :async_evaluate_handle
68
59
 
69
60
  # /**
70
61
  # * @param {string} propertyName
@@ -2,7 +2,7 @@ require_relative './keyboard/key_description'
2
2
  require_relative './keyboard/us_keyboard_layout'
3
3
 
4
4
  class Puppeteer::Keyboard
5
- using Puppeteer::AsyncAwaitBehavior
5
+ using Puppeteer::DefineAsyncMethod
6
6
 
7
7
  # @param {!Puppeteer.CDPSession} client
8
8
  def initialize(client)
@@ -38,12 +38,7 @@ class Puppeteer::Keyboard
38
38
  @client.send_message('Input.dispatchKeyEvent', params)
39
39
  end
40
40
 
41
- # @param key [String]
42
- # @param text [String]
43
- # @return [Future]
44
- async def async_down(key, text: nil)
45
- down(key, text)
46
- end
41
+ define_async_method :async_down
47
42
 
48
43
  # @param {string} key
49
44
  # @return {number}
@@ -127,22 +122,14 @@ class Puppeteer::Keyboard
127
122
  )
128
123
  end
129
124
 
130
- # @param key [String]
131
- # @return [Future]
132
- async def async_up(key)
133
- up(key)
134
- end
125
+ define_async_method :async_up
135
126
 
136
127
  # @param char [string]
137
128
  def send_character(char)
138
129
  @client.send_message('Input.insertText', text: char)
139
130
  end
140
131
 
141
- # @param char [string]
142
- # @return [Future]
143
- async def async_send_character(char)
144
- send_character(char)
145
- end
132
+ define_async_method :async_send_character
146
133
 
147
134
  # @param text [String]
148
135
  # @return [Future]
@@ -159,11 +146,7 @@ class Puppeteer::Keyboard
159
146
  end
160
147
  end
161
148
 
162
- # @param text [String]
163
- # @return [Future]
164
- async def async_type_text(text, delay: nil)
165
- type_text(text, delay)
166
- end
149
+ define_async_method :async_type_text
167
150
 
168
151
  # @param key [String]
169
152
  # @return [Future]
@@ -175,9 +158,5 @@ class Puppeteer::Keyboard
175
158
  up(key)
176
159
  end
177
160
 
178
- # @param key [String]
179
- # @return [Future]
180
- async def async_press(key, delay: nil)
181
- press(key, delay: delay)
182
- end
161
+ define_async_method :async_press
183
162
  end