puppeteer-bidi 0.0.1.beta1 → 0.0.1.beta3

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 (84) hide show
  1. checksums.yaml +4 -4
  2. data/CLAUDE.md +50 -4
  3. data/README.md +8 -1
  4. data/Steepfile +36 -0
  5. data/lib/puppeteer/bidi/async_utils.rb +1 -0
  6. data/lib/puppeteer/bidi/browser.rb +38 -24
  7. data/lib/puppeteer/bidi/browser_context.rb +13 -4
  8. data/lib/puppeteer/bidi/browser_launcher.rb +1 -0
  9. data/lib/puppeteer/bidi/connection.rb +26 -9
  10. data/lib/puppeteer/bidi/core/browser.rb +15 -14
  11. data/lib/puppeteer/bidi/core/browsing_context.rb +64 -46
  12. data/lib/puppeteer/bidi/core/disposable.rb +10 -3
  13. data/lib/puppeteer/bidi/core/errors.rb +18 -1
  14. data/lib/puppeteer/bidi/core/event_emitter.rb +18 -9
  15. data/lib/puppeteer/bidi/core/navigation.rb +4 -3
  16. data/lib/puppeteer/bidi/core/realm.rb +29 -26
  17. data/lib/puppeteer/bidi/core/request.rb +33 -29
  18. data/lib/puppeteer/bidi/core/session.rb +14 -11
  19. data/lib/puppeteer/bidi/core/user_context.rb +17 -16
  20. data/lib/puppeteer/bidi/core/user_prompt.rb +8 -7
  21. data/lib/puppeteer/bidi/core.rb +1 -0
  22. data/lib/puppeteer/bidi/deserializer.rb +1 -0
  23. data/lib/puppeteer/bidi/element_handle.rb +52 -52
  24. data/lib/puppeteer/bidi/errors.rb +1 -0
  25. data/lib/puppeteer/bidi/file_chooser.rb +1 -0
  26. data/lib/puppeteer/bidi/frame.rb +70 -70
  27. data/lib/puppeteer/bidi/http_response.rb +1 -0
  28. data/lib/puppeteer/bidi/injected_source.rb +1 -0
  29. data/lib/puppeteer/bidi/js_handle.rb +23 -23
  30. data/lib/puppeteer/bidi/keyboard.rb +24 -13
  31. data/lib/puppeteer/bidi/lazy_arg.rb +1 -0
  32. data/lib/puppeteer/bidi/mouse.rb +31 -18
  33. data/lib/puppeteer/bidi/page.rb +87 -87
  34. data/lib/puppeteer/bidi/query_handler.rb +3 -0
  35. data/lib/puppeteer/bidi/realm.rb +70 -6
  36. data/lib/puppeteer/bidi/serializer.rb +1 -0
  37. data/lib/puppeteer/bidi/target.rb +24 -0
  38. data/lib/puppeteer/bidi/task_manager.rb +9 -3
  39. data/lib/puppeteer/bidi/timeout_settings.rb +1 -0
  40. data/lib/puppeteer/bidi/transport.rb +1 -0
  41. data/lib/puppeteer/bidi/version.rb +1 -1
  42. data/lib/puppeteer/bidi/wait_task.rb +1 -0
  43. data/lib/puppeteer/bidi.rb +8 -4
  44. data/sig/_external.rbs +128 -0
  45. data/sig/_supplementary.rbs +20 -0
  46. data/sig/puppeteer/bidi/async_utils.rbs +68 -0
  47. data/sig/puppeteer/bidi/browser.rbs +35 -26
  48. data/sig/puppeteer/bidi/browser_context.rbs +39 -0
  49. data/sig/puppeteer/bidi/browser_launcher.rbs +45 -0
  50. data/sig/puppeteer/bidi/connection.rbs +67 -0
  51. data/sig/puppeteer/bidi/core/browser.rbs +79 -0
  52. data/sig/puppeteer/bidi/core/browsing_context.rbs +210 -0
  53. data/sig/puppeteer/bidi/core/disposable.rbs +42 -0
  54. data/sig/puppeteer/bidi/core/errors.rbs +65 -0
  55. data/sig/puppeteer/bidi/core/event_emitter.rbs +50 -0
  56. data/sig/puppeteer/bidi/core/navigation.rbs +37 -0
  57. data/sig/puppeteer/bidi/core/realm.rbs +132 -0
  58. data/sig/puppeteer/bidi/core/request.rbs +120 -0
  59. data/sig/puppeteer/bidi/core/session.rbs +65 -0
  60. data/sig/puppeteer/bidi/core/user_context.rbs +72 -0
  61. data/sig/puppeteer/bidi/core/user_prompt.rbs +52 -0
  62. data/sig/puppeteer/bidi/core.rbs +9 -0
  63. data/sig/puppeteer/bidi/deserializer.rbs +28 -0
  64. data/sig/puppeteer/bidi/element_handle.rbs +52 -52
  65. data/sig/puppeteer/bidi/errors.rbs +34 -0
  66. data/sig/puppeteer/bidi/file_chooser.rbs +27 -0
  67. data/sig/puppeteer/bidi/frame.rbs +70 -70
  68. data/sig/puppeteer/bidi/http_response.rbs +18 -0
  69. data/sig/puppeteer/bidi/injected_source.rbs +21 -0
  70. data/sig/puppeteer/bidi/js_handle.rbs +23 -23
  71. data/sig/puppeteer/bidi/keyboard.rbs +57 -0
  72. data/sig/puppeteer/bidi/lazy_arg.rbs +15 -0
  73. data/sig/puppeteer/bidi/mouse.rbs +73 -0
  74. data/sig/puppeteer/bidi/page.rbs +87 -87
  75. data/sig/puppeteer/bidi/query_handler.rbs +113 -0
  76. data/sig/puppeteer/bidi/realm.rbs +141 -0
  77. data/sig/puppeteer/bidi/serializer.rbs +31 -0
  78. data/sig/puppeteer/bidi/target.rbs +68 -0
  79. data/sig/puppeteer/bidi/task_manager.rbs +36 -0
  80. data/sig/puppeteer/bidi/timeout_settings.rbs +14 -0
  81. data/sig/puppeteer/bidi/transport.rbs +43 -0
  82. data/sig/puppeteer/bidi/wait_task.rbs +62 -0
  83. data/sig/puppeteer/bidi.rbs +8 -4
  84. metadata +36 -1
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ # rbs_inline: enabled
2
3
 
3
4
  module Puppeteer
4
5
  module Bidi
@@ -8,12 +9,12 @@ module Puppeteer
8
9
  include Disposable::DisposableMixin
9
10
 
10
11
  # Create a browsing context
11
- # @param user_context [UserContext] Parent user context
12
- # @param parent [BrowsingContext, nil] Parent browsing context
13
- # @param id [String] Context ID
14
- # @param url [String] Initial URL
15
- # @param original_opener [String, nil] Original opener context ID
16
- # @return [BrowsingContext] New browsing context
12
+ # @rbs user_context: UserContext -- Parent user context
13
+ # @rbs parent: BrowsingContext? -- Parent browsing context
14
+ # @rbs id: String -- Context ID
15
+ # @rbs url: String -- Initial URL
16
+ # @rbs original_opener: String? -- Original opener context ID
17
+ # @rbs return: BrowsingContext -- New browsing context
17
18
  def self.from(user_context, parent, id, url, original_opener)
18
19
  context = new(user_context, parent, id, url, original_opener)
19
20
  context.send(:initialize_context)
@@ -50,25 +51,25 @@ module Puppeteer
50
51
  alias disposed? closed?
51
52
 
52
53
  # Get the current URL
53
- # @return [String] Current URL
54
+ # @rbs return: String -- Current URL
54
55
  def url
55
56
  @url
56
57
  end
57
58
 
58
59
  # Get child browsing contexts
59
- # @return [Array<BrowsingContext>] Child contexts
60
+ # @rbs return: Array[BrowsingContext] -- Child contexts
60
61
  def children
61
62
  @children.values
62
63
  end
63
64
 
64
65
  # Get all realms in this context
65
- # @return [Array<WindowRealm>] All realms
66
+ # @rbs return: Array[WindowRealm] -- All realms
66
67
  def realms
67
68
  [@default_realm] + @realms.values
68
69
  end
69
70
 
70
71
  # Get the top-level browsing context
71
- # @return [BrowsingContext] Top-level context
72
+ # @rbs return: BrowsingContext -- Top-level context
72
73
  def top
73
74
  context = self
74
75
  while context.parent
@@ -84,8 +85,9 @@ module Puppeteer
84
85
  end
85
86
 
86
87
  # Navigate to a URL
87
- # @param url [String] URL to navigate to
88
- # @param wait [String, nil] Wait condition ('none', 'interactive', 'complete')
88
+ # @rbs url: String -- URL to navigate to
89
+ # @rbs wait: String? -- Wait condition ('none', 'interactive', 'complete')
90
+ # @rbs return: Async::Task[untyped]
89
91
  def navigate(url, wait: nil)
90
92
  Async do
91
93
  raise BrowsingContextClosedError, @reason if closed?
@@ -98,15 +100,16 @@ module Puppeteer
98
100
  end
99
101
 
100
102
  # Reload the page
101
- # @param options [Hash] Reload options
103
+ # @rbs **options: untyped -- Reload options
104
+ # @rbs return: Async::Task[untyped]
102
105
  def reload(**options)
103
106
  raise BrowsingContextClosedError, @reason if closed?
104
107
  session.async_send_command('browsingContext.reload', options.merge(context: @id))
105
108
  end
106
109
 
107
110
  # Capture a screenshot
108
- # @param options [Hash] Screenshot options
109
- # @return [Async::Task<String>] Base64-encoded image data
111
+ # @rbs **options: untyped -- Screenshot options
112
+ # @rbs return: Async::Task[String] -- Base64-encoded image data
110
113
  def capture_screenshot(**options)
111
114
  raise BrowsingContextClosedError, @reason if closed?
112
115
  Async do
@@ -116,8 +119,8 @@ module Puppeteer
116
119
  end
117
120
 
118
121
  # Print to PDF
119
- # @param options [Hash] Print options
120
- # @return [Async::Task<String>] Base64-encoded PDF data
122
+ # @rbs **options: untyped -- Print options
123
+ # @rbs return: Async::Task[String] -- Base64-encoded PDF data
121
124
  def print(**options)
122
125
  raise BrowsingContextClosedError, @reason if closed?
123
126
  Async do
@@ -127,7 +130,8 @@ module Puppeteer
127
130
  end
128
131
 
129
132
  # Close this browsing context
130
- # @param prompt_unload [Boolean] Whether to prompt before unload
133
+ # @rbs prompt_unload: bool -- Whether to prompt before unload
134
+ # @rbs return: Async::Task[void]
131
135
  def close(prompt_unload: false)
132
136
  raise BrowsingContextClosedError, @reason if closed?
133
137
 
@@ -163,7 +167,8 @@ module Puppeteer
163
167
  end
164
168
 
165
169
  # Traverse history
166
- # @param delta [Integer] Number of steps to go back (negative) or forward (positive)
170
+ # @rbs delta: Integer -- Number of steps to go back (negative) or forward (positive)
171
+ # @rbs return: Async::Task[untyped]
167
172
  def traverse_history(delta)
168
173
  raise BrowsingContextClosedError, @reason if closed?
169
174
  session.async_send_command('browsingContext.traverseHistory', {
@@ -173,21 +178,24 @@ module Puppeteer
173
178
  end
174
179
 
175
180
  # Handle a user prompt
176
- # @param options [Hash] Prompt handling options
181
+ # @rbs **options: untyped -- Prompt handling options
182
+ # @rbs return: Async::Task[untyped]
177
183
  def handle_user_prompt(**options)
178
184
  raise BrowsingContextClosedError, @reason if closed?
179
185
  session.async_send_command('browsingContext.handleUserPrompt', options.merge(context: @id))
180
186
  end
181
187
 
182
188
  # Set viewport
183
- # @param options [Hash] Viewport options
189
+ # @rbs **options: untyped -- Viewport options
190
+ # @rbs return: Async::Task[untyped]
184
191
  def set_viewport(**options)
185
192
  raise BrowsingContextClosedError, @reason if closed?
186
193
  session.async_send_command('browsingContext.setViewport', options.merge(context: @id))
187
194
  end
188
195
 
189
196
  # Perform input actions
190
- # @param actions [Array<Hash>] Input actions
197
+ # @rbs actions: Array[Hash[String, untyped]] -- Input actions
198
+ # @rbs return: Async::Task[untyped]
191
199
  def perform_actions(actions)
192
200
  raise BrowsingContextClosedError, @reason if closed?
193
201
  session.async_send_command('input.performActions', {
@@ -203,7 +211,8 @@ module Puppeteer
203
211
  end
204
212
 
205
213
  # Set cache behavior
206
- # @param cache_behavior [String] 'default' or 'bypass'
214
+ # @rbs cache_behavior: String -- 'default' or 'bypass'
215
+ # @rbs return: Async::Task[untyped]
207
216
  def set_cache_behavior(cache_behavior)
208
217
  raise BrowsingContextClosedError, @reason if closed?
209
218
  session.async_send_command('network.setCacheBehavior', {
@@ -213,8 +222,8 @@ module Puppeteer
213
222
  end
214
223
 
215
224
  # Create a sandboxed window realm
216
- # @param sandbox [String] Sandbox name
217
- # @return [WindowRealm] New realm
225
+ # @rbs sandbox: String -- Sandbox name
226
+ # @rbs return: WindowRealm -- New realm
218
227
  def create_window_realm(sandbox)
219
228
  raise BrowsingContextClosedError, @reason if closed?
220
229
  realm = WindowRealm.from(self, sandbox)
@@ -225,9 +234,9 @@ module Puppeteer
225
234
  end
226
235
 
227
236
  # Add a preload script to this context
228
- # @param function_declaration [String] JavaScript function
229
- # @param options [Hash] Script options
230
- # @return [String] Script ID
237
+ # @rbs function_declaration: String -- JavaScript function
238
+ # @rbs **options: untyped -- Script options
239
+ # @rbs return: Async::Task[String] -- Script ID
231
240
  def add_preload_script(function_declaration, **options)
232
241
  raise BrowsingContextClosedError, @reason if closed?
233
242
  user_context.browser.add_preload_script(
@@ -237,15 +246,16 @@ module Puppeteer
237
246
  end
238
247
 
239
248
  # Remove a preload script
240
- # @param script [String] Script ID
249
+ # @rbs script: String -- Script ID
250
+ # @rbs return: Async::Task[untyped]
241
251
  def remove_preload_script(script)
242
252
  raise BrowsingContextClosedError, @reason if closed?
243
253
  user_context.browser.remove_preload_script(script)
244
254
  end
245
255
 
246
256
  # Add network intercept
247
- # @param options [Hash] Intercept options
248
- # @return [String] Intercept ID
257
+ # @rbs **options: untyped -- Intercept options
258
+ # @rbs return: String -- Intercept ID
249
259
  def add_intercept(**options)
250
260
  raise BrowsingContextClosedError, @reason if closed?
251
261
  result = session.async_send_command('network.addIntercept', options.merge(contexts: [@id]))
@@ -253,8 +263,8 @@ module Puppeteer
253
263
  end
254
264
 
255
265
  # Get cookies
256
- # @param options [Hash] Cookie filter options
257
- # @return [Array<Hash>] Cookies
266
+ # @rbs **options: untyped -- Cookie filter options
267
+ # @rbs return: Array[Hash[String, untyped]] -- Cookies
258
268
  def get_cookies(**options)
259
269
  raise BrowsingContextClosedError, @reason if closed?
260
270
  params = options.dup
@@ -267,7 +277,8 @@ module Puppeteer
267
277
  end
268
278
 
269
279
  # Set a cookie
270
- # @param cookie [Hash] Cookie data
280
+ # @rbs cookie: Hash[String, untyped] -- Cookie data
281
+ # @rbs return: Async::Task[untyped]
271
282
  def set_cookie(cookie)
272
283
  raise BrowsingContextClosedError, @reason if closed?
273
284
  session.async_send_command('storage.setCookie', {
@@ -280,7 +291,8 @@ module Puppeteer
280
291
  end
281
292
 
282
293
  # Delete cookies
283
- # @param cookie_filters [Array<Hash>] Cookie filters
294
+ # @rbs *cookie_filters: Hash[String, untyped] -- Cookie filters
295
+ # @rbs return: void
284
296
  def delete_cookie(*cookie_filters)
285
297
  raise BrowsingContextClosedError, @reason if closed?
286
298
  cookie_filters.each do |filter|
@@ -295,7 +307,8 @@ module Puppeteer
295
307
  end
296
308
 
297
309
  # Set geolocation override
298
- # @param options [Hash] Geolocation options
310
+ # @rbs **options: untyped -- Geolocation options
311
+ # @rbs return: Async::Task[untyped]
299
312
  def set_geolocation_override(**options)
300
313
  raise BrowsingContextClosedError, @reason if closed?
301
314
  raise 'Missing coordinates' unless options[:coordinates]
@@ -307,7 +320,8 @@ module Puppeteer
307
320
  end
308
321
 
309
322
  # Set timezone override
310
- # @param timezone_id [String, nil] Timezone ID
323
+ # @rbs timezone_id: String? -- Timezone ID
324
+ # @rbs return: Async::Task[untyped]
311
325
  def set_timezone_override(timezone_id = nil)
312
326
  raise BrowsingContextClosedError, @reason if closed?
313
327
 
@@ -321,8 +335,9 @@ module Puppeteer
321
335
  end
322
336
 
323
337
  # Set files on an input element
324
- # @param element [Hash] Element reference
325
- # @param files [Array<String>] File paths
338
+ # @rbs element: Hash[String, untyped] -- Element reference
339
+ # @rbs files: Array[String] -- File paths
340
+ # @rbs return: Async::Task[untyped]
326
341
  def set_files(element, files)
327
342
  raise BrowsingContextClosedError, @reason if closed?
328
343
  session.async_send_command('input.setFiles', {
@@ -333,9 +348,9 @@ module Puppeteer
333
348
  end
334
349
 
335
350
  # Locate nodes in the context
336
- # @param locator [Hash] Node locator
337
- # @param start_nodes [Array<Hash>] Starting nodes
338
- # @return [Array<Hash>] Located nodes
351
+ # @rbs locator: Hash[String, untyped] -- Node locator
352
+ # @rbs start_nodes: Array[Hash[String, untyped]] -- Starting nodes
353
+ # @rbs return: Array[Hash[String, untyped]] -- Located nodes
339
354
  def locate_nodes(locator, start_nodes = [])
340
355
  raise BrowsingContextClosedError, @reason if closed?
341
356
  params = {
@@ -349,7 +364,8 @@ module Puppeteer
349
364
  end
350
365
 
351
366
  # Set JavaScript enabled state
352
- # @param enabled [Boolean] Whether JavaScript is enabled
367
+ # @rbs enabled: bool -- Whether JavaScript is enabled
368
+ # @rbs return: Async::Task[void]
353
369
  def set_javascript_enabled(enabled)
354
370
  Async do
355
371
  raise BrowsingContextClosedError, @reason if closed?
@@ -362,20 +378,22 @@ module Puppeteer
362
378
  end
363
379
 
364
380
  # Check if JavaScript is enabled
365
- # @return [Boolean] Whether JavaScript is enabled
381
+ # @rbs return: bool -- Whether JavaScript is enabled
366
382
  def javascript_enabled?
367
383
  @emulation_state[:javascript_enabled]
368
384
  end
369
385
 
370
386
  # Subscribe to events for this context
371
- # @param events [Array<String>] Event names
387
+ # @rbs events: Array[String] -- Event names
388
+ # @rbs return: void
372
389
  def subscribe(events)
373
390
  raise BrowsingContextClosedError, @reason if closed?
374
391
  session.subscribe(events, [@id])
375
392
  end
376
393
 
377
394
  # Add interception for this context
378
- # @param events [Array<String>] Event names
395
+ # @rbs events: Array[String] -- Event names
396
+ # @rbs return: void
379
397
  def add_interception(events)
380
398
  raise BrowsingContextClosedError, @reason if closed?
381
399
  session.subscribe(events, [@id])
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ # rbs_inline: enabled
2
3
 
3
4
  module Puppeteer
4
5
  module Bidi
@@ -8,14 +9,15 @@ module Puppeteer
8
9
  module Disposable
9
10
  # DisposableStack manages multiple disposable resources
10
11
  class DisposableStack
12
+ # @rbs return: void
11
13
  def initialize
12
14
  @disposed = false
13
- @resources = []
15
+ @resources = [] #: Array[untyped]
14
16
  end
15
17
 
16
18
  # Add a disposable resource to the stack
17
- # @param resource [Object] Resource that responds to #dispose
18
- # @return [Object] The resource itself for convenience
19
+ # @rbs resource: untyped -- Resource that responds to #dispose
20
+ # @rbs return: untyped -- The resource itself for convenience
19
21
  def use(resource)
20
22
  raise 'DisposableStack already disposed' if @disposed
21
23
  @resources << resource
@@ -23,6 +25,7 @@ module Puppeteer
23
25
  end
24
26
 
25
27
  # Dispose all resources in reverse order (LIFO)
28
+ # @rbs return: void
26
29
  def dispose
27
30
  return if @disposed
28
31
  @disposed = true
@@ -39,6 +42,7 @@ module Puppeteer
39
42
  @resources.clear
40
43
  end
41
44
 
45
+ # @rbs return: bool
42
46
  def disposed?
43
47
  @disposed
44
48
  end
@@ -46,12 +50,14 @@ module Puppeteer
46
50
 
47
51
  # Module to be included in classes that need disposal
48
52
  module DisposableMixin
53
+ # @rbs return: void
49
54
  def dispose
50
55
  return if @disposed
51
56
  @disposed = true
52
57
  perform_dispose
53
58
  end
54
59
 
60
+ # @rbs return: bool
55
61
  def disposed?
56
62
  @disposed ||= false
57
63
  end
@@ -59,6 +65,7 @@ module Puppeteer
59
65
  protected
60
66
 
61
67
  # Override this method to perform cleanup
68
+ # @rbs return: void
62
69
  def perform_dispose
63
70
  # Default implementation does nothing
64
71
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ # rbs_inline: enabled
2
3
 
3
4
  module Puppeteer
4
5
  module Bidi
@@ -9,8 +10,12 @@ module Puppeteer
9
10
 
10
11
  # Raised when attempting to use a disposed resource
11
12
  class DisposedError < Error
12
- attr_reader :resource_type, :reason
13
+ attr_reader :resource_type #: String
14
+ attr_reader :reason #: String
13
15
 
16
+ # @rbs resource_type: String
17
+ # @rbs reason: String
18
+ # @rbs return: void
14
19
  def initialize(resource_type, reason)
15
20
  @resource_type = resource_type
16
21
  @reason = reason
@@ -20,6 +25,8 @@ module Puppeteer
20
25
 
21
26
  # Raised when a realm has been destroyed
22
27
  class RealmDestroyedError < DisposedError
28
+ # @rbs reason: String
29
+ # @rbs return: void
23
30
  def initialize(reason)
24
31
  super('Realm', reason)
25
32
  end
@@ -27,6 +34,8 @@ module Puppeteer
27
34
 
28
35
  # Raised when a browsing context has been closed
29
36
  class BrowsingContextClosedError < DisposedError
37
+ # @rbs reason: String
38
+ # @rbs return: void
30
39
  def initialize(reason)
31
40
  super('Browsing context', reason)
32
41
  end
@@ -34,6 +43,8 @@ module Puppeteer
34
43
 
35
44
  # Raised when a user context has been closed
36
45
  class UserContextClosedError < DisposedError
46
+ # @rbs reason: String
47
+ # @rbs return: void
37
48
  def initialize(reason)
38
49
  super('User context', reason)
39
50
  end
@@ -41,6 +52,8 @@ module Puppeteer
41
52
 
42
53
  # Raised when a user prompt has been closed
43
54
  class UserPromptClosedError < DisposedError
55
+ # @rbs reason: String
56
+ # @rbs return: void
44
57
  def initialize(reason)
45
58
  super('User prompt', reason)
46
59
  end
@@ -48,6 +61,8 @@ module Puppeteer
48
61
 
49
62
  # Raised when a session has ended
50
63
  class SessionEndedError < DisposedError
64
+ # @rbs reason: String
65
+ # @rbs return: void
51
66
  def initialize(reason)
52
67
  super('Session', reason)
53
68
  end
@@ -55,6 +70,8 @@ module Puppeteer
55
70
 
56
71
  # Raised when a browser has been disconnected
57
72
  class BrowserDisconnectedError < DisposedError
73
+ # @rbs reason: String
74
+ # @rbs return: void
58
75
  def initialize(reason)
59
76
  super('Browser', reason)
60
77
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ # rbs_inline: enabled
2
3
 
3
4
  module Puppeteer
4
5
  module Bidi
@@ -6,22 +7,25 @@ module Puppeteer
6
7
  # EventEmitter provides event subscription and emission capabilities
7
8
  # Similar to Node.js EventEmitter but simpler
8
9
  class EventEmitter
10
+ # @rbs return: void
9
11
  def initialize
10
12
  @listeners = Hash.new { |h, k| h[k] = [] }
11
13
  @disposed = false
12
14
  end
13
15
 
14
16
  # Register an event listener
15
- # @param event [Symbol, String] Event name
16
- # @param block [Proc] Event handler
17
+ # @rbs event: Symbol | String -- Event name
18
+ # @rbs &block: (untyped) -> void -- Event handler
19
+ # @rbs return: void
17
20
  def on(event, &block)
18
21
  return if @disposed
19
22
  @listeners[event.to_sym] << block
20
23
  end
21
24
 
22
25
  # Register a one-time event listener
23
- # @param event [Symbol, String] Event name
24
- # @param block [Proc] Event handler
26
+ # @rbs event: Symbol | String -- Event name
27
+ # @rbs &block: (untyped) -> void -- Event handler
28
+ # @rbs return: void
25
29
  def once(event, &block)
26
30
  return if @disposed
27
31
  wrapper = lambda do |*args|
@@ -32,8 +36,9 @@ module Puppeteer
32
36
  end
33
37
 
34
38
  # Remove an event listener
35
- # @param event [Symbol, String] Event name
36
- # @param block [Proc] Event handler to remove (optional)
39
+ # @rbs event: Symbol | String -- Event name
40
+ # @rbs &block: ((untyped) -> void)? -- Event handler to remove
41
+ # @rbs return: void
37
42
  def off(event, &block)
38
43
  event_sym = event.to_sym
39
44
  if block
@@ -44,7 +49,8 @@ module Puppeteer
44
49
  end
45
50
 
46
51
  # Remove all listeners for an event or all events
47
- # @param event [Symbol, String, nil] Event name (optional)
52
+ # @rbs event: (Symbol | String)? -- Event name
53
+ # @rbs return: void
48
54
  def remove_all_listeners(event = nil)
49
55
  if event
50
56
  @listeners.delete(event.to_sym)
@@ -54,8 +60,9 @@ module Puppeteer
54
60
  end
55
61
 
56
62
  # Emit an event to all registered listeners
57
- # @param event [Symbol, String] Event name
58
- # @param data [Object] Event data
63
+ # @rbs event: Symbol | String -- Event name
64
+ # @rbs data: untyped -- Event data
65
+ # @rbs return: void
59
66
  def emit(event, data = nil)
60
67
  return if @disposed
61
68
  listeners = @listeners[event.to_sym].dup
@@ -69,11 +76,13 @@ module Puppeteer
69
76
  end
70
77
 
71
78
  # Dispose the event emitter
79
+ # @rbs return: void
72
80
  def dispose
73
81
  @disposed = true
74
82
  @listeners.clear
75
83
  end
76
84
 
85
+ # @rbs return: bool
77
86
  def disposed?
78
87
  @disposed
79
88
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ # rbs_inline: enabled
2
3
 
3
4
  module Puppeteer
4
5
  module Bidi
@@ -8,8 +9,8 @@ module Puppeteer
8
9
  include Disposable::DisposableMixin
9
10
 
10
11
  # Create a navigation instance
11
- # @param browsing_context [BrowsingContext] The browsing context
12
- # @return [Navigation] New navigation instance
12
+ # @rbs browsing_context: BrowsingContext -- The browsing context
13
+ # @rbs return: Navigation -- New navigation instance
13
14
  def self.from(browsing_context)
14
15
  navigation = new(browsing_context)
15
16
  navigation.send(:initialize_navigation)
@@ -28,7 +29,7 @@ module Puppeteer
28
29
  end
29
30
 
30
31
  # Get the nested navigation if any
31
- # @return [Navigation, nil] Nested navigation
32
+ # @rbs return: Navigation? -- Nested navigation
32
33
  def navigation
33
34
  @navigation
34
35
  end