puppeteer-ruby 0.45.6 → 0.50.0.alpha6

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 (104) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -3
  3. data/AGENTS.md +170 -0
  4. data/CLAUDE/README.md +41 -0
  5. data/CLAUDE/architecture.md +253 -0
  6. data/CLAUDE/cdp_protocol.md +230 -0
  7. data/CLAUDE/concurrency.md +216 -0
  8. data/CLAUDE/porting_puppeteer.md +605 -0
  9. data/CLAUDE/rbs_type_checking.md +101 -0
  10. data/CLAUDE/spec_migration_plans.md +1039 -0
  11. data/CLAUDE/testing.md +278 -0
  12. data/CLAUDE.md +242 -0
  13. data/README.md +9 -0
  14. data/Rakefile +7 -0
  15. data/Steepfile +28 -0
  16. data/docs/api_coverage.md +106 -57
  17. data/lib/puppeteer/aria_query_handler.rb +3 -2
  18. data/lib/puppeteer/async_utils.rb +214 -0
  19. data/lib/puppeteer/browser.rb +98 -56
  20. data/lib/puppeteer/browser_connector.rb +18 -3
  21. data/lib/puppeteer/browser_context.rb +196 -3
  22. data/lib/puppeteer/browser_runner.rb +18 -10
  23. data/lib/puppeteer/cdp_session.rb +67 -23
  24. data/lib/puppeteer/chrome_target_manager.rb +65 -40
  25. data/lib/puppeteer/connection.rb +55 -36
  26. data/lib/puppeteer/console_message.rb +9 -1
  27. data/lib/puppeteer/console_patch.rb +47 -0
  28. data/lib/puppeteer/css_coverage.rb +5 -3
  29. data/lib/puppeteer/custom_query_handler.rb +80 -33
  30. data/lib/puppeteer/define_async_method.rb +31 -37
  31. data/lib/puppeteer/dialog.rb +47 -14
  32. data/lib/puppeteer/element_handle.rb +236 -62
  33. data/lib/puppeteer/emulation_manager.rb +1 -1
  34. data/lib/puppeteer/env.rb +1 -1
  35. data/lib/puppeteer/errors.rb +25 -2
  36. data/lib/puppeteer/event_callbackable.rb +15 -0
  37. data/lib/puppeteer/events.rb +4 -0
  38. data/lib/puppeteer/execution_context.rb +148 -3
  39. data/lib/puppeteer/file_chooser.rb +6 -0
  40. data/lib/puppeteer/frame.rb +177 -91
  41. data/lib/puppeteer/frame_manager.rb +69 -48
  42. data/lib/puppeteer/http_request.rb +114 -38
  43. data/lib/puppeteer/http_response.rb +24 -7
  44. data/lib/puppeteer/isolated_world.rb +64 -41
  45. data/lib/puppeteer/js_coverage.rb +5 -3
  46. data/lib/puppeteer/js_handle.rb +77 -16
  47. data/lib/puppeteer/keyboard.rb +30 -17
  48. data/lib/puppeteer/launcher/browser_options.rb +3 -1
  49. data/lib/puppeteer/launcher/chrome.rb +8 -5
  50. data/lib/puppeteer/launcher/launch_options.rb +7 -2
  51. data/lib/puppeteer/launcher.rb +4 -8
  52. data/lib/puppeteer/lifecycle_watcher.rb +38 -22
  53. data/lib/puppeteer/locators.rb +733 -0
  54. data/lib/puppeteer/mouse.rb +273 -64
  55. data/lib/puppeteer/network_event_manager.rb +7 -0
  56. data/lib/puppeteer/network_manager.rb +393 -112
  57. data/lib/puppeteer/p_query_handler.rb +367 -0
  58. data/lib/puppeteer/p_selector_parser.rb +241 -0
  59. data/lib/puppeteer/page/screenshot_task_queue.rb +14 -4
  60. data/lib/puppeteer/page.rb +583 -226
  61. data/lib/puppeteer/puppeteer.rb +171 -64
  62. data/lib/puppeteer/query_handler_manager.rb +66 -16
  63. data/lib/puppeteer/reactor_runner.rb +247 -0
  64. data/lib/puppeteer/remote_object.rb +127 -47
  65. data/lib/puppeteer/target.rb +74 -27
  66. data/lib/puppeteer/task_manager.rb +3 -1
  67. data/lib/puppeteer/timeout_helper.rb +6 -10
  68. data/lib/puppeteer/touch_handle.rb +39 -0
  69. data/lib/puppeteer/touch_screen.rb +72 -22
  70. data/lib/puppeteer/tracing.rb +3 -3
  71. data/lib/puppeteer/version.rb +1 -1
  72. data/lib/puppeteer/wait_task.rb +264 -101
  73. data/lib/puppeteer/web_socket.rb +2 -2
  74. data/lib/puppeteer/web_socket_transport.rb +91 -27
  75. data/lib/puppeteer/web_worker.rb +175 -0
  76. data/lib/puppeteer.rb +23 -4
  77. data/puppeteer-ruby.gemspec +15 -11
  78. data/sig/_external.rbs +8 -0
  79. data/sig/_supplementary.rbs +314 -0
  80. data/sig/puppeteer/browser.rbs +166 -0
  81. data/sig/puppeteer/cdp_session.rbs +64 -0
  82. data/sig/puppeteer/dialog.rbs +41 -0
  83. data/sig/puppeteer/element_handle.rbs +308 -0
  84. data/sig/puppeteer/execution_context.rbs +87 -0
  85. data/sig/puppeteer/frame.rbs +233 -0
  86. data/sig/puppeteer/http_request.rbs +214 -0
  87. data/sig/puppeteer/http_response.rbs +89 -0
  88. data/sig/puppeteer/js_handle.rbs +64 -0
  89. data/sig/puppeteer/keyboard.rbs +40 -0
  90. data/sig/puppeteer/locators.rbs +222 -0
  91. data/sig/puppeteer/mouse.rbs +113 -0
  92. data/sig/puppeteer/p_query_handler.rbs +73 -0
  93. data/sig/puppeteer/p_selector_parser.rbs +31 -0
  94. data/sig/puppeteer/page.rbs +522 -0
  95. data/sig/puppeteer/puppeteer.rbs +98 -0
  96. data/sig/puppeteer/remote_object.rbs +78 -0
  97. data/sig/puppeteer/touch_handle.rbs +21 -0
  98. data/sig/puppeteer/touch_screen.rbs +35 -0
  99. data/sig/puppeteer/web_worker.rbs +83 -0
  100. metadata +122 -45
  101. data/CHANGELOG.md +0 -397
  102. data/lib/puppeteer/concurrent_ruby_utils.rb +0 -81
  103. data/lib/puppeteer/firefox_target_manager.rb +0 -157
  104. data/lib/puppeteer/launcher/firefox.rb +0 -453
@@ -1,10 +1,13 @@
1
+ # rbs_inline: enabled
2
+
1
3
  class Puppeteer::Frame
2
4
  using Puppeteer::DefineAsyncMethod
3
5
 
4
- # @param frame_manager [Puppeteer::FrameManager]
5
- # @param parent_frame [Puppeteer::Frame|nil]
6
- # @param frame_id [String]
7
- # @param client [Puppeteer::CDPSession]
6
+ # @rbs frame_manager: Puppeteer::FrameManager -- Owning frame manager
7
+ # @rbs parent_frame: Puppeteer::Frame? -- Parent frame
8
+ # @rbs frame_id: String -- Frame ID
9
+ # @rbs client: Puppeteer::CDPSession -- CDP session
10
+ # @rbs return: void -- No return value
8
11
  def initialize(frame_manager, parent_frame, frame_id, client)
9
12
  @frame_manager = frame_manager
10
13
  @parent_frame = parent_frame
@@ -13,6 +16,7 @@ class Puppeteer::Frame
13
16
  @has_started_loading = false
14
17
 
15
18
  @loader_id = ''
19
+ @url = 'about:blank'
16
20
  @lifecycle_events = Set.new
17
21
  @child_frames = Set.new
18
22
  if parent_frame
@@ -22,6 +26,7 @@ class Puppeteer::Frame
22
26
  update_client(client)
23
27
  end
24
28
 
29
+ # @rbs return: String -- Inspection string
25
30
  def inspect
26
31
  values = %i[id parent_frame detached loader_id lifecycle_events child_frames].map do |sym|
27
32
  value = instance_variable_get(:"@#{sym}")
@@ -30,62 +35,110 @@ class Puppeteer::Frame
30
35
  "#<Puppeteer::Frame #{values.join(' ')}>"
31
36
  end
32
37
 
38
+ # @rbs return: Puppeteer::CDPSession -- Current CDP session
33
39
  def _client
34
40
  @client
35
41
  end
36
42
 
37
- # @param client [Puppeteer::CDPSession]
38
43
  private def update_client(client)
39
44
  @client = client
40
45
  @main_world = Puppeteer::IsolaatedWorld.new(@client, @frame_manager, self, @frame_manager.timeout_settings)
41
46
  @puppeteer_world = Puppeteer::IsolaatedWorld.new(@client, @frame_manager, self, @frame_manager.timeout_settings)
42
47
  end
43
48
 
49
+ # @rbs return: Puppeteer::Page -- Owning page
44
50
  def page
45
51
  @frame_manager.page
46
52
  end
47
53
 
54
+ # @rbs return: Numeric -- Default timeout in milliseconds
55
+ def default_timeout
56
+ @frame_manager.timeout_settings.timeout
57
+ end
58
+
59
+ # @rbs selector_or_function: String -- Selector or JS function
60
+ # @rbs return: Puppeteer::Locator -- Locator for selector or function
61
+ def locator(selector_or_function)
62
+ if Puppeteer::Locator.function_string?(selector_or_function)
63
+ Puppeteer::FunctionLocator.create(self, selector_or_function)
64
+ else
65
+ Puppeteer::NodeLocator.create(self, selector_or_function)
66
+ end
67
+ end
68
+
69
+ # @rbs return: bool -- Whether this is an OOPIF frame
48
70
  def oop_frame?
49
71
  @client != @frame_manager.client
50
72
  end
51
73
 
52
74
  attr_accessor :frame_manager, :id, :loader_id, :lifecycle_events, :main_world, :puppeteer_world
75
+ attr_reader :client
53
76
 
54
- def has_started_loading?
55
- @has_started_loading
77
+ # @rbs other: Object -- Other object to compare
78
+ # @rbs return: bool -- Equality result
79
+ def ==(other)
80
+ other = other.__getobj__ if other.is_a?(Puppeteer::ReactorRunner::Proxy)
81
+ return true if equal?(other)
82
+ return false unless other.is_a?(Puppeteer::Frame)
83
+ return false unless @id && other.id
84
+
85
+ @id == other.id
56
86
  end
57
87
 
58
- # @param url [String]
59
- # @param rederer [String]
60
- # @param timeout [number|nil]
61
- # @param wait_until [string|nil] 'load' | 'domcontentloaded' | 'networkidle0' | 'networkidle2'
62
- # @return [Puppeteer::HTTPResponse]
63
- def goto(url, referer: nil, timeout: nil, wait_until: nil)
64
- @frame_manager.navigate_frame(self, url, referer: referer, timeout: timeout, wait_until: wait_until)
88
+ # @rbs return: bool -- Whether loading has started
89
+ def has_started_loading?
90
+ @has_started_loading
65
91
  end
66
92
 
67
- # @param timeout [number|nil]
68
- # @param wait_until [string|nil] 'load' | 'domcontentloaded' | 'networkidle0' | 'networkidle2'
69
- def wait_for_navigation(timeout: nil, wait_until: nil)
70
- @frame_manager.wait_for_frame_navigation(self, timeout: timeout, wait_until: wait_until)
93
+ # @rbs url: String -- URL to navigate
94
+ # @rbs referer: String? -- Referer header value
95
+ # @rbs referrer_policy: String? -- Referrer policy
96
+ # @rbs timeout: Numeric? -- Navigation timeout in milliseconds
97
+ # @rbs wait_until: String? -- Lifecycle event to wait for
98
+ # @rbs return: Puppeteer::HTTPResponse? -- Navigation response
99
+ def goto(url, referer: nil, referrer_policy: nil, timeout: nil, wait_until: nil)
100
+ @frame_manager.navigate_frame(
101
+ self,
102
+ url,
103
+ referer: referer,
104
+ referrer_policy: referrer_policy,
105
+ timeout: timeout,
106
+ wait_until: wait_until,
107
+ )
108
+ end
109
+
110
+ # @rbs timeout: Numeric? -- Navigation timeout in milliseconds
111
+ # @rbs wait_until: String? -- Lifecycle event to wait for
112
+ # @rbs ignore_same_document_navigation: bool -- Ignore same-document navigation
113
+ # @rbs return: Puppeteer::HTTPResponse? -- Navigation response
114
+ def wait_for_navigation(timeout: nil, wait_until: nil, ignore_same_document_navigation: false)
115
+ @frame_manager.wait_for_frame_navigation(
116
+ self,
117
+ timeout: timeout,
118
+ wait_until: wait_until,
119
+ ignore_same_document_navigation: ignore_same_document_navigation,
120
+ )
71
121
  end
72
122
 
73
123
  define_async_method :async_wait_for_navigation
74
124
 
125
+ # @rbs return: Puppeteer::ExecutionContext -- Main world execution context
75
126
  def execution_context
76
127
  @main_world.execution_context
77
128
  end
78
129
 
79
- # @param {Function|string} pageFunction
80
- # @return {!Promise<!Puppeteer.JSHandle>}
130
+ # @rbs page_function: String -- Function or expression to evaluate
131
+ # @rbs args: Array[untyped] -- Arguments for evaluation
132
+ # @rbs return: Puppeteer::JSHandle -- Handle to evaluation result
81
133
  def evaluate_handle(page_function, *args)
82
134
  @main_world.evaluate_handle(page_function, *args)
83
135
  end
84
136
 
85
137
  define_async_method :async_evaluate_handle
86
138
 
87
- # @param {Function|string} pageFunction
88
- # @param {!Array<*>} args
139
+ # @rbs page_function: String -- Function or expression to evaluate
140
+ # @rbs args: Array[untyped] -- Arguments for evaluation
141
+ # @rbs return: untyped -- Evaluation result
89
142
  def evaluate(page_function, *args)
90
143
  @main_world.evaluate(page_function, *args)
91
144
  end
@@ -93,8 +146,8 @@ class Puppeteer::Frame
93
146
  define_async_method :async_evaluate
94
147
 
95
148
  # `$()` in JavaScript.
96
- # @param {string} selector
97
- # @return {!Promise<?Puppeteer.ElementHandle>}
149
+ # @rbs selector: String -- CSS selector
150
+ # @rbs return: Puppeteer::ElementHandle? -- Matching element or nil
98
151
  def query_selector(selector)
99
152
  @main_world.query_selector(selector)
100
153
  end
@@ -103,8 +156,8 @@ class Puppeteer::Frame
103
156
  define_async_method :async_query_selector
104
157
 
105
158
  # `$x()` in JavaScript. $ is not allowed to use as a method name in Ruby.
106
- # @param {string} expression
107
- # @return {!Promise<!Array<!Puppeteer.ElementHandle>>}
159
+ # @rbs expression: String -- XPath expression
160
+ # @rbs return: Array[Puppeteer::ElementHandle] -- Matching elements
108
161
  def Sx(expression)
109
162
  param_xpath =
110
163
  if expression.start_with?('//')
@@ -119,10 +172,10 @@ class Puppeteer::Frame
119
172
  define_async_method :async_Sx
120
173
 
121
174
  # `$eval()` in JavaScript.
122
- # @param {string} selector
123
- # @param {Function|string} pageFunction
124
- # @param {!Array<*>} args
125
- # @return {!Promise<(!Object|undefined)>}
175
+ # @rbs selector: String -- CSS selector
176
+ # @rbs page_function: String -- Function or expression to evaluate
177
+ # @rbs args: Array[untyped] -- Arguments for evaluation
178
+ # @rbs return: untyped -- Evaluation result
126
179
  def eval_on_selector(selector, page_function, *args)
127
180
  @main_world.eval_on_selector(selector, page_function, *args)
128
181
  end
@@ -131,10 +184,10 @@ class Puppeteer::Frame
131
184
  define_async_method :async_eval_on_selector
132
185
 
133
186
  # `$$eval()` in JavaScript.
134
- # @param {string} selector
135
- # @param {Function|string} pageFunction
136
- # @param {!Array<*>} args
137
- # @return {!Promise<(!Object|undefined)>}
187
+ # @rbs selector: String -- CSS selector
188
+ # @rbs page_function: String -- Function or expression to evaluate
189
+ # @rbs args: Array[untyped] -- Arguments for evaluation
190
+ # @rbs return: untyped -- Evaluation result
138
191
  def eval_on_selector_all(selector, page_function, *args)
139
192
  @main_world.eval_on_selector_all(selector, page_function, *args)
140
193
  end
@@ -143,137 +196,166 @@ class Puppeteer::Frame
143
196
  define_async_method :async_eval_on_selector_all
144
197
 
145
198
  # `$$()` in JavaScript.
146
- # @param {string} selector
147
- # @return {!Promise<!Array<!Puppeteer.ElementHandle>>}
148
- def query_selector_all(selector)
149
- @main_world.query_selector_all(selector)
199
+ # @rbs selector: String -- CSS selector
200
+ # @rbs isolate: bool? -- Use isolated world for queries
201
+ # @rbs return: Array[Puppeteer::ElementHandle] -- Matching elements
202
+ def query_selector_all(selector, isolate: nil)
203
+ @main_world.query_selector_all(selector, isolate: isolate)
150
204
  end
151
205
  alias_method :SS, :query_selector_all
152
206
 
153
207
  define_async_method :async_query_selector_all
154
208
 
155
- # @return [String]
209
+ # @rbs return: String -- Page HTML content
156
210
  def content
157
211
  @puppeteer_world.content
158
212
  end
159
213
 
160
- # @param html [String]
161
- # @param timeout [Integer]
162
- # @param wait_until [String|Array<String>]
214
+ # @rbs html: String -- HTML content
215
+ # @rbs timeout: Numeric? -- Navigation timeout in milliseconds
216
+ # @rbs wait_until: String | Array[String] | nil -- Lifecycle events to wait for
217
+ # @rbs return: void -- No return value
163
218
  def set_content(html, timeout: nil, wait_until: nil)
164
219
  @puppeteer_world.set_content(html, timeout: timeout, wait_until: wait_until)
165
220
  end
166
221
 
167
- # @return [String]
222
+ # @rbs return: String -- Frame name
168
223
  def name
169
224
  @name || ''
170
225
  end
171
226
 
172
- # @return [String]
227
+ # @rbs return: String? -- Frame URL
173
228
  def url
174
229
  @url
175
230
  end
176
231
 
177
- # @return [Frame?]
232
+ # @rbs return: Puppeteer::Frame? -- Parent frame
178
233
  def parent_frame
179
234
  @parent_frame
180
235
  end
181
236
 
237
+ # @rbs return: Puppeteer::ElementHandle? -- Frame element handle
238
+ def frame_element
239
+ parent = parent_frame
240
+ return nil unless parent
241
+
242
+ response = parent.client.send_message('DOM.getFrameOwner', frameId: @id)
243
+ parent.main_world.adopt_backend_node(response['backendNodeId'])
244
+ end
245
+
182
246
  protected def _child_frames
183
247
  @child_frames
184
248
  end
185
249
 
250
+ # @rbs return: Array[Puppeteer::Frame] -- Child frames
186
251
  def child_frames
187
252
  @child_frames.to_a
188
253
  end
189
254
 
255
+ # @rbs return: bool -- Whether the frame is detached
190
256
  def detached?
191
257
  @detached
192
258
  end
193
259
 
194
- # @param url [String?]
195
- # @param path [String?]
196
- # @param content [String?]
197
- # @param type [String?]
198
- # @param id [String?]
260
+ # @rbs url: String? -- Script URL
261
+ # @rbs path: String? -- Path to script file
262
+ # @rbs content: String? -- Script contents
263
+ # @rbs type: String? -- Script type
264
+ # @rbs id: String? -- Script element ID
265
+ # @rbs return: Puppeteer::ElementHandle -- Script element handle
199
266
  def add_script_tag(url: nil, path: nil, content: nil, type: nil, id: nil)
200
267
  @main_world.add_script_tag(url: url, path: path, content: content, type: type, id: id)
201
268
  end
202
269
 
203
- # @param url [String?]
204
- # @param path [String?]
205
- # @param content [String?]
270
+ # @rbs url: String? -- Stylesheet URL
271
+ # @rbs path: String? -- Path to stylesheet file
272
+ # @rbs content: String? -- Stylesheet contents
273
+ # @rbs return: Puppeteer::ElementHandle -- Style element handle
206
274
  def add_style_tag(url: nil, path: nil, content: nil)
207
275
  @main_world.add_style_tag(url: url, path: path, content: content)
208
276
  end
209
277
 
210
- # @param selector [String]
211
- # @param delay [Number]
212
- # @param button [String] "left"|"right"|"middle"
213
- # @param click_count [Number]
214
- def click(selector, delay: nil, button: nil, click_count: nil)
215
- @puppeteer_world.click(selector, delay: delay, button: button, click_count: click_count)
278
+ # @rbs selector: String -- CSS selector
279
+ # @rbs delay: Numeric? -- Delay between down and up (ms)
280
+ # @rbs button: String? -- Mouse button
281
+ # @rbs click_count: Integer? -- Deprecated: use count (click_count only sets clickCount)
282
+ # @rbs count: Integer? -- Number of clicks to perform
283
+ # @rbs return: void -- No return value
284
+ def click(selector, delay: nil, button: nil, click_count: nil, count: nil)
285
+ @puppeteer_world.click(selector, delay: delay, button: button, click_count: click_count, count: count)
216
286
  end
217
287
 
218
288
  define_async_method :async_click
219
289
 
220
- # @param {string} selector
290
+ # @rbs selector: String -- CSS selector
291
+ # @rbs return: void -- No return value
221
292
  def focus(selector)
222
293
  @puppeteer_world.focus(selector)
223
294
  end
224
295
 
225
296
  define_async_method :async_focus
226
297
 
227
- # @param {string} selector
298
+ # @rbs selector: String -- CSS selector
299
+ # @rbs return: void -- No return value
228
300
  def hover(selector)
229
301
  @puppeteer_world.hover(selector)
230
302
  end
231
303
 
232
- # @param {string} selector
233
- # @param {!Array<string>} values
234
- # @return {!Promise<!Array<string>>}
304
+ # @rbs selector: String -- CSS selector
305
+ # @rbs values: Array[String] -- Option values to select
306
+ # @rbs return: Array[String] -- Selected values
235
307
  def select(selector, *values)
236
308
  @puppeteer_world.select(selector, *values)
237
309
  end
238
310
 
239
311
  define_async_method :async_select
240
312
 
241
- # @param {string} selector
313
+ # @rbs selector: String -- CSS selector
314
+ # @rbs return: void -- No return value
242
315
  def tap(selector)
243
316
  @puppeteer_world.tap(selector)
244
317
  end
245
318
 
246
319
  define_async_method :async_tap
247
320
 
248
- # @param selector [String]
249
- # @param text [String]
250
- # @param delay [Number]
321
+ # @rbs selector: String -- CSS selector
322
+ # @rbs text: String -- Text to type
323
+ # @rbs delay: Numeric? -- Delay between key presses (ms)
324
+ # @rbs return: void -- No return value
251
325
  def type_text(selector, text, delay: nil)
252
326
  @main_world.type_text(selector, text, delay: delay)
253
327
  end
254
328
 
255
329
  define_async_method :async_type_text
256
330
 
257
- # @param selector [String]
258
- # @param visible [Boolean] Wait for element visible (not 'display: none' nor 'visibility: hidden') on true. default to false.
259
- # @param hidden [Boolean] Wait for element invisible ('display: none' nor 'visibility: hidden') on true. default to false.
260
- # @param timeout [Integer]
331
+ # @rbs selector: String -- CSS selector
332
+ # @rbs visible: bool? -- Wait for element to be visible
333
+ # @rbs hidden: bool? -- Wait for element to be hidden
334
+ # @rbs timeout: Numeric? -- Maximum wait time in milliseconds
335
+ # @rbs return: Puppeteer::ElementHandle? -- Matching element or nil
261
336
  def wait_for_selector(selector, visible: nil, hidden: nil, timeout: nil)
262
337
  query_handler_manager = Puppeteer::QueryHandlerManager.instance
263
- query_handler_manager.detect_query_handler(selector).wait_for(self, visible: visible, hidden: hidden, timeout: timeout)
338
+ query_handler_manager.detect_query_handler(selector).wait_for(
339
+ self,
340
+ visible: visible,
341
+ hidden: hidden,
342
+ timeout: timeout,
343
+ )
264
344
  end
265
345
 
266
346
  define_async_method :async_wait_for_selector
267
347
 
268
- # @param milliseconds [Integer] the number of milliseconds to wait.
348
+ # @rbs milliseconds: Numeric -- Time to wait in milliseconds
349
+ # @rbs return: void -- No return value
269
350
  def wait_for_timeout(milliseconds)
270
- sleep(milliseconds / 1000.0)
351
+ Puppeteer::AsyncUtils.sleep_seconds(milliseconds / 1000.0)
271
352
  end
272
353
 
273
- # @param xpath [String]
274
- # @param visible [Boolean] Wait for element visible (not 'display: none' nor 'visibility: hidden') on true. default to false.
275
- # @param hidden [Boolean] Wait for element invisible ('display: none' nor 'visibility: hidden') on true. default to false.
276
- # @param timeout [Integer]
354
+ # @rbs xpath: String -- XPath expression
355
+ # @rbs visible: bool? -- Wait for element to be visible
356
+ # @rbs hidden: bool? -- Wait for element to be hidden
357
+ # @rbs timeout: Numeric? -- Maximum wait time in milliseconds
358
+ # @rbs return: Puppeteer::ElementHandle? -- Matching element or nil
277
359
  def wait_for_xpath(xpath, visible: nil, hidden: nil, timeout: nil)
278
360
  param_xpath =
279
361
  if xpath.start_with?('//')
@@ -287,37 +369,38 @@ class Puppeteer::Frame
287
369
 
288
370
  define_async_method :async_wait_for_xpath
289
371
 
290
- # @param page_function [String]
291
- # @param args [Integer|Array]
292
- # @param polling [String]
293
- # @param timeout [Integer]
294
- # @return [Puppeteer::JSHandle]
372
+ # @rbs page_function: String -- Function or expression to evaluate
373
+ # @rbs args: Array[untyped] -- Arguments for evaluation
374
+ # @rbs polling: String | Numeric | nil -- Polling strategy
375
+ # @rbs timeout: Numeric? -- Maximum wait time in milliseconds
376
+ # @rbs return: Puppeteer::JSHandle -- Handle to evaluation result
295
377
  def wait_for_function(page_function, args: [], polling: nil, timeout: nil)
296
378
  @main_world.wait_for_function(page_function, args: args, polling: polling, timeout: timeout)
297
379
  end
298
380
 
299
381
  define_async_method :async_wait_for_function
300
382
 
301
- # @return [String]
383
+ # @rbs return: String -- Frame title
302
384
  def title
303
385
  @puppeteer_world.title
304
386
  end
305
387
 
306
- # @param frame_payload [Hash]
388
+ # @rbs frame_payload: Hash[String, untyped] -- Frame payload
389
+ # @rbs return: void -- No return value
307
390
  def navigated(frame_payload)
308
391
  @name = frame_payload['name']
309
392
  @url = "#{frame_payload['url']}#{frame_payload['urlFragment']}"
310
-
311
- # Ensure loaderId updated.
312
- # The order of [Page.lifecycleEvent name="init"] and [Page.frameNavigated] is random... for some reason...
313
- @loader_id = frame_payload['loaderId'] if frame_payload['loaderId']
314
393
  end
315
394
 
316
- # @param url [String]
395
+ # @rbs url: String -- Updated URL
396
+ # @rbs return: void -- No return value
317
397
  def navigated_within_document(url)
318
398
  @url = url
319
399
  end
320
400
 
401
+ # @rbs loader_id: String -- Loader ID
402
+ # @rbs name: String -- Lifecycle event name
403
+ # @rbs return: void -- No return value
321
404
  def handle_lifecycle_event(loader_id, name)
322
405
  if name == 'init'
323
406
  @loader_id = loader_id
@@ -326,15 +409,18 @@ class Puppeteer::Frame
326
409
  @lifecycle_events << name
327
410
  end
328
411
 
412
+ # @rbs return: void -- No return value
329
413
  def handle_loading_started
330
414
  @has_started_loading = true
331
415
  end
332
416
 
417
+ # @rbs return: void -- No return value
333
418
  def handle_loading_stopped
334
419
  @lifecycle_events << 'DOMContentLoaded'
335
420
  @lifecycle_events << 'load'
336
421
  end
337
422
 
423
+ # @rbs return: void -- No return value
338
424
  def detach
339
425
  @detached = true
340
426
  @main_world.detach