puppeteer-ruby 0.45.6 → 0.50.0.alpha5

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 (98) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -3
  3. data/AGENTS.md +169 -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 +575 -0
  9. data/CLAUDE/rbs_type_checking.md +101 -0
  10. data/CLAUDE/spec_migration_plans.md +1041 -0
  11. data/CLAUDE/testing.md +278 -0
  12. data/CLAUDE.md +242 -0
  13. data/README.md +8 -0
  14. data/Rakefile +7 -0
  15. data/Steepfile +28 -0
  16. data/docs/api_coverage.md +105 -56
  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 +231 -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 +162 -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 +58 -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/mouse.rb +273 -64
  54. data/lib/puppeteer/network_event_manager.rb +7 -0
  55. data/lib/puppeteer/network_manager.rb +393 -112
  56. data/lib/puppeteer/page/screenshot_task_queue.rb +14 -4
  57. data/lib/puppeteer/page.rb +568 -226
  58. data/lib/puppeteer/puppeteer.rb +171 -64
  59. data/lib/puppeteer/query_handler_manager.rb +112 -16
  60. data/lib/puppeteer/reactor_runner.rb +247 -0
  61. data/lib/puppeteer/remote_object.rb +127 -47
  62. data/lib/puppeteer/target.rb +74 -27
  63. data/lib/puppeteer/task_manager.rb +3 -1
  64. data/lib/puppeteer/timeout_helper.rb +6 -10
  65. data/lib/puppeteer/touch_handle.rb +39 -0
  66. data/lib/puppeteer/touch_screen.rb +72 -22
  67. data/lib/puppeteer/tracing.rb +3 -3
  68. data/lib/puppeteer/version.rb +1 -1
  69. data/lib/puppeteer/wait_task.rb +264 -101
  70. data/lib/puppeteer/web_socket.rb +2 -2
  71. data/lib/puppeteer/web_socket_transport.rb +91 -27
  72. data/lib/puppeteer/web_worker.rb +175 -0
  73. data/lib/puppeteer.rb +20 -4
  74. data/puppeteer-ruby.gemspec +15 -11
  75. data/sig/_external.rbs +8 -0
  76. data/sig/_supplementary.rbs +314 -0
  77. data/sig/puppeteer/browser.rbs +166 -0
  78. data/sig/puppeteer/cdp_session.rbs +64 -0
  79. data/sig/puppeteer/dialog.rbs +41 -0
  80. data/sig/puppeteer/element_handle.rbs +305 -0
  81. data/sig/puppeteer/execution_context.rbs +87 -0
  82. data/sig/puppeteer/frame.rbs +226 -0
  83. data/sig/puppeteer/http_request.rbs +214 -0
  84. data/sig/puppeteer/http_response.rbs +89 -0
  85. data/sig/puppeteer/js_handle.rbs +64 -0
  86. data/sig/puppeteer/keyboard.rbs +40 -0
  87. data/sig/puppeteer/mouse.rbs +113 -0
  88. data/sig/puppeteer/page.rbs +515 -0
  89. data/sig/puppeteer/puppeteer.rbs +98 -0
  90. data/sig/puppeteer/remote_object.rbs +78 -0
  91. data/sig/puppeteer/touch_handle.rbs +21 -0
  92. data/sig/puppeteer/touch_screen.rbs +35 -0
  93. data/sig/puppeteer/web_worker.rbs +83 -0
  94. metadata +116 -45
  95. data/CHANGELOG.md +0 -397
  96. data/lib/puppeteer/concurrent_ruby_utils.rb +0 -81
  97. data/lib/puppeteer/firefox_target_manager.rb +0 -157
  98. data/lib/puppeteer/launcher/firefox.rb +0 -453
data/CHANGELOG.md DELETED
@@ -1,397 +0,0 @@
1
- ### main [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.45.6...main)]
2
-
3
- - xxx
4
-
5
- ### 0.45.6 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.45.5...0.45.6)]
6
-
7
- Bugfix:
8
-
9
- - Fix puppeteer-ruby to work with Firefox >= 129. Note that CDP support for Firefox is already ended. [ref](https://fxdx.dev/deprecating-cdp-support-in-firefox-embracing-the-future-with-webdriver-bidi/)
10
-
11
- ### 0.45.5 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.45.4...0.45.5)]
12
-
13
- Bugfix:
14
-
15
- - Relax concurrent-ruby's dependency for Rails 7.2 compatibility. ([#333](https://github.com/YusukeIwaki/puppeteer-ruby/pull/333))
16
-
17
- ### 0.45.4 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.45.3...0.45.4)]
18
-
19
- Bugfix
20
-
21
- - Fixed to work with Windows Chrome browser on WSL v1. ([#327](https://github.com/YusukeIwaki/puppeteer-ruby/pull/327))
22
-
23
- ### 0.45.3 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.45.2...0.45.3)]
24
-
25
- Bugfix
26
-
27
- - Fix hang on the size using ServiceWorker.
28
-
29
- ### 0.45.2 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.45.1...0.45.2)]
30
-
31
- Experimental feature
32
-
33
- - Introduce `PUPPETEER_RUBY_NO_SANDBOX` for Docker users.
34
-
35
- ### 0.45.1 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.45.0...0.45.1)]
36
-
37
- Bugfix
38
-
39
- - Fix screenshot `full_page` option
40
-
41
- ### 0.45.0 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.44.3...0.45.0)]
42
-
43
- - Port Puppeteer v18.0-v19.5 features except for 3 features below (If wanted, please create a issue of the feature request :)
44
- - Extra headers for Puppeteer.connect ([#9314](https://github.com/puppeteer/puppeteer/pull/9314))
45
- - Improvement of missing product message ([#9207](https://github.com/puppeteer/puppeteer/pull/9207))
46
- - Configuration file (.puppeteerrc/puppeteer.config.js) ([#9140](https://github.com/puppeteer/puppeteer/pull/9140)).
47
-
48
- ### 0.44.3 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.44.2...0.44.3)]
49
-
50
- Bugfix
51
-
52
- - Revive Firefox automation :tada:
53
-
54
- ### 0.44.2 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.44.1...0.44.2)]
55
-
56
- Bugfix
57
-
58
- - Fix warning on `Page#wait_for_navigation`
59
-
60
- ### 0.44.1 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.44.0...0.44.1)]
61
-
62
- Bugfix
63
-
64
- - Ensure closing websocket [#269](https://github.com/YusukeIwaki/puppeteer-ruby/pull/269)
65
-
66
- ### 0.44.0 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.43.1...0.44.0)]
67
-
68
- - Port Puppeteer v17.0-v17.1 features.
69
- - `wait_for_selector` no longer accept `root` parameter.
70
-
71
- ### 0.43.1 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.43.0...0.43.1)]
72
-
73
- - Port Puppeteer v16.1 features, including bugfix and XPath query handler.
74
-
75
- ### 0.43.0 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.42.0...0.43.0)]
76
-
77
- - Port Puppeteer v16.0 features. Increasing stability.
78
-
79
- ### 0.42.0 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.41.0...0.42.0)]
80
-
81
- - Port Puppeteer v15.3-v15.5 features, including `Frame#page`
82
-
83
- ### 0.41.0 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.40.7...0.41.0)]
84
-
85
- - Port Puppeteer v14.0-v15.2 features, including `ElementHandle#wait_for_xpath`
86
-
87
- ### 0.40.7 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.40.6...0.40.7)]
88
-
89
- - Port Puppeteer v13.6-v13.7 features.
90
-
91
- ### 0.40.6 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.40.5...0.40.6)]
92
-
93
- - Port Puppeteer v13.1-v13.5 features mainly for request interception.
94
-
95
- ### 0.40.5 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.40.4...0.40.5)]
96
-
97
- Bugfix:
98
-
99
- - Port Puppeteer v13.1-v13.5 bugfixes mainly for OOPIFs.
100
-
101
- ### 0.40.4 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.40.3...0.40.4)]
102
-
103
- Bugfix:
104
-
105
- - Fix warning on handling console message.
106
-
107
- ### 0.40.3 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.40.2...0.40.3)]
108
-
109
- Bugfix:
110
-
111
- - Prevent `Ctrl+C` from stopping Chrome [#196](https://github.com/YusukeIwaki/puppeteer-ruby/pull/196)
112
-
113
- ### 0.40.2 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.40.1...0.40.2)]
114
-
115
- Bugfix:
116
-
117
- - Fix crash on setting response listener [#195](https://github.com/YusukeIwaki/puppeteer-ruby/pull/195)
118
-
119
- ### 0.40.1 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.40.0...0.40.1)]
120
-
121
- Bugfix:
122
-
123
- - Fix error on reload [#190](https://github.com/YusukeIwaki/puppeteer-ruby/pull/190)
124
- - Fix error message on failing to find Chrome executable.
125
- - Fix apidoc
126
-
127
- ### 0.40.0 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.39.0...0.40.0)]
128
-
129
- New features:
130
-
131
- - Puppeteer 13.0, 13.1 functionalities
132
- - Support Ruby 3.1
133
-
134
- ### 0.39.0 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.38.0...0.39.0)]
135
-
136
- New features:
137
-
138
- - Puppeteer 12.0 functionalities
139
-
140
- ### 0.38.0 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.37.4...0.38.0)]
141
-
142
- New features:
143
-
144
- - Puppeteer 11.0 functionalities
145
- - OOP iframe support
146
- - Customize debugging port
147
- - HTTPRequest#initiator
148
- - Customize temp directory for user data
149
- - Add webp to screenshot quality option allow list
150
-
151
- ### 0.37.4 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.37.3...0.37.4)]
152
-
153
- Bugfix:
154
-
155
- - Fix ElementHandle#screenshot to work.
156
-
157
- ### 0.37.3 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.37.2...0.37.3)]
158
-
159
- Improvement:
160
-
161
- - Improve the logic of detection of Chrome/Firefox executable path on Linux.
162
-
163
- ### 0.37.2 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.37.1...0.37.2)]
164
-
165
- Bugfix:
166
-
167
- - `timeout: 0` did set the timeout value to zero. Now it disables the timeout as expected.
168
-
169
- ### 0.37.1 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.37.0...0.37.1)]
170
-
171
- Bugfix:
172
-
173
- - Fix handle_SIGINT, handle_SIGTERM, handle_SIGHUP options to work with `false` value specified.
174
-
175
- ### 0.37.0 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.36.0...0.37.0)]
176
-
177
- New features:
178
-
179
- - Some features introduced in Puppeteer 10.4
180
-
181
- ### 0.36.0 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.35.1...0.36.0)]
182
-
183
- New features:
184
-
185
- - Drag and Drop feature introduced in Puppeteer 10.1
186
- - `Page#emulateNetworkConditions`, `Page#emulateCPUThrottling`
187
- - `Page#exposeFunction`
188
- - Metrics
189
-
190
- ### 0.35.1 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.35.0...0.35.1)]
191
-
192
- New features:
193
-
194
- - Allow Rails users to use this library without `require 'puppeteer'`.
195
-
196
- ### 0.35.0 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.34.3...0.35.0)]
197
-
198
- New features:
199
-
200
- - Add `channel` parameter for Puppeteer.launch. Now `channel: chrome` or `channel: chrome-canary` (chrome-beta, chrome-dev is also available) automatically detects the executablePath of Google Chrome. Windows/macOS users can also use `channel: msedge`.
201
-
202
- ### 0.34.3 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.34.2...0.34.3)]
203
-
204
- Bugfix:
205
-
206
- - Fix wait_for_xxx's timeout error type.
207
-
208
- ### 0.34.2 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.34.1...0.34.2)]
209
-
210
- New features:
211
-
212
- - Add `Page#bring_to_front`.
213
-
214
- ### 0.34.1 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.34.0...0.34.1)]
215
-
216
- Bugfix:
217
-
218
- - Fix `Page#pdf` to work without `path` parameter.
219
-
220
- ### 0.34.0 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.33.0...0.34.0)]
221
-
222
- New features:
223
-
224
- - Sync API with block
225
-
226
- ### 0.33.0 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.32.4...0.33.0)]
227
-
228
- NOTE: Requires Ruby version >= 2.6 explicitly since this version.
229
-
230
- Bugfix:
231
-
232
- - Fix PDF options to work correctly on decimal numbers specified.
233
-
234
- ### 0.32.4 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.32.3...0.32.4)]
235
-
236
- Bugfix:
237
-
238
- - Fix `#type_text` to input '<' correctly.
239
-
240
- ### 0.32.3 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.32.2...0.32.3)]
241
-
242
- Bugfix:
243
-
244
- - Fix puppeteer-ruby to work on Rails in development mode.
245
-
246
- ### 0.32.2 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.32.1...0.32.2)]
247
-
248
- Bugfix:
249
-
250
- - Fix full_page option in screenshot.
251
-
252
- ### 0.32.1 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.32.0...0.32.1)]
253
-
254
- Bugfix:
255
-
256
- - Fix WebSocket to work with `wss://...` endpoint (ex. browserless.io)
257
-
258
- ### 0.32.0 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.31.6...0.32.0)]
259
-
260
- New features:
261
-
262
- - Tracing
263
- - JS/CSS coverages
264
-
265
- Improvement:
266
-
267
- - Increase stability [#92](https://github.com/YusukeIwaki/puppeteer-ruby/pull/92)
268
-
269
- ### 0.31.6 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.31.5...0.31.6)]
270
-
271
- Improvement:
272
-
273
- - Increase stability [#87](https://github.com/YusukeIwaki/puppeteer-ruby/pull/87)
274
-
275
- ### 0.31.5 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.31.4...0.31.5)]
276
-
277
- Bugfix:
278
-
279
- - Fix file uploading to work without crash.
280
-
281
- ### 0.31.4 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.31.3...0.31.4)]
282
-
283
- Bugfix:
284
-
285
- - Fix PDF options (format, margin, omit_background) to work.
286
-
287
- ### 0.31.3 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.31.1...0.31.3)]
288
-
289
- Bugfix:
290
-
291
- - Fix `wait_for_selector` to work. _It is strongly recommended to update for 0.29.0-0.31.x users._
292
-
293
- ### 0.31.1 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.31.0...0.31.1)]
294
-
295
- Bugfix:
296
-
297
- - Fix `Page#pdf` to work on Windows.
298
-
299
- ### 0.31.0 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.30.0...0.31.0)]
300
-
301
- New features:
302
-
303
- - Now puppeteer-ruby is compatible with Windows
304
-
305
- Bugfix:
306
-
307
- - Fix `Page#add_script_tag` and `Page#add_style_tag` to work
308
-
309
- ### 0.30.0 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.29.0...0.30.0)]
310
-
311
- New features:
312
-
313
- - S, SS, Seval, SSeval is renamed to query_selector, query_selector_all, eval_on_selector, eval_on_selector_all
314
-
315
- ### 0.29.0 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.28.1...0.29.0)]
316
-
317
- New features:
318
-
319
- - Add `AriaQueryHandler`. Now we can use "aria/...." for selectors.
320
-
321
- ### 0.28.1 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.0.27...0.28.1)]
322
-
323
- New features:
324
-
325
- - Add `Page#emulate_idle_state`
326
- - Change versioning rule.
327
-
328
- ### 0.0.27 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.0.26...0.0.27)]
329
-
330
- New features:
331
-
332
- - Now puppeteer-ruby is Ruby 3.0 compatible!
333
-
334
- ### 0.0.26 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.0.25...0.0.26)]
335
-
336
- Bugfix:
337
-
338
- - Fix `Page#screenshot` working correctly with `quality` parameter.
339
-
340
- ### 0.0.25 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.0.23...0.0.25)]
341
-
342
- New feature:
343
-
344
- - **Cookie** feature: `Page#set_cookie`, `Page#cookies`
345
-
346
- ### 0.0.23 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.0.22...0.0.23)]
347
-
348
- New feature:
349
-
350
- - **GeoLocation** feature
351
- - grant/clear permission
352
-
353
- Bugfix/Improvement:
354
-
355
- - Refactoring for events ([#31](https://github.com/YusukeIwaki/puppeteer-ruby/pull/31))
356
- - Improve SEND/RECV handling in CDPSession ([#34](https://github.com/YusukeIwaki/puppeteer-ruby/pull/34))
357
-
358
- ### 0.0.22 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.0.21...0.0.22)]
359
-
360
- Bugfix
361
-
362
- - Make `Puppeteer#default_args` to work
363
- - Respect Firefox launch options
364
- - Respect `default_viewport: nil`
365
-
366
- ### 0.0.21 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.0.20...0.0.21)]
367
-
368
- Bugfix/Improvement:
369
-
370
- - Update DeviceDescriptors (list of emulatable devices)
371
- - Fix bug on inputing "(" ([#25](https://github.com/YusukeIwaki/puppeteer-ruby/pull/25))
372
-
373
- ### 0.0.20 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.0.19...0.0.20)]
374
-
375
- New feature
376
-
377
- - Dialog-handling feature
378
-
379
- ### 0.0.19 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.0.18...0.0.19)]
380
-
381
- New feature
382
-
383
- - **Firefox support**
384
-
385
- Bugfix/Improvement
386
-
387
- - Allow `Page#keyboard` with block ([#18](https://github.com/YusukeIwaki/puppeteer-ruby/pull/18))
388
-
389
- ### 0.0.18 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.0.17...0.0.18)]
390
-
391
- New feature
392
-
393
- - **Firefox support**
394
-
395
- Bugfix/Improvement
396
-
397
- - Allow `Page#keyboard` with block ([#18](https://github.com/YusukeIwaki/puppeteer-ruby/pull/18))
@@ -1,81 +0,0 @@
1
- # utility methods for Concurrent::Promises.
2
- module Puppeteer::ConcurrentRubyUtils
3
- module ConcurrentPromisesFutureExtension
4
- # Extension for describing 2 concurrent tasks smartly.
5
- #
6
- # page.async_wait_for_navigation.with_waiting_for_complete do
7
- # page.click('#submit')
8
- # end
9
- def with_waiting_for_complete(&block)
10
- async_block_call = Concurrent::Promises.delay do
11
- block.call
12
- rescue => err
13
- Logger.new($stderr).warn(err)
14
- raise err
15
- end
16
-
17
- Concurrent::Promises.zip(self, async_block_call).value!.first
18
- end
19
- end
20
-
21
- # wait for all promises.
22
- # REMARK: This method doesn't assure the order of calling.
23
- # for example, await_all(async1, async2) calls calls2 -> calls1 often.
24
- def await_all(*args)
25
- if args.length == 1 && args.first.is_a?(Enumerable)
26
- await_all(*args.first)
27
- else
28
- if args.any? { |arg| !arg.is_a?(Concurrent::Promises::Future) }
29
- raise ArgumentError.new("All argument must be a Future: #{args}")
30
- end
31
-
32
- Concurrent::Promises.zip(*args).value!
33
- end
34
- end
35
-
36
- # wait for first promises.
37
- # REMARK: This method doesn't assure the order of calling.
38
- # for example, await_all(async1, async2) calls calls2 -> calls1 often.
39
- def await_any(*args)
40
- if args.length == 1 && args.first.is_a?(Enumerable)
41
- await_any(*args.first)
42
- else
43
- if args.any? { |arg| !arg.is_a?(Concurrent::Promises::Future) }
44
- raise ArgumentError.new("All argument must be a Future: #{args}")
45
- end
46
-
47
- Concurrent::Promises.any(*args).value!
48
- end
49
- end
50
-
51
- # blocking get value of Future.
52
- def await(future_or_value)
53
- if future_or_value.is_a?(Concurrent::Promises::Future)
54
- future_or_value.value!
55
- else
56
- future_or_value
57
- end
58
- end
59
-
60
- def future(*args, &block)
61
- Concurrent::Promises.future(*args) do |*block_args|
62
- block.call(*block_args)
63
- rescue Puppeteer::TimeoutError
64
- # suppress error logging
65
- raise
66
- rescue => err
67
- Logger.new($stderr).warn(err)
68
- raise err
69
- end.extend(ConcurrentPromisesFutureExtension)
70
- end
71
-
72
- def resolvable_future(&block)
73
- future = Concurrent::Promises.resolvable_future
74
- if block
75
- block.call(future)
76
- end
77
- future.extend(ConcurrentPromisesFutureExtension)
78
- end
79
- end
80
-
81
- include Puppeteer::ConcurrentRubyUtils
@@ -1,157 +0,0 @@
1
- # FirefoxTargetManager implements target management using
2
- # `Target.setDiscoverTargets` without using auto-attach. It, therefore, creates
3
- # targets that lazily establish their CDP sessions.
4
- #
5
- # Although the approach is potentially flaky, there is no other way for Firefox
6
- # because Firefox's CDP implementation does not support auto-attach.
7
- #
8
- # Firefox does not support targetInfoChanged and detachedFromTarget events:
9
- # - https://bugzilla.mozilla.org/show_bug.cgi?id=1610855
10
- # - https://bugzilla.mozilla.org/show_bug.cgi?id=1636979
11
- class Puppeteer::FirefoxTargetManager
12
- include Puppeteer::EventCallbackable
13
-
14
- def initialize(connection:, target_factory:, target_filter_callback:)
15
- @discovered_targets_by_target_id = {}
16
- @available_targets_by_target_id = {}
17
- @available_targets_by_session_id = {}
18
- @ignored_targets = Set.new
19
- @target_ids_for_init = Set.new
20
-
21
- @connection = connection
22
- @target_filter_callback = target_filter_callback
23
- @target_factory = target_factory
24
- @target_interceptors = {}
25
- @initialize_promise = resolvable_future
26
-
27
- @connection_event_listeners = []
28
- @connection_event_listeners << @connection.add_event_listener(
29
- 'Target.targetCreated',
30
- &method(:handle_target_created)
31
- )
32
- @connection_event_listeners << @connection.add_event_listener(
33
- 'Target.targetDestroyed',
34
- &method(:handle_target_destroyed)
35
- )
36
- @connection_event_listeners << @connection.add_event_listener(
37
- 'sessiondetached',
38
- &method(:handle_session_detached)
39
- )
40
-
41
- setup_attachment_listeners(@connection)
42
- end
43
-
44
- def add_target_interceptor(client, interceptor)
45
- interceptors = @target_interceptors[client] || []
46
- interceptors << interceptor
47
- @target_interceptors[client] = interceptors
48
- end
49
-
50
- def remove_target_interceptor(client, interceptor)
51
- @target_interceptors[client]&.delete_if { |current| current == interceptor }
52
- end
53
-
54
- private def setup_attachment_listeners(session)
55
- @attachment_listener_ids ||= {}
56
- @attachment_listener_ids[session] ||= []
57
-
58
- @attachment_listener_ids[session] << session.add_event_listener('Target.attachedToTarget') do |event|
59
- handle_attached_to_target(session, event)
60
- end
61
- end
62
-
63
- private def handle_session_detached(session)
64
- remove_session_listeners(session)
65
- @target_interceptors.delete(session)
66
- end
67
-
68
- private def remove_session_listeners(session)
69
- listener_ids = @attachment_listener_ids&.delete(session)
70
- return if !listener_ids || listener_ids.empty?
71
- session.remove_event_listener(*listener_ids)
72
- end
73
-
74
- def available_targets
75
- @available_targets_by_target_id
76
- end
77
-
78
- def dispose
79
- @connection.remove_event_listener(*@connection_event_listeners)
80
- remove_session_listeners(@connection)
81
- end
82
-
83
- def init
84
- @connection.send_message('Target.setDiscoverTargets', discover: true)
85
- @target_ids_for_init.merge(@discovered_targets_by_target_id.keys)
86
- @initialize_promise.value!
87
- end
88
-
89
- private def handle_target_created(event)
90
- target_info = Puppeteer::Target::TargetInfo.new(event['targetInfo'])
91
- return if @discovered_targets_by_target_id[target_info.target_id]
92
- @discovered_targets_by_target_id[target_info.target_id] = target_info
93
-
94
- if target_info.type == 'browser' && target_info.attached
95
- target = @target_factory.call(target_info, nil)
96
- @available_targets_by_target_id[target_info.target_id] = target
97
- finish_initialization_if_ready(target.target_id)
98
- end
99
-
100
- unless @target_filter_callback.call(target_info)
101
- @ignored_targets << target_info.target_id
102
- finish_initialization_if_ready(target_info.target_id)
103
- return
104
- end
105
-
106
- target = @target_factory.call(target_info, nil)
107
- @available_targets_by_target_id[target_info.target_id] = target
108
- emit_event(TargetManagerEmittedEvents::TargetAvailable, target)
109
- finish_initialization_if_ready(target.target_id)
110
- end
111
-
112
- private def handle_target_destroyed(event)
113
- target_id = event['targetId']
114
- target_info = @discovered_targets_by_target_id.delete(target_id)
115
- finish_initialization_if_ready(target_id)
116
-
117
- target = @available_targets_by_target_id.delete(target_id)
118
- emit_event(TargetManagerEmittedEvents::TargetGone, target)
119
- end
120
-
121
- class SessionNotCreatedError < StandardError ; end
122
-
123
- private def handle_attached_to_target(parent_session, event)
124
- target_info = Puppeteer::Target::TargetInfo.new(event['targetInfo'])
125
- session_id = event['sessionId']
126
- session = @connection.session(session_id)
127
- unless session
128
- raise SessionNotCreatedError.new("Session #{session_id} was not created.")
129
- end
130
-
131
- target = @available_targets_by_target_id[target_info.target_id] or raise "Target #{target_info.target_id} is missing"
132
- setup_attachment_listeners(session)
133
-
134
- @available_targets_by_session_id[session_id] = target
135
-
136
- @target_interceptors[parent_session]&.each do |hook|
137
- if parent_session.is_a?(Puppeteer::Connection)
138
- hook.call(target, nil)
139
- else
140
- # Sanity check: if parent session is not a connection, it should be
141
- # present in #attachedTargetsBySessionId.
142
- available_target = @available_targets_by_session_id[parent_session.id]
143
- unless available_target
144
- raise "No target found for the parent session: #{parent_session.id}"
145
- end
146
- hook.call(target, available_target)
147
- end
148
- end
149
- end
150
-
151
- private def finish_initialization_if_ready(target_id)
152
- @target_ids_for_init.delete(target_id)
153
- if @target_ids_for_init.empty?
154
- @initialize_promise.fulfill(nil) unless @initialize_promise.resolved?
155
- end
156
- end
157
- end