playwright-ruby-client 0.0.8 → 1.58.1.alpha1

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 (209) hide show
  1. checksums.yaml +4 -4
  2. data/AGENTS.md +4 -0
  3. data/CLAUDE/api_generation.md +28 -0
  4. data/CLAUDE/ci_expectations.md +23 -0
  5. data/CLAUDE/gem_release_flow.md +39 -0
  6. data/CLAUDE/past_upgrade_pr_patterns.md +42 -0
  7. data/CLAUDE/playwright_upgrade_workflow.md +35 -0
  8. data/CLAUDE/rspec_debugging.md +30 -0
  9. data/CLAUDE/unimplemented_examples.md +18 -0
  10. data/CLAUDE.md +32 -0
  11. data/CONTRIBUTING.md +5 -0
  12. data/README.md +60 -16
  13. data/documentation/README.md +33 -0
  14. data/documentation/babel.config.js +3 -0
  15. data/documentation/docs/api/api_request.md +7 -0
  16. data/documentation/docs/api/api_request_context.md +298 -0
  17. data/documentation/docs/api/api_response.md +114 -0
  18. data/documentation/docs/api/browser.md +237 -0
  19. data/documentation/docs/api/browser_context.md +503 -0
  20. data/documentation/docs/api/browser_type.md +184 -0
  21. data/documentation/docs/api/cdp_session.md +44 -0
  22. data/documentation/docs/api/clock.md +154 -0
  23. data/documentation/docs/api/console_message.md +85 -0
  24. data/documentation/docs/api/dialog.md +84 -0
  25. data/documentation/docs/api/download.md +111 -0
  26. data/documentation/docs/api/element_handle.md +694 -0
  27. data/documentation/docs/api/experimental/_category_.yml +3 -0
  28. data/documentation/docs/api/experimental/android.md +42 -0
  29. data/documentation/docs/api/experimental/android_device.md +109 -0
  30. data/documentation/docs/api/experimental/android_input.md +43 -0
  31. data/documentation/docs/api/experimental/android_socket.md +7 -0
  32. data/documentation/docs/api/experimental/android_web_view.md +7 -0
  33. data/documentation/docs/api/file_chooser.md +53 -0
  34. data/documentation/docs/api/frame.md +1218 -0
  35. data/documentation/docs/api/frame_locator.md +348 -0
  36. data/documentation/docs/api/js_handle.md +121 -0
  37. data/documentation/docs/api/keyboard.md +170 -0
  38. data/documentation/docs/api/locator.md +1495 -0
  39. data/documentation/docs/api/locator_assertions.md +827 -0
  40. data/documentation/docs/api/mouse.md +86 -0
  41. data/documentation/docs/api/page.md +1946 -0
  42. data/documentation/docs/api/page_assertions.md +65 -0
  43. data/documentation/docs/api/playwright.md +66 -0
  44. data/documentation/docs/api/request.md +255 -0
  45. data/documentation/docs/api/response.md +176 -0
  46. data/documentation/docs/api/route.md +205 -0
  47. data/documentation/docs/api/selectors.md +63 -0
  48. data/documentation/docs/api/touchscreen.md +22 -0
  49. data/documentation/docs/api/tracing.md +129 -0
  50. data/documentation/docs/api/web_socket.md +51 -0
  51. data/documentation/docs/api/worker.md +83 -0
  52. data/documentation/docs/article/api_coverage.mdx +11 -0
  53. data/documentation/docs/article/getting_started.md +161 -0
  54. data/documentation/docs/article/guides/_category_.yml +3 -0
  55. data/documentation/docs/article/guides/download_playwright_driver.md +55 -0
  56. data/documentation/docs/article/guides/inspector.md +31 -0
  57. data/documentation/docs/article/guides/launch_browser.md +121 -0
  58. data/documentation/docs/article/guides/playwright_on_alpine_linux.md +112 -0
  59. data/documentation/docs/article/guides/rails_integration.md +278 -0
  60. data/documentation/docs/article/guides/rails_integration_with_null_driver.md +145 -0
  61. data/documentation/docs/article/guides/recording_video.md +79 -0
  62. data/documentation/docs/article/guides/rspec_integration.md +59 -0
  63. data/documentation/docs/article/guides/semi_automation.md +71 -0
  64. data/documentation/docs/article/guides/use_storage_state.md +78 -0
  65. data/documentation/docs/include/api_coverage.md +671 -0
  66. data/documentation/docusaurus.config.js +114 -0
  67. data/documentation/package.json +39 -0
  68. data/documentation/sidebars.js +15 -0
  69. data/documentation/src/components/HomepageFeatures.js +61 -0
  70. data/documentation/src/components/HomepageFeatures.module.css +13 -0
  71. data/documentation/src/css/custom.css +44 -0
  72. data/documentation/src/pages/index.js +49 -0
  73. data/documentation/src/pages/index.module.css +41 -0
  74. data/documentation/src/pages/markdown-page.md +7 -0
  75. data/documentation/static/.nojekyll +0 -0
  76. data/documentation/static/img/playwright-logo.svg +9 -0
  77. data/documentation/static/img/playwright-ruby-client.png +0 -0
  78. data/documentation/static/img/undraw_dropdown_menu.svg +1 -0
  79. data/documentation/static/img/undraw_web_development.svg +1 -0
  80. data/documentation/static/img/undraw_windows.svg +1 -0
  81. data/documentation/yarn.lock +9005 -0
  82. data/lib/playwright/{input_types/android_input.rb → android_input_impl.rb} +5 -1
  83. data/lib/playwright/api_implementation.rb +18 -0
  84. data/lib/playwright/api_response_impl.rb +77 -0
  85. data/lib/playwright/channel.rb +62 -1
  86. data/lib/playwright/channel_owner.rb +70 -7
  87. data/lib/playwright/channel_owners/android.rb +16 -3
  88. data/lib/playwright/channel_owners/android_device.rb +22 -66
  89. data/lib/playwright/channel_owners/api_request_context.rb +247 -0
  90. data/lib/playwright/channel_owners/artifact.rb +40 -0
  91. data/lib/playwright/channel_owners/binding_call.rb +70 -0
  92. data/lib/playwright/channel_owners/browser.rb +114 -22
  93. data/lib/playwright/channel_owners/browser_context.rb +589 -15
  94. data/lib/playwright/channel_owners/browser_type.rb +90 -1
  95. data/lib/playwright/channel_owners/cdp_session.rb +19 -0
  96. data/lib/playwright/channel_owners/dialog.rb +32 -0
  97. data/lib/playwright/channel_owners/element_handle.rb +107 -43
  98. data/lib/playwright/channel_owners/fetch_request.rb +8 -0
  99. data/lib/playwright/channel_owners/frame.rb +334 -104
  100. data/lib/playwright/channel_owners/js_handle.rb +9 -13
  101. data/lib/playwright/channel_owners/local_utils.rb +82 -0
  102. data/lib/playwright/channel_owners/page.rb +778 -95
  103. data/lib/playwright/channel_owners/playwright.rb +25 -30
  104. data/lib/playwright/channel_owners/request.rb +120 -18
  105. data/lib/playwright/channel_owners/response.rb +113 -0
  106. data/lib/playwright/channel_owners/route.rb +181 -0
  107. data/lib/playwright/channel_owners/stream.rb +30 -0
  108. data/lib/playwright/channel_owners/tracing.rb +117 -0
  109. data/lib/playwright/channel_owners/web_socket.rb +96 -0
  110. data/lib/playwright/channel_owners/worker.rb +46 -0
  111. data/lib/playwright/channel_owners/writable_stream.rb +14 -0
  112. data/lib/playwright/clock_impl.rb +67 -0
  113. data/lib/playwright/connection.rb +111 -63
  114. data/lib/playwright/console_message_impl.rb +29 -0
  115. data/lib/playwright/download_impl.rb +32 -0
  116. data/lib/playwright/errors.rb +42 -5
  117. data/lib/playwright/event_emitter.rb +17 -3
  118. data/lib/playwright/event_emitter_proxy.rb +49 -0
  119. data/lib/playwright/events.rb +10 -5
  120. data/lib/playwright/file_chooser_impl.rb +24 -0
  121. data/lib/playwright/frame_locator_impl.rb +66 -0
  122. data/lib/playwright/har_router.rb +89 -0
  123. data/lib/playwright/http_headers.rb +14 -0
  124. data/lib/playwright/input_files.rb +102 -15
  125. data/lib/playwright/javascript/expression.rb +7 -11
  126. data/lib/playwright/javascript/regex.rb +23 -0
  127. data/lib/playwright/javascript/source_url.rb +16 -0
  128. data/lib/playwright/javascript/value_parser.rb +108 -19
  129. data/lib/playwright/javascript/value_serializer.rb +47 -8
  130. data/lib/playwright/javascript/visitor_info.rb +26 -0
  131. data/lib/playwright/javascript.rb +2 -10
  132. data/lib/playwright/{input_types/keyboard.rb → keyboard_impl.rb} +6 -2
  133. data/lib/playwright/locator_assertions_impl.rb +571 -0
  134. data/lib/playwright/locator_impl.rb +544 -0
  135. data/lib/playwright/locator_utils.rb +136 -0
  136. data/lib/playwright/mouse_impl.rb +57 -0
  137. data/lib/playwright/page_assertions_impl.rb +154 -0
  138. data/lib/playwright/playwright_api.rb +102 -30
  139. data/lib/playwright/raw_headers.rb +61 -0
  140. data/lib/playwright/route_handler.rb +78 -0
  141. data/lib/playwright/select_option_values.rb +34 -13
  142. data/lib/playwright/selectors_impl.rb +45 -0
  143. data/lib/playwright/test.rb +102 -0
  144. data/lib/playwright/timeout_settings.rb +9 -4
  145. data/lib/playwright/touchscreen_impl.rb +14 -0
  146. data/lib/playwright/transport.rb +61 -10
  147. data/lib/playwright/url_matcher.rb +24 -2
  148. data/lib/playwright/utils.rb +48 -13
  149. data/lib/playwright/version.rb +2 -1
  150. data/lib/playwright/video.rb +54 -0
  151. data/lib/playwright/waiter.rb +166 -0
  152. data/lib/playwright/web_socket_client.rb +167 -0
  153. data/lib/playwright/web_socket_transport.rb +116 -0
  154. data/lib/playwright.rb +188 -11
  155. data/lib/playwright_api/android.rb +46 -11
  156. data/lib/playwright_api/android_device.rb +182 -31
  157. data/lib/playwright_api/android_input.rb +22 -13
  158. data/lib/playwright_api/android_socket.rb +18 -0
  159. data/lib/playwright_api/android_web_view.rb +24 -0
  160. data/lib/playwright_api/api_request.rb +26 -0
  161. data/lib/playwright_api/api_request_context.rb +311 -0
  162. data/lib/playwright_api/api_response.rb +92 -0
  163. data/lib/playwright_api/browser.rb +116 -103
  164. data/lib/playwright_api/browser_context.rb +290 -389
  165. data/lib/playwright_api/browser_type.rb +96 -118
  166. data/lib/playwright_api/cdp_session.rb +36 -39
  167. data/lib/playwright_api/clock.rb +121 -0
  168. data/lib/playwright_api/console_message.rb +35 -19
  169. data/lib/playwright_api/dialog.rb +53 -50
  170. data/lib/playwright_api/download.rb +49 -43
  171. data/lib/playwright_api/element_handle.rb +354 -402
  172. data/lib/playwright_api/file_chooser.rb +15 -18
  173. data/lib/playwright_api/frame.rb +703 -603
  174. data/lib/playwright_api/frame_locator.rb +285 -0
  175. data/lib/playwright_api/js_handle.rb +50 -76
  176. data/lib/playwright_api/keyboard.rb +67 -146
  177. data/lib/playwright_api/locator.rb +1304 -0
  178. data/lib/playwright_api/locator_assertions.rb +704 -0
  179. data/lib/playwright_api/mouse.rb +23 -29
  180. data/lib/playwright_api/page.rb +1196 -1176
  181. data/lib/playwright_api/page_assertions.rb +60 -0
  182. data/lib/playwright_api/playwright.rb +54 -122
  183. data/lib/playwright_api/request.rb +112 -74
  184. data/lib/playwright_api/response.rb +92 -20
  185. data/lib/playwright_api/route.rb +152 -62
  186. data/lib/playwright_api/selectors.rb +47 -61
  187. data/lib/playwright_api/touchscreen.rb +8 -2
  188. data/lib/playwright_api/tracing.rb +128 -0
  189. data/lib/playwright_api/web_socket.rb +43 -5
  190. data/lib/playwright_api/worker.rb +74 -34
  191. data/playwright.gemspec +14 -9
  192. data/sig/playwright.rbs +658 -0
  193. metadata +216 -50
  194. data/docs/api_coverage.md +0 -354
  195. data/lib/playwright/channel_owners/chromium_browser.rb +0 -8
  196. data/lib/playwright/channel_owners/chromium_browser_context.rb +0 -8
  197. data/lib/playwright/channel_owners/console_message.rb +0 -21
  198. data/lib/playwright/channel_owners/firefox_browser.rb +0 -8
  199. data/lib/playwright/channel_owners/selectors.rb +0 -4
  200. data/lib/playwright/channel_owners/webkit_browser.rb +0 -8
  201. data/lib/playwright/input_type.rb +0 -19
  202. data/lib/playwright/input_types/mouse.rb +0 -4
  203. data/lib/playwright/input_types/touchscreen.rb +0 -4
  204. data/lib/playwright/javascript/function.rb +0 -67
  205. data/lib/playwright/wait_helper.rb +0 -73
  206. data/lib/playwright_api/accessibility.rb +0 -93
  207. data/lib/playwright_api/binding_call.rb +0 -23
  208. data/lib/playwright_api/chromium_browser_context.rb +0 -57
  209. data/lib/playwright_api/video.rb +0 -24
@@ -0,0 +1,503 @@
1
+ ---
2
+ sidebar_position: 10
3
+ ---
4
+
5
+ # BrowserContext
6
+
7
+
8
+ BrowserContexts provide a way to operate multiple independent browser sessions.
9
+
10
+ If a page opens another page, e.g. with a `window.open` call, the popup will belong to the parent page's browser
11
+ context.
12
+
13
+ Playwright allows creating isolated non-persistent browser contexts with [Browser#new_context](./browser#new_context) method. Non-persistent browser
14
+ contexts don't write any browsing data to disk.
15
+
16
+ ```ruby
17
+ # create a new incognito browser context
18
+ context = browser.new_context
19
+
20
+ # create a new page inside context.
21
+ page = context.new_page
22
+ page.goto("https://example.com")
23
+
24
+ # dispose context once it is no longer needed.
25
+ context.close
26
+ ```
27
+
28
+ ## add_cookies
29
+
30
+ ```
31
+ def add_cookies(cookies)
32
+ ```
33
+
34
+
35
+ Adds cookies into this browser context. All pages within this context will have these cookies installed. Cookies can be
36
+ obtained via [BrowserContext#cookies](./browser_context#cookies).
37
+
38
+ **Usage**
39
+
40
+ ```ruby
41
+ browser_context.add_cookies([cookie_object1, cookie_object2])
42
+ ```
43
+
44
+ ## add_init_script
45
+
46
+ ```
47
+ def add_init_script(path: nil, script: nil)
48
+ ```
49
+
50
+
51
+ Adds a script which would be evaluated in one of the following scenarios:
52
+ - Whenever a page is created in the browser context or is navigated.
53
+ - Whenever a child frame is attached or navigated in any page in the browser context. In this case, the script is evaluated in the context of the newly attached frame.
54
+
55
+ The script is evaluated after the document was created but before any of its scripts were run. This is useful to amend
56
+ the JavaScript environment, e.g. to seed `Math.random`.
57
+
58
+ **Usage**
59
+
60
+ An example of overriding `Math.random` before the page loads:
61
+
62
+ ```ruby
63
+ # in your playwright script, assuming the preload.js file is in same directory.
64
+ browser_context.add_init_script(path: "preload.js")
65
+ ```
66
+
67
+ **NOTE**: The order of evaluation of multiple scripts installed via [BrowserContext#add_init_script](./browser_context#add_init_script) and
68
+ [Page#add_init_script](./page#add_init_script) is not defined.
69
+
70
+ ## background_pages
71
+
72
+ ```
73
+ def background_pages
74
+ ```
75
+
76
+ :::warning
77
+
78
+ Background pages have been removed from Chromium together with Manifest V2 extensions.
79
+
80
+ :::
81
+
82
+
83
+ Returns an empty list.
84
+
85
+ ## browser
86
+
87
+ ```
88
+ def browser
89
+ ```
90
+
91
+
92
+ Gets the browser instance that owns the context. Returns `null` if the context is created outside of normal browser, e.g. Android or Electron.
93
+
94
+ ## clear_cookies
95
+
96
+ ```
97
+ def clear_cookies(domain: nil, name: nil, path: nil)
98
+ ```
99
+
100
+
101
+ Removes cookies from context. Accepts optional filter.
102
+
103
+ **Usage**
104
+
105
+ ```ruby
106
+ context.clear_cookies()
107
+ context.clear_cookies(name: "session-id")
108
+ context.clear_cookies(domain: "my-origin.com")
109
+ context.clear_cookies(path: "/api/v1")
110
+ context.clear_cookies(name: "session-id", domain: "my-origin.com")
111
+ ```
112
+
113
+ ## clear_permissions
114
+
115
+ ```
116
+ def clear_permissions
117
+ ```
118
+
119
+
120
+ Clears all permission overrides for the browser context.
121
+
122
+ **Usage**
123
+
124
+ ```ruby
125
+ context = browser.new_context
126
+ context.grant_permissions(["clipboard-read"])
127
+
128
+ # do stuff ..
129
+
130
+ context.clear_permissions
131
+ ```
132
+
133
+ ## close
134
+
135
+ ```
136
+ def close(reason: nil)
137
+ ```
138
+
139
+
140
+ Closes the browser context. All the pages that belong to the browser context will be closed.
141
+
142
+ **NOTE**: The default browser context cannot be closed.
143
+
144
+ ## cookies
145
+
146
+ ```
147
+ def cookies(urls: nil)
148
+ ```
149
+
150
+
151
+ If no URLs are specified, this method returns all cookies. If URLs are specified, only cookies that affect those URLs
152
+ are returned.
153
+
154
+ ## expose_binding
155
+
156
+ ```
157
+ def expose_binding(name, callback, handle: nil)
158
+ ```
159
+
160
+
161
+ The method adds a function called `name` on the `window` object of every frame in every page in the context.
162
+ When called, the function executes `callback` and returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) which resolves to the return value of
163
+ `callback`. If the `callback` returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise), it will be awaited.
164
+
165
+ The first argument of the `callback` function contains information about the caller: `{ browserContext:
166
+ BrowserContext, page: Page, frame: Frame }`.
167
+
168
+ See [Page#expose_binding](./page#expose_binding) for page-only version.
169
+
170
+ **Usage**
171
+
172
+ An example of exposing page URL to all frames in all pages in the context:
173
+
174
+ ```ruby
175
+ browser_context.expose_binding("pageURL", ->(source) { source[:page].url })
176
+ page = browser_context.new_page
177
+
178
+ page.content = <<~HTML
179
+ <script>
180
+ async function onClick() {
181
+ document.querySelector('div').textContent = await window.pageURL();
182
+ }
183
+ </script>
184
+ <button onclick="onClick()">Click me</button>
185
+ <div></div>
186
+ HTML
187
+
188
+ page.get_by_role("button").click
189
+ ```
190
+
191
+ ## expose_function
192
+
193
+ ```
194
+ def expose_function(name, callback)
195
+ ```
196
+
197
+
198
+ The method adds a function called `name` on the `window` object of every frame in every page in the context.
199
+ When called, the function executes `callback` and returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) which resolves to the return value of
200
+ `callback`.
201
+
202
+ If the `callback` returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise), it will be awaited.
203
+
204
+ See [Page#expose_function](./page#expose_function) for page-only version.
205
+
206
+ **Usage**
207
+
208
+ An example of adding a `sha256` function to all pages in the context:
209
+
210
+ ```ruby
211
+ require 'digest'
212
+
213
+ def sha256(text)
214
+ Digest::SHA256.hexdigest(text)
215
+ end
216
+
217
+ browser_context.expose_function("sha256", method(:sha256))
218
+ page = browser_context.new_page()
219
+ page.content = <<~HTML
220
+ <script>
221
+ async function onClick() {
222
+ document.querySelector('div').textContent = await window.sha256('PLAYWRIGHT');
223
+ }
224
+ </script>
225
+ <button onclick="onClick()">Click me</button>
226
+ <div></div>
227
+ HTML
228
+ page.get_by_role("button").click
229
+ ```
230
+
231
+ ## grant_permissions
232
+
233
+ ```
234
+ def grant_permissions(permissions, origin: nil)
235
+ ```
236
+
237
+
238
+ Grants specified permissions to the browser context. Only grants corresponding permissions to the given origin if
239
+ specified.
240
+
241
+ ## new_cdp_session
242
+
243
+ ```
244
+ def new_cdp_session(page)
245
+ ```
246
+
247
+
248
+ **NOTE**: CDP sessions are only supported on Chromium-based browsers.
249
+
250
+ Returns the newly created session.
251
+
252
+ ## new_page
253
+
254
+ ```
255
+ def new_page(&block)
256
+ ```
257
+
258
+
259
+ Creates a new page in the browser context.
260
+
261
+ ## pages
262
+
263
+ ```
264
+ def pages
265
+ ```
266
+
267
+
268
+ Returns all open pages in the context.
269
+
270
+ ## route
271
+
272
+ ```
273
+ def route(url, handler, times: nil)
274
+ ```
275
+
276
+
277
+ Routing provides the capability to modify network requests that are made by any page in the browser context. Once route
278
+ is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted.
279
+
280
+ **NOTE**: [BrowserContext#route](./browser_context#route) will not intercept requests intercepted by Service Worker. See [this](https://github.com/microsoft/playwright/issues/1090) issue. We recommend disabling Service Workers when using request interception by setting `serviceWorkers` to `'block'`.
281
+
282
+ **Usage**
283
+
284
+ An example of a naive handler that aborts all image requests:
285
+
286
+ ```ruby
287
+ context = browser.new_context
288
+ page = context.new_page
289
+ context.route("**/*.{png,jpg,jpeg}", ->(route, request) { route.abort })
290
+ page.goto("https://example.com")
291
+ ```
292
+
293
+ or the same snippet using a regex pattern instead:
294
+
295
+ ```ruby
296
+ context = browser.new_context
297
+ page = context.new_page
298
+ context.route(/\.(png|jpg)$/, ->(route, request) { route.abort })
299
+ page.goto("https://example.com")
300
+ ```
301
+
302
+ It is possible to examine the request to decide the route action. For example, mocking all requests that contain some post data, and leaving all other requests as is:
303
+
304
+ ```ruby
305
+ def handle_route(route, request)
306
+ if request.post_data["my-string"]
307
+ mocked_data = request.post_data.merge({ "my-string" => 'mocked-data'})
308
+ route.fulfill(postData: mocked_data)
309
+ else
310
+ route.continue
311
+ end
312
+ end
313
+ context.route("/api/**", method(:handle_route))
314
+ ```
315
+
316
+ Page routes (set up with [Page#route](./page#route)) take precedence over browser context routes when request matches both
317
+ handlers.
318
+
319
+ To remove a route with its handler you can use [BrowserContext#unroute](./browser_context#unroute).
320
+
321
+ **NOTE**: Enabling routing disables http cache.
322
+
323
+ ## route_from_har
324
+
325
+ ```
326
+ def route_from_har(
327
+ har,
328
+ notFound: nil,
329
+ update: nil,
330
+ updateContent: nil,
331
+ updateMode: nil,
332
+ url: nil)
333
+ ```
334
+
335
+
336
+ If specified the network requests that are made in the context will be served from the HAR file. Read more about [Replaying from HAR](https://playwright.dev/python/docs/mock#replaying-from-har).
337
+
338
+ Playwright will not serve requests intercepted by Service Worker from the HAR file. See [this](https://github.com/microsoft/playwright/issues/1090) issue. We recommend disabling Service Workers when using request interception by setting `serviceWorkers` to `'block'`.
339
+
340
+ ## service_workers
341
+
342
+ ```
343
+ def service_workers
344
+ ```
345
+
346
+
347
+ **NOTE**: Service workers are only supported on Chromium-based browsers.
348
+
349
+ All existing service workers in the context.
350
+
351
+ ## set_default_navigation_timeout
352
+
353
+ ```
354
+ def set_default_navigation_timeout(timeout)
355
+ ```
356
+ alias: `default_navigation_timeout=`
357
+
358
+
359
+ This setting will change the default maximum navigation time for the following methods and related shortcuts:
360
+ - [Page#go_back](./page#go_back)
361
+ - [Page#go_forward](./page#go_forward)
362
+ - [Page#goto](./page#goto)
363
+ - [Page#reload](./page#reload)
364
+ - [Page#set_content](./page#set_content)
365
+ - [Page#expect_navigation](./page#expect_navigation)
366
+
367
+ **NOTE**: [Page#set_default_navigation_timeout](./page#set_default_navigation_timeout) and [Page#set_default_timeout](./page#set_default_timeout) take priority over
368
+ [BrowserContext#set_default_navigation_timeout](./browser_context#set_default_navigation_timeout).
369
+
370
+ ## set_default_timeout
371
+
372
+ ```
373
+ def set_default_timeout(timeout)
374
+ ```
375
+ alias: `default_timeout=`
376
+
377
+
378
+ This setting will change the default maximum time for all the methods accepting `timeout` option.
379
+
380
+ **NOTE**: [Page#set_default_navigation_timeout](./page#set_default_navigation_timeout), [Page#set_default_timeout](./page#set_default_timeout) and
381
+ [BrowserContext#set_default_navigation_timeout](./browser_context#set_default_navigation_timeout) take priority over [BrowserContext#set_default_timeout](./browser_context#set_default_timeout).
382
+
383
+ ## set_extra_http_headers
384
+
385
+ ```
386
+ def set_extra_http_headers(headers)
387
+ ```
388
+ alias: `extra_http_headers=`
389
+
390
+
391
+ The extra HTTP headers will be sent with every request initiated by any page in the context. These headers are merged
392
+ with page-specific extra HTTP headers set with [Page#set_extra_http_headers](./page#set_extra_http_headers). If page overrides a particular
393
+ header, page-specific header value will be used instead of the browser context header value.
394
+
395
+ **NOTE**: [BrowserContext#set_extra_http_headers](./browser_context#set_extra_http_headers) does not guarantee the order of headers in the outgoing requests.
396
+
397
+ ## set_geolocation
398
+
399
+ ```
400
+ def set_geolocation(geolocation)
401
+ ```
402
+ alias: `geolocation=`
403
+
404
+
405
+ Sets the context's geolocation. Passing `null` or `undefined` emulates position unavailable.
406
+
407
+ **Usage**
408
+
409
+ ```ruby
410
+ browser_context.geolocation = { latitude: 59.95, longitude: 30.31667 }
411
+ ```
412
+
413
+ **NOTE**: Consider using [BrowserContext#grant_permissions](./browser_context#grant_permissions) to grant permissions for the browser context pages to read
414
+ its geolocation.
415
+
416
+ ## set_offline
417
+
418
+ ```
419
+ def set_offline(offline)
420
+ ```
421
+ alias: `offline=`
422
+
423
+
424
+
425
+ ## storage_state
426
+
427
+ ```
428
+ def storage_state(indexedDB: nil, path: nil)
429
+ ```
430
+
431
+
432
+ Returns storage state for this browser context, contains current cookies, local storage snapshot and IndexedDB snapshot.
433
+
434
+ ## unroute_all
435
+
436
+ ```
437
+ def unroute_all(behavior: nil)
438
+ ```
439
+
440
+
441
+ Removes all routes created with [BrowserContext#route](./browser_context#route) and [BrowserContext#route_from_har](./browser_context#route_from_har).
442
+
443
+ ## unroute
444
+
445
+ ```
446
+ def unroute(url, handler: nil)
447
+ ```
448
+
449
+
450
+ Removes a route created with [BrowserContext#route](./browser_context#route). When `handler` is not specified, removes all
451
+ routes for the `url`.
452
+
453
+ ## expect_console_message
454
+
455
+ ```
456
+ def expect_console_message(predicate: nil, timeout: nil, &block)
457
+ ```
458
+
459
+
460
+ Performs action and waits for a [ConsoleMessage](./console_message) to be logged by in the pages in the context. If predicate is provided, it passes
461
+ [ConsoleMessage](./console_message) value into the `predicate` function and waits for `predicate(message)` to return a truthy value.
462
+ Will throw an error if the page is closed before the [`event: BrowserContext.console`] event is fired.
463
+
464
+ ## expect_event
465
+
466
+ ```
467
+ def expect_event(event, predicate: nil, timeout: nil, &block)
468
+ ```
469
+
470
+
471
+ Waits for event to fire and passes its value into the predicate function. Returns when the predicate returns truthy
472
+ value. Will throw an error if the context closes before the event is fired. Returns the event data value.
473
+
474
+ **Usage**
475
+
476
+ ```ruby
477
+ new_page = browser_context.expect_event('page') do
478
+ page.get_by_role("button").click
479
+ end
480
+ ```
481
+
482
+ ## expect_page
483
+
484
+ ```
485
+ def expect_page(predicate: nil, timeout: nil, &block)
486
+ ```
487
+
488
+
489
+ Performs action and waits for a new [Page](./page) to be created in the context. If predicate is provided, it passes
490
+ [Page](./page) value into the `predicate` function and waits for `predicate(event)` to return a truthy value.
491
+ Will throw an error if the context closes before new [Page](./page) is created.
492
+
493
+ ## clock
494
+
495
+
496
+ Playwright has ability to mock clock and passage of time.
497
+
498
+ ## request
499
+
500
+
501
+ API testing helper associated with this context. Requests made with this API will use context cookies.
502
+
503
+ ## tracing
@@ -0,0 +1,184 @@
1
+ ---
2
+ sidebar_position: 10
3
+ ---
4
+
5
+ # BrowserType
6
+
7
+
8
+ BrowserType provides methods to launch a specific browser instance or connect to an existing one. The following is a
9
+ typical example of using Playwright to drive automation:
10
+
11
+ ```ruby
12
+ chromium = playwright.chromium
13
+ chromium.launch do |browser|
14
+ page = browser.new_page
15
+ page.goto('https://example.com/')
16
+
17
+ # other actions
18
+
19
+ end
20
+ ```
21
+
22
+ ## connect_over_cdp
23
+
24
+ ```
25
+ def connect_over_cdp(
26
+ endpointURL,
27
+ headers: nil,
28
+ isLocal: nil,
29
+ slowMo: nil,
30
+ timeout: nil,
31
+ &block)
32
+ ```
33
+
34
+
35
+ This method attaches Playwright to an existing browser instance using the Chrome DevTools Protocol.
36
+
37
+ The default browser context is accessible via [Browser#contexts](./browser#contexts).
38
+
39
+ **NOTE**: Connecting over the Chrome DevTools Protocol is only supported for Chromium-based browsers.
40
+
41
+ **NOTE**: This connection is significantly lower fidelity than the Playwright protocol connection via [BrowserType#connect](./browser_type#connect). If you are experiencing issues or attempting to use advanced functionality, you probably want to use [BrowserType#connect](./browser_type#connect).
42
+
43
+ **Usage**
44
+
45
+ ```ruby
46
+ browser = playwright.chromium.connect_over_cdp("http://localhost:9222")
47
+ default_context = browser.contexts.first
48
+ page = default_context.pages.first
49
+ ```
50
+
51
+ ## executable_path
52
+
53
+ ```
54
+ def executable_path
55
+ ```
56
+
57
+
58
+ A path where Playwright expects to find a bundled browser executable.
59
+
60
+ ## launch
61
+
62
+ ```
63
+ def launch(
64
+ args: nil,
65
+ channel: nil,
66
+ chromiumSandbox: nil,
67
+ downloadsPath: nil,
68
+ env: nil,
69
+ executablePath: nil,
70
+ firefoxUserPrefs: nil,
71
+ handleSIGHUP: nil,
72
+ handleSIGINT: nil,
73
+ handleSIGTERM: nil,
74
+ headless: nil,
75
+ ignoreDefaultArgs: nil,
76
+ proxy: nil,
77
+ slowMo: nil,
78
+ timeout: nil,
79
+ tracesDir: nil,
80
+ &block)
81
+ ```
82
+
83
+
84
+ Returns the browser instance.
85
+
86
+ **Usage**
87
+
88
+ You can use `ignoreDefaultArgs` to filter out `--mute-audio` from default arguments:
89
+
90
+ ```ruby
91
+ browser = playwright.chromium.launch( # or "firefox" or "webkit".
92
+ ignoreDefaultArgs: ["--mute-audio"]
93
+ )
94
+
95
+ browser.close
96
+ ```
97
+
98
+ > **Chromium-only** Playwright can also be used to control the Google Chrome or Microsoft Edge browsers, but it works best with the version of
99
+ Chromium it is bundled with. There is no guarantee it will work with any other version. Use `executablePath`
100
+ option with extreme caution.
101
+
102
+ >
103
+
104
+ > If Google Chrome (rather than Chromium) is preferred, a
105
+ [Chrome Canary](https://www.google.com/chrome/browser/canary.html) or
106
+ [Dev Channel](https://www.chromium.org/getting-involved/dev-channel) build is suggested.
107
+
108
+ >
109
+
110
+ > Stock browsers like Google Chrome and Microsoft Edge are suitable for tests that require proprietary media codecs for video playback. See [this article](https://www.howtogeek.com/202825/what%E2%80%99s-the-difference-between-chromium-and-chrome/) for other differences between Chromium and Chrome.
111
+ [This article](https://chromium.googlesource.com/chromium/src/+/lkgr/docs/chromium_browser_vs_google_chrome.md)
112
+ describes some differences for Linux users.
113
+
114
+ ## launch_persistent_context
115
+
116
+ ```
117
+ def launch_persistent_context(
118
+ userDataDir,
119
+ acceptDownloads: nil,
120
+ args: nil,
121
+ baseURL: nil,
122
+ bypassCSP: nil,
123
+ channel: nil,
124
+ chromiumSandbox: nil,
125
+ clientCertificates: nil,
126
+ colorScheme: nil,
127
+ contrast: nil,
128
+ deviceScaleFactor: nil,
129
+ downloadsPath: nil,
130
+ env: nil,
131
+ executablePath: nil,
132
+ extraHTTPHeaders: nil,
133
+ firefoxUserPrefs: nil,
134
+ forcedColors: nil,
135
+ geolocation: nil,
136
+ handleSIGHUP: nil,
137
+ handleSIGINT: nil,
138
+ handleSIGTERM: nil,
139
+ hasTouch: nil,
140
+ headless: nil,
141
+ httpCredentials: nil,
142
+ ignoreDefaultArgs: nil,
143
+ ignoreHTTPSErrors: nil,
144
+ isMobile: nil,
145
+ javaScriptEnabled: nil,
146
+ locale: nil,
147
+ noViewport: nil,
148
+ offline: nil,
149
+ permissions: nil,
150
+ proxy: nil,
151
+ record_har_content: nil,
152
+ record_har_mode: nil,
153
+ record_har_omit_content: nil,
154
+ record_har_path: nil,
155
+ record_har_url_filter: nil,
156
+ record_video_dir: nil,
157
+ record_video_size: nil,
158
+ reducedMotion: nil,
159
+ screen: nil,
160
+ serviceWorkers: nil,
161
+ slowMo: nil,
162
+ strictSelectors: nil,
163
+ timeout: nil,
164
+ timezoneId: nil,
165
+ tracesDir: nil,
166
+ userAgent: nil,
167
+ viewport: nil,
168
+ &block)
169
+ ```
170
+
171
+
172
+ Returns the persistent browser context instance.
173
+
174
+ Launches browser that uses persistent storage located at `userDataDir` and returns the only context. Closing
175
+ this context will automatically close the browser.
176
+
177
+ ## name
178
+
179
+ ```
180
+ def name
181
+ ```
182
+
183
+
184
+ Returns browser name. For example: `'chromium'`, `'webkit'` or `'firefox'`.