playwright-ruby-client 1.28.1 → 1.29.1.alpha1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/documentation/docs/api/accessibility.md +9 -14
  3. data/documentation/docs/api/api_request_context.md +44 -41
  4. data/documentation/docs/api/api_response.md +13 -3
  5. data/documentation/docs/api/browser.md +24 -23
  6. data/documentation/docs/api/browser_context.md +71 -45
  7. data/documentation/docs/api/browser_type.md +21 -14
  8. data/documentation/docs/api/cdp_session.md +3 -5
  9. data/documentation/docs/api/console_message.md +7 -4
  10. data/documentation/docs/api/dialog.md +9 -5
  11. data/documentation/docs/api/download.md +19 -11
  12. data/documentation/docs/api/element_handle.md +125 -116
  13. data/documentation/docs/api/experimental/android.md +4 -5
  14. data/documentation/docs/api/experimental/android_device.md +11 -2
  15. data/documentation/docs/api/experimental/android_input.md +5 -0
  16. data/documentation/docs/api/file_chooser.md +6 -3
  17. data/documentation/docs/api/frame.md +182 -171
  18. data/documentation/docs/api/frame_locator.md +27 -38
  19. data/documentation/docs/api/js_handle.md +16 -10
  20. data/documentation/docs/api/keyboard.md +29 -16
  21. data/documentation/docs/api/locator.md +189 -140
  22. data/documentation/docs/api/mouse.md +9 -4
  23. data/documentation/docs/api/page.md +304 -289
  24. data/documentation/docs/api/playwright.md +8 -5
  25. data/documentation/docs/api/request.md +34 -15
  26. data/documentation/docs/api/response.md +27 -10
  27. data/documentation/docs/api/route.md +44 -12
  28. data/documentation/docs/api/selectors.md +5 -3
  29. data/documentation/docs/api/touchscreen.md +2 -0
  30. data/documentation/docs/api/tracing.md +11 -11
  31. data/documentation/docs/api/web_socket.md +9 -4
  32. data/documentation/docs/api/worker.md +12 -11
  33. data/documentation/docs/include/api_coverage.md +2 -0
  34. data/lib/playwright/channel_owners/api_request_context.rb +37 -2
  35. data/lib/playwright/channel_owners/browser_context.rb +22 -26
  36. data/lib/playwright/channel_owners/page.rb +35 -25
  37. data/lib/playwright/channel_owners/route.rb +28 -8
  38. data/lib/playwright/event_emitter.rb +6 -1
  39. data/lib/playwright/locator_impl.rb +8 -0
  40. data/lib/playwright/select_option_values.rb +2 -0
  41. data/lib/playwright/version.rb +2 -2
  42. data/lib/playwright_api/accessibility.rb +9 -13
  43. data/lib/playwright_api/android.rb +14 -12
  44. data/lib/playwright_api/android_device.rb +38 -13
  45. data/lib/playwright_api/android_input.rb +5 -0
  46. data/lib/playwright_api/android_socket.rb +4 -2
  47. data/lib/playwright_api/android_web_view.rb +5 -2
  48. data/lib/playwright_api/api_request.rb +6 -3
  49. data/lib/playwright_api/api_request_context.rb +52 -42
  50. data/lib/playwright_api/api_response.rb +13 -2
  51. data/lib/playwright_api/browser.rb +30 -22
  52. data/lib/playwright_api/browser_context.rb +82 -45
  53. data/lib/playwright_api/browser_type.rb +29 -19
  54. data/lib/playwright_api/cdp_session.rb +9 -10
  55. data/lib/playwright_api/console_message.rb +13 -8
  56. data/lib/playwright_api/dialog.rb +14 -10
  57. data/lib/playwright_api/download.rb +19 -9
  58. data/lib/playwright_api/element_handle.rb +122 -99
  59. data/lib/playwright_api/file_chooser.rb +6 -1
  60. data/lib/playwright_api/frame.rb +186 -141
  61. data/lib/playwright_api/frame_locator.rb +29 -32
  62. data/lib/playwright_api/js_handle.rb +22 -12
  63. data/lib/playwright_api/keyboard.rb +29 -14
  64. data/lib/playwright_api/locator.rb +183 -112
  65. data/lib/playwright_api/mouse.rb +9 -2
  66. data/lib/playwright_api/page.rb +307 -259
  67. data/lib/playwright_api/playwright.rb +17 -10
  68. data/lib/playwright_api/request.rb +40 -13
  69. data/lib/playwright_api/response.rb +33 -16
  70. data/lib/playwright_api/route.rb +50 -17
  71. data/lib/playwright_api/selectors.rb +12 -7
  72. data/lib/playwright_api/touchscreen.rb +2 -0
  73. data/lib/playwright_api/tracing.rb +17 -11
  74. data/lib/playwright_api/web_socket.rb +15 -10
  75. data/lib/playwright_api/worker.rb +20 -17
  76. data/playwright.gemspec +2 -2
  77. data/sig/playwright.rbs +559 -0
  78. metadata +10 -9
@@ -18,28 +18,31 @@ module Playwright
18
18
  # ```
19
19
  class Browser < PlaywrightApi
20
20
 
21
+ #
21
22
  # Get the browser type (chromium, firefox or webkit) that the browser belongs to.
22
23
  def browser_type
23
24
  wrap_impl(@impl.browser_type)
24
25
  end
25
26
 
27
+ #
26
28
  # In case this browser is obtained using [`method: BrowserType.launch`], closes the browser and all of its pages (if any
27
29
  # were opened).
28
30
  #
29
31
  # In case this browser is connected to, clears all created contexts belonging to this browser and disconnects from the
30
32
  # browser server.
31
33
  #
32
- # > NOTE: This is similar to force quitting the browser. Therefore, you should call [`method: BrowserContext.close`] on
33
- # any `BrowserContext`'s you explicitly created earlier with [`method: Browser.newContext`] **before** calling
34
- # [`method: Browser.close`].
34
+ # **NOTE**: This is similar to force quitting the browser. Therefore, you should call [`method: BrowserContext.close`] on any `BrowserContext`'s you explicitly created earlier with [`method: Browser.newContext`] **before** calling [`method: Browser.close`].
35
35
  #
36
36
  # The `Browser` object itself is considered to be disposed and cannot be used anymore.
37
37
  def close
38
38
  wrap_impl(@impl.close)
39
39
  end
40
40
 
41
+ #
41
42
  # Returns an array of all open browser contexts. In a newly created browser, this will return zero browser contexts.
42
43
  #
44
+ # **Usage**
45
+ #
43
46
  # ```python sync
44
47
  # browser = pw.webkit.launch()
45
48
  # print(len(browser.contexts())) # prints `0`
@@ -50,24 +53,27 @@ module Playwright
50
53
  wrap_impl(@impl.contexts)
51
54
  end
52
55
 
56
+ #
53
57
  # Indicates that the browser is connected.
54
58
  def connected?
55
59
  wrap_impl(@impl.connected?)
56
60
  end
57
61
 
58
- # > NOTE: CDP Sessions are only supported on Chromium-based browsers.
62
+ #
63
+ # **NOTE**: CDP Sessions are only supported on Chromium-based browsers.
59
64
  #
60
65
  # Returns the newly created browser session.
61
66
  def new_browser_cdp_session
62
67
  wrap_impl(@impl.new_browser_cdp_session)
63
68
  end
64
69
 
70
+ #
65
71
  # Creates a new browser context. It won't share cookies/cache with other browser contexts.
66
72
  #
67
- # > NOTE: If directly using this method to create `BrowserContext`s, it is best practice to explicitly close the returned
68
- # context via [`method: BrowserContext.close`] when your code is done with the `BrowserContext`, and before calling
69
- # [`method: Browser.close`]. This will ensure the `context` is closed gracefully and any artifacts—like HARs and
70
- # videos—are fully flushed and saved.
73
+ # **NOTE**: If directly using this method to create `BrowserContext`s, it is best practice to explicitly close the returned context via [`method: BrowserContext.close`] when your code is done with the `BrowserContext`,
74
+ # and before calling [`method: Browser.close`]. This will ensure the `context` is closed gracefully and any artifacts—like HARs and videos—are fully flushed and saved.
75
+ #
76
+ # **Usage**
71
77
  #
72
78
  # ```python sync
73
79
  # browser = playwright.firefox.launch() # or "chromium" or "webkit".
@@ -119,6 +125,7 @@ module Playwright
119
125
  wrap_impl(@impl.new_context(acceptDownloads: unwrap_impl(acceptDownloads), baseURL: unwrap_impl(baseURL), bypassCSP: unwrap_impl(bypassCSP), colorScheme: unwrap_impl(colorScheme), deviceScaleFactor: unwrap_impl(deviceScaleFactor), extraHTTPHeaders: unwrap_impl(extraHTTPHeaders), forcedColors: unwrap_impl(forcedColors), geolocation: unwrap_impl(geolocation), hasTouch: unwrap_impl(hasTouch), httpCredentials: unwrap_impl(httpCredentials), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), isMobile: unwrap_impl(isMobile), javaScriptEnabled: unwrap_impl(javaScriptEnabled), locale: unwrap_impl(locale), noViewport: unwrap_impl(noViewport), offline: unwrap_impl(offline), permissions: unwrap_impl(permissions), proxy: unwrap_impl(proxy), record_har_content: unwrap_impl(record_har_content), record_har_mode: unwrap_impl(record_har_mode), record_har_omit_content: unwrap_impl(record_har_omit_content), record_har_path: unwrap_impl(record_har_path), record_har_url_filter: unwrap_impl(record_har_url_filter), record_video_dir: unwrap_impl(record_video_dir), record_video_size: unwrap_impl(record_video_size), reducedMotion: unwrap_impl(reducedMotion), screen: unwrap_impl(screen), serviceWorkers: unwrap_impl(serviceWorkers), storageState: unwrap_impl(storageState), strictSelectors: unwrap_impl(strictSelectors), timezoneId: unwrap_impl(timezoneId), userAgent: unwrap_impl(userAgent), viewport: unwrap_impl(viewport), &wrap_block_call(block)))
120
126
  end
121
127
 
128
+ #
122
129
  # Creates a new page in a new browser context. Closing this page will close the context as well.
123
130
  #
124
131
  # This is a convenience API that should only be used for the single-page scenarios and short snippets. Production code and
@@ -162,12 +169,13 @@ module Playwright
162
169
  wrap_impl(@impl.new_page(acceptDownloads: unwrap_impl(acceptDownloads), baseURL: unwrap_impl(baseURL), bypassCSP: unwrap_impl(bypassCSP), colorScheme: unwrap_impl(colorScheme), deviceScaleFactor: unwrap_impl(deviceScaleFactor), extraHTTPHeaders: unwrap_impl(extraHTTPHeaders), forcedColors: unwrap_impl(forcedColors), geolocation: unwrap_impl(geolocation), hasTouch: unwrap_impl(hasTouch), httpCredentials: unwrap_impl(httpCredentials), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), isMobile: unwrap_impl(isMobile), javaScriptEnabled: unwrap_impl(javaScriptEnabled), locale: unwrap_impl(locale), noViewport: unwrap_impl(noViewport), offline: unwrap_impl(offline), permissions: unwrap_impl(permissions), proxy: unwrap_impl(proxy), record_har_content: unwrap_impl(record_har_content), record_har_mode: unwrap_impl(record_har_mode), record_har_omit_content: unwrap_impl(record_har_omit_content), record_har_path: unwrap_impl(record_har_path), record_har_url_filter: unwrap_impl(record_har_url_filter), record_video_dir: unwrap_impl(record_video_dir), record_video_size: unwrap_impl(record_video_size), reducedMotion: unwrap_impl(reducedMotion), screen: unwrap_impl(screen), serviceWorkers: unwrap_impl(serviceWorkers), storageState: unwrap_impl(storageState), strictSelectors: unwrap_impl(strictSelectors), timezoneId: unwrap_impl(timezoneId), userAgent: unwrap_impl(userAgent), viewport: unwrap_impl(viewport), &wrap_block_call(block)))
163
170
  end
164
171
 
165
- # > NOTE: This API controls [Chromium Tracing](https://www.chromium.org/developers/how-tos/trace-event-profiling-tool)
166
- # which is a low-level chromium-specific debugging tool. API to control [Playwright Tracing](../trace-viewer) could be
167
- # found [here](./class-tracing).
168
172
  #
169
- # You can use [`method: Browser.startTracing`] and [`method: Browser.stopTracing`] to create a trace file that can be
170
- # opened in Chrome DevTools performance panel.
173
+ # **NOTE**: This API controls [Chromium Tracing](https://www.chromium.org/developers/how-tos/trace-event-profiling-tool) which is a low-level chromium-specific debugging tool. API to control [Playwright Tracing](../trace-viewer) could be found [here](./class-tracing).
174
+ #
175
+ # You can use [`method: Browser.startTracing`] and [`method: Browser.stopTracing`] to create a trace file that can
176
+ # be opened in Chrome DevTools performance panel.
177
+ #
178
+ # **Usage**
171
179
  #
172
180
  # ```python sync
173
181
  # browser.start_tracing(page, path="trace.json")
@@ -178,15 +186,15 @@ module Playwright
178
186
  wrap_impl(@impl.start_tracing(page: unwrap_impl(page), categories: unwrap_impl(categories), path: unwrap_impl(path), screenshots: unwrap_impl(screenshots)))
179
187
  end
180
188
 
181
- # > NOTE: This API controls [Chromium Tracing](https://www.chromium.org/developers/how-tos/trace-event-profiling-tool)
182
- # which is a low-level chromium-specific debugging tool. API to control [Playwright Tracing](../trace-viewer) could be
183
- # found [here](./class-tracing).
189
+ #
190
+ # **NOTE**: This API controls [Chromium Tracing](https://www.chromium.org/developers/how-tos/trace-event-profiling-tool) which is a low-level chromium-specific debugging tool. API to control [Playwright Tracing](../trace-viewer) could be found [here](./class-tracing).
184
191
  #
185
192
  # Returns the buffer with trace data.
186
193
  def stop_tracing
187
194
  wrap_impl(@impl.stop_tracing)
188
195
  end
189
196
 
197
+ #
190
198
  # Returns the browser version.
191
199
  def version
192
200
  wrap_impl(@impl.version)
@@ -194,20 +202,20 @@ module Playwright
194
202
 
195
203
  # -- inherited from EventEmitter --
196
204
  # @nodoc
197
- def once(event, callback)
198
- event_emitter_proxy.once(event, callback)
205
+ def off(event, callback)
206
+ event_emitter_proxy.off(event, callback)
199
207
  end
200
208
 
201
209
  # -- inherited from EventEmitter --
202
210
  # @nodoc
203
- def on(event, callback)
204
- event_emitter_proxy.on(event, callback)
211
+ def once(event, callback)
212
+ event_emitter_proxy.once(event, callback)
205
213
  end
206
214
 
207
215
  # -- inherited from EventEmitter --
208
216
  # @nodoc
209
- def off(event, callback)
210
- event_emitter_proxy.off(event, callback)
217
+ def on(event, callback)
218
+ event_emitter_proxy.on(event, callback)
211
219
  end
212
220
 
213
221
  private def event_emitter_proxy
@@ -20,6 +20,7 @@ module Playwright
20
20
  # ```
21
21
  class BrowserContext < PlaywrightApi
22
22
 
23
+ #
23
24
  # API testing helper associated with this context. Requests made with this API will use context cookies.
24
25
  def request # property
25
26
  wrap_impl(@impl.request)
@@ -29,9 +30,12 @@ module Playwright
29
30
  wrap_impl(@impl.tracing)
30
31
  end
31
32
 
33
+ #
32
34
  # Adds cookies into this browser context. All pages within this context will have these cookies installed. Cookies can be
33
35
  # obtained via [`method: BrowserContext.cookies`].
34
36
  #
37
+ # **Usage**
38
+ #
35
39
  # ```python sync
36
40
  # browser_context.add_cookies([cookie_object1, cookie_object2])
37
41
  # ```
@@ -39,14 +43,16 @@ module Playwright
39
43
  wrap_impl(@impl.add_cookies(unwrap_impl(cookies)))
40
44
  end
41
45
 
46
+ #
42
47
  # Adds a script which would be evaluated in one of the following scenarios:
43
48
  # - Whenever a page is created in the browser context or is navigated.
44
- # - Whenever a child frame is attached or navigated in any page in the browser context. In this case, the script is
45
- # evaluated in the context of the newly attached frame.
49
+ # - 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.
46
50
  #
47
51
  # The script is evaluated after the document was created but before any of its scripts were run. This is useful to amend
48
52
  # the JavaScript environment, e.g. to seed `Math.random`.
49
53
  #
54
+ # **Usage**
55
+ #
50
56
  # An example of overriding `Math.random` before the page loads:
51
57
  #
52
58
  # ```python sync
@@ -54,31 +60,37 @@ module Playwright
54
60
  # browser_context.add_init_script(path="preload.js")
55
61
  # ```
56
62
  #
57
- # > NOTE: The order of evaluation of multiple scripts installed via [`method: BrowserContext.addInitScript`] and
63
+ # **NOTE**: The order of evaluation of multiple scripts installed via [`method: BrowserContext.addInitScript`] and
58
64
  # [`method: Page.addInitScript`] is not defined.
59
65
  def add_init_script(path: nil, script: nil)
60
66
  wrap_impl(@impl.add_init_script(path: unwrap_impl(path), script: unwrap_impl(script)))
61
67
  end
62
68
 
63
- # > NOTE: Background pages are only supported on Chromium-based browsers.
69
+ #
70
+ # **NOTE**: Background pages are only supported on Chromium-based browsers.
64
71
  #
65
72
  # All existing background pages in the context.
66
73
  def background_pages
67
74
  wrap_impl(@impl.background_pages)
68
75
  end
69
76
 
77
+ #
70
78
  # Returns the browser instance of the context. If it was launched as a persistent context null gets returned.
71
79
  def browser
72
80
  wrap_impl(@impl.browser)
73
81
  end
74
82
 
83
+ #
75
84
  # Clears context cookies.
76
85
  def clear_cookies
77
86
  wrap_impl(@impl.clear_cookies)
78
87
  end
79
88
 
89
+ #
80
90
  # Clears all permission overrides for the browser context.
81
91
  #
92
+ # **Usage**
93
+ #
82
94
  # ```python sync
83
95
  # context = browser.new_context()
84
96
  # context.grant_permissions(["clipboard-read"])
@@ -89,28 +101,33 @@ module Playwright
89
101
  wrap_impl(@impl.clear_permissions)
90
102
  end
91
103
 
104
+ #
92
105
  # Closes the browser context. All the pages that belong to the browser context will be closed.
93
106
  #
94
- # > NOTE: The default browser context cannot be closed.
107
+ # **NOTE**: The default browser context cannot be closed.
95
108
  def close
96
109
  wrap_impl(@impl.close)
97
110
  end
98
111
 
112
+ #
99
113
  # If no URLs are specified, this method returns all cookies. If URLs are specified, only cookies that affect those URLs
100
114
  # are returned.
101
115
  def cookies(urls: nil)
102
116
  wrap_impl(@impl.cookies(urls: unwrap_impl(urls)))
103
117
  end
104
118
 
105
- # The method adds a function called `name` on the `window` object of every frame in every page in the context. When
106
- # called, the function executes `callback` and returns a [Promise] which resolves to the return value of `callback`. If
107
- # the `callback` returns a [Promise], it will be awaited.
108
119
  #
109
- # The first argument of the `callback` function contains information about the caller: `{ browserContext: BrowserContext,
110
- # page: Page, frame: Frame }`.
120
+ # The method adds a function called `name` on the `window` object of every frame in every page in the context.
121
+ # When called, the function executes `callback` and returns a [Promise] which resolves to the return value of
122
+ # `callback`. If the `callback` returns a [Promise], it will be awaited.
123
+ #
124
+ # The first argument of the `callback` function contains information about the caller: `{ browserContext:
125
+ # BrowserContext, page: Page, frame: Frame }`.
111
126
  #
112
127
  # See [`method: Page.exposeBinding`] for page-only version.
113
128
  #
129
+ # **Usage**
130
+ #
114
131
  # An example of exposing page URL to all frames in all pages in the context:
115
132
  #
116
133
  # ```python sync
@@ -156,13 +173,17 @@ module Playwright
156
173
  wrap_impl(@impl.expose_binding(unwrap_impl(name), unwrap_impl(callback), handle: unwrap_impl(handle)))
157
174
  end
158
175
 
159
- # The method adds a function called `name` on the `window` object of every frame in every page in the context. When
160
- # called, the function executes `callback` and returns a [Promise] which resolves to the return value of `callback`.
176
+ #
177
+ # The method adds a function called `name` on the `window` object of every frame in every page in the context.
178
+ # When called, the function executes `callback` and returns a [Promise] which resolves to the return value of
179
+ # `callback`.
161
180
  #
162
181
  # If the `callback` returns a [Promise], it will be awaited.
163
182
  #
164
183
  # See [`method: Page.exposeFunction`] for page-only version.
165
184
  #
185
+ # **Usage**
186
+ #
166
187
  # An example of adding a `sha256` function to all pages in the context:
167
188
  #
168
189
  # ```python sync
@@ -199,35 +220,40 @@ module Playwright
199
220
  wrap_impl(@impl.expose_function(unwrap_impl(name), unwrap_impl(callback)))
200
221
  end
201
222
 
223
+ #
202
224
  # Grants specified permissions to the browser context. Only grants corresponding permissions to the given origin if
203
225
  # specified.
204
226
  def grant_permissions(permissions, origin: nil)
205
227
  wrap_impl(@impl.grant_permissions(unwrap_impl(permissions), origin: unwrap_impl(origin)))
206
228
  end
207
229
 
208
- # > NOTE: CDP sessions are only supported on Chromium-based browsers.
230
+ #
231
+ # **NOTE**: CDP sessions are only supported on Chromium-based browsers.
209
232
  #
210
233
  # Returns the newly created session.
211
234
  def new_cdp_session(page)
212
235
  wrap_impl(@impl.new_cdp_session(unwrap_impl(page)))
213
236
  end
214
237
 
238
+ #
215
239
  # Creates a new page in the browser context.
216
240
  def new_page(&block)
217
241
  wrap_impl(@impl.new_page(&wrap_block_call(block)))
218
242
  end
219
243
 
244
+ #
220
245
  # Returns all open pages in the context.
221
246
  def pages
222
247
  wrap_impl(@impl.pages)
223
248
  end
224
249
 
250
+ #
225
251
  # Routing provides the capability to modify network requests that are made by any page in the browser context. Once route
226
252
  # is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted.
227
253
  #
228
- # > NOTE: [`method: BrowserContext.route`] will not intercept requests intercepted by Service Worker. See
229
- # [this](https://github.com/microsoft/playwright/issues/1090) issue. We recommend disabling Service Workers when using
230
- # request interception by setting `Browser.newContext.serviceWorkers` to `'block'`.
254
+ # **NOTE**: [`method: BrowserContext.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 `Browser.newContext.serviceWorkers` to `'block'`.
255
+ #
256
+ # **Usage**
231
257
  #
232
258
  # An example of a naive handler that aborts all image requests:
233
259
  #
@@ -251,8 +277,7 @@ module Playwright
251
277
  # browser.close()
252
278
  # ```
253
279
  #
254
- # It is possible to examine the request to decide the route action. For example, mocking all requests that contain some
255
- # post data, and leaving all other requests as is:
280
+ # 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:
256
281
  #
257
282
  # ```python sync
258
283
  # def handle_route(route):
@@ -268,28 +293,28 @@ module Playwright
268
293
  #
269
294
  # To remove a route with its handler you can use [`method: BrowserContext.unroute`].
270
295
  #
271
- # > NOTE: Enabling routing disables http cache.
296
+ # **NOTE**: Enabling routing disables http cache.
272
297
  def route(url, handler, times: nil)
273
298
  wrap_impl(@impl.route(unwrap_impl(url), unwrap_impl(handler), times: unwrap_impl(times)))
274
299
  end
275
300
 
276
- # If specified the network requests that are made in the context will be served from the HAR file. Read more about
277
- # [Replaying from HAR](../network.md#replaying-from-har).
278
301
  #
279
- # Playwright will not serve requests intercepted by Service Worker from the HAR file. See
280
- # [this](https://github.com/microsoft/playwright/issues/1090) issue. We recommend disabling Service Workers when using
281
- # request interception by setting `Browser.newContext.serviceWorkers` to `'block'`.
302
+ # If specified the network requests that are made in the context will be served from the HAR file. Read more about [Replaying from HAR](../network.md#replaying-from-har).
303
+ #
304
+ # 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 `Browser.newContext.serviceWorkers` to `'block'`.
282
305
  def route_from_har(har, notFound: nil, update: nil, url: nil)
283
306
  wrap_impl(@impl.route_from_har(unwrap_impl(har), notFound: unwrap_impl(notFound), update: unwrap_impl(update), url: unwrap_impl(url)))
284
307
  end
285
308
 
286
- # > NOTE: Service workers are only supported on Chromium-based browsers.
309
+ #
310
+ # **NOTE**: Service workers are only supported on Chromium-based browsers.
287
311
  #
288
312
  # All existing service workers in the context.
289
313
  def service_workers
290
314
  wrap_impl(@impl.service_workers)
291
315
  end
292
316
 
317
+ #
293
318
  # This setting will change the default maximum navigation time for the following methods and related shortcuts:
294
319
  # - [`method: Page.goBack`]
295
320
  # - [`method: Page.goForward`]
@@ -298,40 +323,45 @@ module Playwright
298
323
  # - [`method: Page.setContent`]
299
324
  # - [`method: Page.waitForNavigation`]
300
325
  #
301
- # > NOTE: [`method: Page.setDefaultNavigationTimeout`] and [`method: Page.setDefaultTimeout`] take priority over
326
+ # **NOTE**: [`method: Page.setDefaultNavigationTimeout`] and [`method: Page.setDefaultTimeout`] take priority over
302
327
  # [`method: BrowserContext.setDefaultNavigationTimeout`].
303
328
  def set_default_navigation_timeout(timeout)
304
329
  wrap_impl(@impl.set_default_navigation_timeout(unwrap_impl(timeout)))
305
330
  end
306
331
  alias_method :default_navigation_timeout=, :set_default_navigation_timeout
307
332
 
333
+ #
308
334
  # This setting will change the default maximum time for all the methods accepting `timeout` option.
309
335
  #
310
- # > NOTE: [`method: Page.setDefaultNavigationTimeout`], [`method: Page.setDefaultTimeout`] and
336
+ # **NOTE**: [`method: Page.setDefaultNavigationTimeout`], [`method: Page.setDefaultTimeout`] and
311
337
  # [`method: BrowserContext.setDefaultNavigationTimeout`] take priority over [`method: BrowserContext.setDefaultTimeout`].
312
338
  def set_default_timeout(timeout)
313
339
  wrap_impl(@impl.set_default_timeout(unwrap_impl(timeout)))
314
340
  end
315
341
  alias_method :default_timeout=, :set_default_timeout
316
342
 
343
+ #
317
344
  # The extra HTTP headers will be sent with every request initiated by any page in the context. These headers are merged
318
345
  # with page-specific extra HTTP headers set with [`method: Page.setExtraHTTPHeaders`]. If page overrides a particular
319
346
  # header, page-specific header value will be used instead of the browser context header value.
320
347
  #
321
- # > NOTE: [`method: BrowserContext.setExtraHTTPHeaders`] does not guarantee the order of headers in the outgoing requests.
348
+ # **NOTE**: [`method: BrowserContext.setExtraHTTPHeaders`] does not guarantee the order of headers in the outgoing requests.
322
349
  def set_extra_http_headers(headers)
323
350
  wrap_impl(@impl.set_extra_http_headers(unwrap_impl(headers)))
324
351
  end
325
352
  alias_method :extra_http_headers=, :set_extra_http_headers
326
353
 
354
+ #
327
355
  # Sets the context's geolocation. Passing `null` or `undefined` emulates position unavailable.
328
356
  #
357
+ # **Usage**
358
+ #
329
359
  # ```python sync
330
360
  # browser_context.set_geolocation({"latitude": 59.95, "longitude": 30.31667})
331
361
  # ```
332
362
  #
333
- # > NOTE: Consider using [`method: BrowserContext.grantPermissions`] to grant permissions for the browser context pages to
334
- # read its geolocation.
363
+ # **NOTE**: Consider using [`method: BrowserContext.grantPermissions`] to grant permissions for the browser context pages to read
364
+ # its geolocation.
335
365
  def set_geolocation(geolocation)
336
366
  wrap_impl(@impl.set_geolocation(unwrap_impl(geolocation)))
337
367
  end
@@ -342,20 +372,25 @@ module Playwright
342
372
  end
343
373
  alias_method :offline=, :set_offline
344
374
 
375
+ #
345
376
  # Returns storage state for this browser context, contains current cookies and local storage snapshot.
346
377
  def storage_state(path: nil)
347
378
  wrap_impl(@impl.storage_state(path: unwrap_impl(path)))
348
379
  end
349
380
 
350
- # Removes a route created with [`method: BrowserContext.route`]. When `handler` is not specified, removes all routes for
351
- # the `url`.
381
+ #
382
+ # Removes a route created with [`method: BrowserContext.route`]. When `handler` is not specified, removes all
383
+ # routes for the `url`.
352
384
  def unroute(url, handler: nil)
353
385
  wrap_impl(@impl.unroute(unwrap_impl(url), handler: unwrap_impl(handler)))
354
386
  end
355
387
 
388
+ #
356
389
  # Waits for event to fire and passes its value into the predicate function. Returns when the predicate returns truthy
357
390
  # value. Will throw an error if the context closes before the event is fired. Returns the event data value.
358
391
  #
392
+ # **Usage**
393
+ #
359
394
  # ```python sync
360
395
  # with context.expect_event("page") as event_info:
361
396
  # page.get_by_role("button").click()
@@ -365,18 +400,20 @@ module Playwright
365
400
  wrap_impl(@impl.expect_event(unwrap_impl(event), predicate: unwrap_impl(predicate), timeout: unwrap_impl(timeout), &wrap_block_call(block)))
366
401
  end
367
402
 
368
- # Performs action and waits for a new `Page` to be created in the context. If predicate is provided, it passes `Page`
369
- # value into the `predicate` function and waits for `predicate(event)` to return a truthy value. Will throw an error if
370
- # the context closes before new `Page` is created.
403
+ #
404
+ # Performs action and waits for a new `Page` to be created in the context. If predicate is provided, it passes
405
+ # `Page` value into the `predicate` function and waits for `predicate(event)` to return a truthy value.
406
+ # Will throw an error if the context closes before new `Page` is created.
371
407
  def expect_page(predicate: nil, timeout: nil)
372
408
  wrap_impl(@impl.expect_page(predicate: unwrap_impl(predicate), timeout: unwrap_impl(timeout)))
373
409
  end
374
410
 
375
- # > NOTE: In most cases, you should use [`method: BrowserContext.waitForEvent`].
376
411
  #
377
- # Waits for given `event` to fire. If predicate is provided, it passes event's value into the `predicate` function and
378
- # waits for `predicate(event)` to return a truthy value. Will throw an error if the browser context is closed before the
379
- # `event` is fired.
412
+ # **NOTE**: In most cases, you should use [`method: BrowserContext.waitForEvent`].
413
+ #
414
+ # Waits for given `event` to fire. If predicate is provided, it passes
415
+ # event's value into the `predicate` function and waits for `predicate(event)` to return a truthy value.
416
+ # Will throw an error if the browser context is closed before the `event` is fired.
380
417
  def wait_for_event(event, predicate: nil, timeout: nil)
381
418
  raise NotImplementedError.new('wait_for_event is not implemented yet.')
382
419
  end
@@ -408,20 +445,20 @@ module Playwright
408
445
 
409
446
  # -- inherited from EventEmitter --
410
447
  # @nodoc
411
- def once(event, callback)
412
- event_emitter_proxy.once(event, callback)
448
+ def off(event, callback)
449
+ event_emitter_proxy.off(event, callback)
413
450
  end
414
451
 
415
452
  # -- inherited from EventEmitter --
416
453
  # @nodoc
417
- def on(event, callback)
418
- event_emitter_proxy.on(event, callback)
454
+ def once(event, callback)
455
+ event_emitter_proxy.once(event, callback)
419
456
  end
420
457
 
421
458
  # -- inherited from EventEmitter --
422
459
  # @nodoc
423
- def off(event, callback)
424
- event_emitter_proxy.off(event, callback)
460
+ def on(event, callback)
461
+ event_emitter_proxy.on(event, callback)
425
462
  end
426
463
 
427
464
  private def event_emitter_proxy
@@ -1,4 +1,5 @@
1
1
  module Playwright
2
+ #
2
3
  # BrowserType provides methods to launch a specific browser instance or connect to an existing one. The following is a
3
4
  # typical example of using Playwright to drive automation:
4
5
  #
@@ -18,18 +19,20 @@ module Playwright
18
19
  # ```
19
20
  class BrowserType < PlaywrightApi
20
21
 
21
- # This method attaches Playwright to an existing browser instance. When connecting to another browser launched via
22
- # `BrowserType.launchServer` in Node.js, the major and minor version needs to match the client version (1.2.3 → is
23
- # compatible with 1.2.x).
22
+ #
23
+ # This method attaches Playwright to an existing browser instance. When connecting to another browser launched via `BrowserType.launchServer` in Node.js, the major and minor version needs to match the client version (1.2.3 → is compatible with 1.2.x).
24
24
  def connect(wsEndpoint, headers: nil, slowMo: nil, timeout: nil)
25
25
  raise NotImplementedError.new('connect is not implemented yet.')
26
26
  end
27
27
 
28
+ #
28
29
  # This method attaches Playwright to an existing browser instance using the Chrome DevTools Protocol.
29
30
  #
30
31
  # The default browser context is accessible via [`method: Browser.contexts`].
31
32
  #
32
- # > NOTE: Connecting over the Chrome DevTools Protocol is only supported for Chromium-based browsers.
33
+ # **NOTE**: Connecting over the Chrome DevTools Protocol is only supported for Chromium-based browsers.
34
+ #
35
+ # **Usage**
33
36
  #
34
37
  # ```python sync
35
38
  # browser = playwright.chromium.connect_over_cdp("http://localhost:9222")
@@ -45,13 +48,17 @@ module Playwright
45
48
  wrap_impl(@impl.connect_over_cdp(unwrap_impl(endpointURL), headers: unwrap_impl(headers), slowMo: unwrap_impl(slowMo), timeout: unwrap_impl(timeout), &wrap_block_call(block)))
46
49
  end
47
50
 
51
+ #
48
52
  # A path where Playwright expects to find a bundled browser executable.
49
53
  def executable_path
50
54
  wrap_impl(@impl.executable_path)
51
55
  end
52
56
 
57
+ #
53
58
  # Returns the browser instance.
54
59
  #
60
+ # **Usage**
61
+ #
55
62
  # You can use `ignoreDefaultArgs` to filter out `--mute-audio` from default arguments:
56
63
  #
57
64
  # ```python sync
@@ -60,18 +67,19 @@ module Playwright
60
67
  # )
61
68
  # ```
62
69
  #
63
- # > **Chromium-only** Playwright can also be used to control the Google Chrome or Microsoft Edge browsers, but it works
64
- # best with the version of Chromium it is bundled with. There is no guarantee it will work with any other version. Use
65
- # `executablePath` option with extreme caution.
70
+ # > **Chromium-only** Playwright can also be used to control the Google Chrome or Microsoft Edge browsers, but it works best with the version of
71
+ # Chromium it is bundled with. There is no guarantee it will work with any other version. Use `executablePath`
72
+ # option with extreme caution.
73
+ #
66
74
  # >
75
+ #
67
76
  # > If Google Chrome (rather than Chromium) is preferred, a
68
77
  # [Chrome Canary](https://www.google.com/chrome/browser/canary.html) or
69
78
  # [Dev Channel](https://www.chromium.org/getting-involved/dev-channel) build is suggested.
79
+ #
70
80
  # >
71
- # > Stock browsers like Google Chrome and Microsoft Edge are suitable for tests that require proprietary media codecs for
72
- # video playback. See
73
- # [this article](https://www.howtogeek.com/202825/what%E2%80%99s-the-difference-between-chromium-and-chrome/) for other
74
- # differences between Chromium and Chrome.
81
+ #
82
+ # > 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.
75
83
  # [This article](https://chromium.googlesource.com/chromium/src/+/lkgr/docs/chromium_browser_vs_google_chrome.md)
76
84
  # describes some differences for Linux users.
77
85
  def launch(
@@ -96,10 +104,11 @@ module Playwright
96
104
  wrap_impl(@impl.launch(args: unwrap_impl(args), channel: unwrap_impl(channel), chromiumSandbox: unwrap_impl(chromiumSandbox), devtools: unwrap_impl(devtools), downloadsPath: unwrap_impl(downloadsPath), env: unwrap_impl(env), executablePath: unwrap_impl(executablePath), firefoxUserPrefs: unwrap_impl(firefoxUserPrefs), handleSIGHUP: unwrap_impl(handleSIGHUP), handleSIGINT: unwrap_impl(handleSIGINT), handleSIGTERM: unwrap_impl(handleSIGTERM), headless: unwrap_impl(headless), ignoreDefaultArgs: unwrap_impl(ignoreDefaultArgs), proxy: unwrap_impl(proxy), slowMo: unwrap_impl(slowMo), timeout: unwrap_impl(timeout), tracesDir: unwrap_impl(tracesDir), &wrap_block_call(block)))
97
105
  end
98
106
 
107
+ #
99
108
  # Returns the persistent browser context instance.
100
109
  #
101
- # Launches browser that uses persistent storage located at `userDataDir` and returns the only context. Closing this
102
- # context will automatically close the browser.
110
+ # Launches browser that uses persistent storage located at `userDataDir` and returns the only context. Closing
111
+ # this context will automatically close the browser.
103
112
  def launch_persistent_context(
104
113
  userDataDir,
105
114
  acceptDownloads: nil,
@@ -153,6 +162,7 @@ module Playwright
153
162
  wrap_impl(@impl.launch_persistent_context(unwrap_impl(userDataDir), acceptDownloads: unwrap_impl(acceptDownloads), args: unwrap_impl(args), baseURL: unwrap_impl(baseURL), bypassCSP: unwrap_impl(bypassCSP), channel: unwrap_impl(channel), chromiumSandbox: unwrap_impl(chromiumSandbox), colorScheme: unwrap_impl(colorScheme), deviceScaleFactor: unwrap_impl(deviceScaleFactor), devtools: unwrap_impl(devtools), downloadsPath: unwrap_impl(downloadsPath), env: unwrap_impl(env), executablePath: unwrap_impl(executablePath), extraHTTPHeaders: unwrap_impl(extraHTTPHeaders), forcedColors: unwrap_impl(forcedColors), geolocation: unwrap_impl(geolocation), handleSIGHUP: unwrap_impl(handleSIGHUP), handleSIGINT: unwrap_impl(handleSIGINT), handleSIGTERM: unwrap_impl(handleSIGTERM), hasTouch: unwrap_impl(hasTouch), headless: unwrap_impl(headless), httpCredentials: unwrap_impl(httpCredentials), ignoreDefaultArgs: unwrap_impl(ignoreDefaultArgs), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), isMobile: unwrap_impl(isMobile), javaScriptEnabled: unwrap_impl(javaScriptEnabled), locale: unwrap_impl(locale), noViewport: unwrap_impl(noViewport), offline: unwrap_impl(offline), permissions: unwrap_impl(permissions), proxy: unwrap_impl(proxy), record_har_content: unwrap_impl(record_har_content), record_har_mode: unwrap_impl(record_har_mode), record_har_omit_content: unwrap_impl(record_har_omit_content), record_har_path: unwrap_impl(record_har_path), record_har_url_filter: unwrap_impl(record_har_url_filter), record_video_dir: unwrap_impl(record_video_dir), record_video_size: unwrap_impl(record_video_size), reducedMotion: unwrap_impl(reducedMotion), screen: unwrap_impl(screen), serviceWorkers: unwrap_impl(serviceWorkers), slowMo: unwrap_impl(slowMo), strictSelectors: unwrap_impl(strictSelectors), timeout: unwrap_impl(timeout), timezoneId: unwrap_impl(timezoneId), tracesDir: unwrap_impl(tracesDir), userAgent: unwrap_impl(userAgent), viewport: unwrap_impl(viewport), &wrap_block_call(block)))
154
163
  end
155
164
 
165
+ #
156
166
  # Returns browser name. For example: `'chromium'`, `'webkit'` or `'firefox'`.
157
167
  def name
158
168
  wrap_impl(@impl.name)
@@ -160,20 +170,20 @@ module Playwright
160
170
 
161
171
  # -- inherited from EventEmitter --
162
172
  # @nodoc
163
- def once(event, callback)
164
- event_emitter_proxy.once(event, callback)
173
+ def off(event, callback)
174
+ event_emitter_proxy.off(event, callback)
165
175
  end
166
176
 
167
177
  # -- inherited from EventEmitter --
168
178
  # @nodoc
169
- def on(event, callback)
170
- event_emitter_proxy.on(event, callback)
179
+ def once(event, callback)
180
+ event_emitter_proxy.once(event, callback)
171
181
  end
172
182
 
173
183
  # -- inherited from EventEmitter --
174
184
  # @nodoc
175
- def off(event, callback)
176
- event_emitter_proxy.off(event, callback)
185
+ def on(event, callback)
186
+ event_emitter_proxy.on(event, callback)
177
187
  end
178
188
 
179
189
  private def event_emitter_proxy