playwright-ruby-client 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/documentation/README.md +33 -0
  3. data/documentation/babel.config.js +3 -0
  4. data/documentation/docs/api/accessibility.md +7 -0
  5. data/documentation/docs/api/browser.md +185 -0
  6. data/documentation/docs/api/browser_context.md +398 -0
  7. data/documentation/docs/api/browser_type.md +105 -0
  8. data/documentation/docs/api/cdp_session.md +7 -0
  9. data/documentation/docs/api/console_message.md +41 -0
  10. data/documentation/docs/api/dialog.md +74 -0
  11. data/documentation/docs/api/element_handle.md +640 -0
  12. data/documentation/docs/api/experimental/_category_.yml +3 -0
  13. data/documentation/docs/api/experimental/android.md +25 -0
  14. data/documentation/docs/api/experimental/android_device.md +91 -0
  15. data/documentation/docs/api/experimental/android_input.md +38 -0
  16. data/documentation/docs/api/experimental/android_socket.md +7 -0
  17. data/documentation/docs/api/experimental/android_web_view.md +7 -0
  18. data/documentation/docs/api/file_chooser.md +51 -0
  19. data/documentation/docs/api/frame.md +867 -0
  20. data/documentation/docs/api/js_handle.md +116 -0
  21. data/documentation/docs/api/keyboard.md +157 -0
  22. data/documentation/docs/api/mouse.md +69 -0
  23. data/documentation/docs/api/page.md +1469 -0
  24. data/documentation/docs/api/playwright.md +63 -0
  25. data/documentation/docs/api/request.md +188 -0
  26. data/documentation/docs/api/response.md +97 -0
  27. data/documentation/docs/api/route.md +80 -0
  28. data/documentation/docs/api/selectors.md +23 -0
  29. data/documentation/docs/api/touchscreen.md +8 -0
  30. data/documentation/docs/api/tracing.md +54 -0
  31. data/documentation/docs/api/web_socket.md +7 -0
  32. data/documentation/docs/api/worker.md +7 -0
  33. data/documentation/docs/article/api_coverage.mdx +11 -0
  34. data/documentation/docs/article/getting_started.md +152 -0
  35. data/documentation/docs/article/guides/_category_.yml +3 -0
  36. data/documentation/docs/article/guides/download_playwright_driver.md +49 -0
  37. data/documentation/docs/article/guides/launch_browser.md +119 -0
  38. data/documentation/docs/article/guides/rails_integration.md +51 -0
  39. data/{docs → documentation/docs/include}/api_coverage.md +0 -0
  40. data/documentation/docusaurus.config.js +107 -0
  41. data/documentation/package.json +39 -0
  42. data/documentation/sidebars.js +15 -0
  43. data/documentation/src/components/HomepageFeatures.js +61 -0
  44. data/documentation/src/components/HomepageFeatures.module.css +13 -0
  45. data/documentation/src/css/custom.css +44 -0
  46. data/documentation/src/pages/index.js +50 -0
  47. data/documentation/src/pages/index.module.css +41 -0
  48. data/documentation/src/pages/markdown-page.md +7 -0
  49. data/documentation/static/.nojekyll +0 -0
  50. data/documentation/static/img/playwright-logo.svg +9 -0
  51. data/documentation/static/img/undraw_dropdown_menu.svg +1 -0
  52. data/documentation/static/img/undraw_web_development.svg +1 -0
  53. data/documentation/static/img/undraw_windows.svg +1 -0
  54. data/documentation/yarn.lock +8805 -0
  55. data/lib/playwright/channel_owners/binding_call.rb +33 -0
  56. data/lib/playwright/channel_owners/browser_context.rb +2 -2
  57. data/lib/playwright/channel_owners/element_handle.rb +2 -10
  58. data/lib/playwright/channel_owners/frame.rb +6 -28
  59. data/lib/playwright/channel_owners/js_handle.rb +2 -10
  60. data/lib/playwright/channel_owners/page.rb +10 -1
  61. data/lib/playwright/input_files.rb +0 -8
  62. data/lib/playwright/javascript.rb +0 -10
  63. data/lib/playwright/javascript/expression.rb +2 -7
  64. data/lib/playwright/version.rb +1 -1
  65. data/lib/playwright_api/accessibility.rb +7 -89
  66. data/lib/playwright_api/android.rb +7 -64
  67. data/lib/playwright_api/android_device.rb +8 -8
  68. data/lib/playwright_api/browser.rb +15 -169
  69. data/lib/playwright_api/browser_context.rb +47 -609
  70. data/lib/playwright_api/browser_type.rb +13 -103
  71. data/lib/playwright_api/cdp_session.rb +2 -25
  72. data/lib/playwright_api/console_message.rb +6 -6
  73. data/lib/playwright_api/dialog.rb +11 -92
  74. data/lib/playwright_api/element_handle.rb +60 -362
  75. data/lib/playwright_api/file_chooser.rb +0 -28
  76. data/lib/playwright_api/frame.rb +74 -713
  77. data/lib/playwright_api/js_handle.rb +16 -90
  78. data/lib/playwright_api/keyboard.rb +21 -213
  79. data/lib/playwright_api/mouse.rb +1 -45
  80. data/lib/playwright_api/page.rb +155 -1635
  81. data/lib/playwright_api/playwright.rb +14 -117
  82. data/lib/playwright_api/request.rb +15 -121
  83. data/lib/playwright_api/response.rb +9 -9
  84. data/lib/playwright_api/route.rb +8 -105
  85. data/lib/playwright_api/selectors.rb +6 -97
  86. data/lib/playwright_api/tracing.rb +1 -61
  87. data/lib/playwright_api/web_socket.rb +1 -1
  88. data/lib/playwright_api/worker.rb +6 -42
  89. metadata +55 -4
  90. data/lib/playwright/javascript/function.rb +0 -67
@@ -1,42 +1,8 @@
1
1
  module Playwright
2
2
  # The Mouse class operates in main-frame CSS pixels relative to the top-left corner of the viewport.
3
- #
3
+ #
4
4
  # Every `page` object has its own Mouse, accessible with [`property: Page.mouse`].
5
- #
6
5
  #
7
- # ```js
8
- # // Using ‘page.mouse’ to trace a 100x100 square.
9
- # await page.mouse.move(0, 0);
10
- # await page.mouse.down();
11
- # await page.mouse.move(0, 100);
12
- # await page.mouse.move(100, 100);
13
- # await page.mouse.move(100, 0);
14
- # await page.mouse.move(0, 0);
15
- # await page.mouse.up();
16
- # ```
17
- #
18
- # ```java
19
- # // Using ‘page.mouse’ to trace a 100x100 square.
20
- # page.mouse().move(0, 0);
21
- # page.mouse().down();
22
- # page.mouse().move(0, 100);
23
- # page.mouse().move(100, 100);
24
- # page.mouse().move(100, 0);
25
- # page.mouse().move(0, 0);
26
- # page.mouse().up();
27
- # ```
28
- #
29
- # ```python async
30
- # # using ‘page.mouse’ to trace a 100x100 square.
31
- # await page.mouse.move(0, 0)
32
- # await page.mouse.down()
33
- # await page.mouse.move(0, 100)
34
- # await page.mouse.move(100, 100)
35
- # await page.mouse.move(100, 0)
36
- # await page.mouse.move(0, 0)
37
- # await page.mouse.up()
38
- # ```
39
- #
40
6
  # ```python sync
41
7
  # # using ‘page.mouse’ to trace a 100x100 square.
42
8
  # page.mouse.move(0, 0)
@@ -47,16 +13,6 @@ module Playwright
47
13
  # page.mouse.move(0, 0)
48
14
  # page.mouse.up()
49
15
  # ```
50
- #
51
- # ```csharp
52
- # await Page.Mouse.MoveAsync(0, 0);
53
- # await Page.Mouse.DownAsync();
54
- # await Page.Mouse.MoveAsync(0, 100);
55
- # await Page.Mouse.MoveAsync(100, 100);
56
- # await Page.Mouse.MoveAsync(100, 0);
57
- # await Page.Mouse.MoveAsync(0, 0);
58
- # await Page.Mouse.UpAsync();
59
- # ```
60
16
  class Mouse < PlaywrightApi
61
17
 
62
18
  # Shortcut for [`method: Mouse.move`], [`method: Mouse.down`], [`method: Mouse.up`].
@@ -1,66 +1,15 @@
1
1
  module Playwright
2
2
  # - extends: [EventEmitter]
3
- #
3
+ #
4
4
  # Page provides methods to interact with a single tab in a `Browser`, or an
5
5
  # [extension background page](https://developer.chrome.com/extensions/background_pages) in Chromium. One `Browser`
6
6
  # instance might have multiple `Page` instances.
7
- #
7
+ #
8
8
  # This example creates a page, navigates it to a URL, and then saves a screenshot:
9
- #
10
9
  #
11
- # ```js
12
- # const { webkit } = require('playwright'); // Or 'chromium' or 'firefox'.
13
- #
14
- # (async () => {
15
- # const browser = await webkit.launch();
16
- # const context = await browser.newContext();
17
- # const page = await context.newPage();
18
- # await page.goto('https://example.com');
19
- # await page.screenshot({path: 'screenshot.png'});
20
- # await browser.close();
21
- # })();
22
- # ```
23
- #
24
- # ```java
25
- # import com.microsoft.playwright.*;
26
- #
27
- # public class Example {
28
- # public static void main(String[] args) {
29
- # try (Playwright playwright = Playwright.create()) {
30
- # BrowserType webkit = playwright.webkit();
31
- # Browser browser = webkit.launch();
32
- # BrowserContext context = browser.newContext();
33
- # Page page = context.newPage();
34
- # page.navigate("https://example.com");
35
- # page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get("screenshot.png")));
36
- # browser.close();
37
- # }
38
- # }
39
- # }
40
- # ```
41
- #
42
- # ```python async
43
- # import asyncio
44
- # from playwright.async_api import async_playwright
45
- #
46
- # async def run(playwright):
47
- # webkit = playwright.webkit
48
- # browser = await webkit.launch()
49
- # context = await browser.new_context()
50
- # page = await context.new_page()
51
- # await page.goto("https://example.com")
52
- # await page.screenshot(path="screenshot.png")
53
- # await browser.close()
54
- #
55
- # async def main():
56
- # async with async_playwright() as playwright:
57
- # await run(playwright)
58
- # asyncio.run(main())
59
- # ```
60
- #
61
10
  # ```python sync
62
11
  # from playwright.sync_api import sync_playwright
63
- #
12
+ #
64
13
  # def run(playwright):
65
14
  # webkit = playwright.webkit
66
15
  # browser = webkit.launch()
@@ -69,72 +18,23 @@ module Playwright
69
18
  # page.goto("https://example.com")
70
19
  # page.screenshot(path="screenshot.png")
71
20
  # browser.close()
72
- #
21
+ #
73
22
  # with sync_playwright() as playwright:
74
23
  # run(playwright)
75
24
  # ```
76
- #
77
- # ```csharp
78
- # using Microsoft.Playwright;
79
- # using System.Threading.Tasks;
80
- #
81
- # class PageExamples
82
- # {
83
- # public static async Task Run()
84
- # {
85
- # using var playwright = await Playwright.CreateAsync();
86
- # await using var browser = await playwright.Webkit.LaunchAsync();
87
- # var page = await browser.NewPageAsync();
88
- # await page.GotoAsync("https://www.theverge.com");
89
- # await page.ScreenshotAsync("theverge.png");
90
- # }
91
- # }
92
- # ```
93
- #
25
+ #
94
26
  # The Page class emits various events (described below) which can be handled using any of Node's native
95
27
  # [`EventEmitter`](https://nodejs.org/api/events.html#events_class_eventemitter) methods, such as `on`, `once` or
96
28
  # `removeListener`.
97
- #
29
+ #
98
30
  # This example logs a message for a single page `load` event:
99
- #
100
31
  #
101
- # ```js
102
- # page.once('load', () => console.log('Page loaded!'));
103
- # ```
104
- #
105
- # ```java
106
- # page.onLoad(p -> System.out.println("Page loaded!"));
107
- # ```
108
- #
109
32
  # ```py
110
33
  # page.once("load", lambda: print("page loaded!"))
111
34
  # ```
112
- #
113
- # ```csharp
114
- # page.Load += (_, _) => Console.WriteLine("Page loaded!");
115
- # ```
116
- #
35
+ #
117
36
  # To unsubscribe from events use the `removeListener` method:
118
- #
119
37
  #
120
- # ```js
121
- # function logRequest(interceptedRequest) {
122
- # console.log('A request was made:', interceptedRequest.url());
123
- # }
124
- # page.on('request', logRequest);
125
- # // Sometime later...
126
- # page.removeListener('request', logRequest);
127
- # ```
128
- #
129
- # ```java
130
- # Consumer<Request> logRequest = interceptedRequest -> {
131
- # System.out.println("A request was made: " + interceptedRequest.url());
132
- # };
133
- # page.onRequest(logRequest);
134
- # // Sometime later...
135
- # page.offRequest(logRequest);
136
- # ```
137
- #
138
38
  # ```py
139
39
  # def log_request(intercepted_request):
140
40
  # print("a request was made:", intercepted_request.url)
@@ -142,16 +42,6 @@ module Playwright
142
42
  # # sometime later...
143
43
  # page.remove_listener("request", log_request)
144
44
  # ```
145
- #
146
- # ```csharp
147
- # void PageLoadHandler(object _, IPage p) {
148
- # Console.WriteLine("Page loaded!");
149
- # };
150
- #
151
- # page.Load += PageLoadHandler;
152
- # // Do some work...
153
- # page.Load -= PageLoadHandler;
154
- # ```
155
45
  class Page < PlaywrightApi
156
46
 
157
47
  def accessibility # property
@@ -174,43 +64,17 @@ module Playwright
174
64
  # - Whenever the page is navigated.
175
65
  # - Whenever the child frame is attached or navigated. In this case, the script is evaluated in the context of the newly
176
66
  # attached frame.
177
- #
67
+ #
178
68
  # The script is evaluated after the document was created but before any of its scripts were run. This is useful to amend
179
69
  # the JavaScript environment, e.g. to seed `Math.random`.
180
- #
181
- # An example of overriding `Math.random` before the page loads:
182
- #
183
70
  #
184
- # ```js browser
185
- # // preload.js
186
- # Math.random = () => 42;
187
- # ```
188
- #
71
+ # An example of overriding `Math.random` before the page loads:
189
72
  #
190
- # ```js
191
- # // In your playwright script, assuming the preload.js file is in same directory
192
- # await page.addInitScript({ path: './preload.js' });
193
- # ```
194
- #
195
- # ```java
196
- # // In your playwright script, assuming the preload.js file is in same directory
197
- # page.addInitScript(Paths.get("./preload.js"));
198
- # ```
199
- #
200
- # ```python async
201
- # # in your playwright script, assuming the preload.js file is in same directory
202
- # await page.add_init_script(path="./preload.js")
203
- # ```
204
- #
205
73
  # ```python sync
206
74
  # # in your playwright script, assuming the preload.js file is in same directory
207
75
  # page.add_init_script(path="./preload.js")
208
76
  # ```
209
- #
210
- # ```csharp
211
- # await page.AddInitScriptAsync(scriptPath: "./preload.js");
212
- # ```
213
- #
77
+ #
214
78
  # > NOTE: The order of evaluation of multiple scripts installed via [`method: BrowserContext.addInitScript`] and
215
79
  # [`method: Page.addInitScript`] is not defined.
216
80
  def add_init_script(path: nil, script: nil)
@@ -219,7 +83,7 @@ module Playwright
219
83
 
220
84
  # Adds a `<script>` tag into the page with the desired url or content. Returns the added tag when the script's onload
221
85
  # fires or when the script content was injected into frame.
222
- #
86
+ #
223
87
  # Shortcut for main frame's [`method: Frame.addScriptTag`].
224
88
  def add_script_tag(content: nil, path: nil, type: nil, url: nil)
225
89
  wrap_impl(@impl.add_script_tag(content: unwrap_impl(content), path: unwrap_impl(path), type: unwrap_impl(type), url: unwrap_impl(url)))
@@ -227,7 +91,7 @@ module Playwright
227
91
 
228
92
  # Adds a `<link rel="stylesheet">` tag into the page with the desired url or a `<style type="text/css">` tag with the
229
93
  # content. Returns the added tag when the stylesheet's onload fires or when the CSS content was injected into frame.
230
- #
94
+ #
231
95
  # Shortcut for main frame's [`method: Frame.addStyleTag`].
232
96
  def add_style_tag(content: nil, path: nil, url: nil)
233
97
  wrap_impl(@impl.add_style_tag(content: unwrap_impl(content), path: unwrap_impl(path), url: unwrap_impl(url)))
@@ -248,10 +112,10 @@ module Playwright
248
112
  # 1. Use [`property: Page.mouse`] to click in the center of the element.
249
113
  # 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
250
114
  # 1. Ensure that the element is now checked. If not, this method throws.
251
- #
115
+ #
252
116
  # When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
253
117
  # zero timeout disables this.
254
- #
118
+ #
255
119
  # Shortcut for main frame's [`method: Frame.check`].
256
120
  def check(
257
121
  selector,
@@ -270,10 +134,10 @@ module Playwright
270
134
  # 1. Scroll the element into view if needed.
271
135
  # 1. Use [`property: Page.mouse`] to click in the center of the element, or the specified `position`.
272
136
  # 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
273
- #
137
+ #
274
138
  # When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
275
139
  # zero timeout disables this.
276
- #
140
+ #
277
141
  # Shortcut for main frame's [`method: Frame.click`].
278
142
  def click(
279
143
  selector,
@@ -291,9 +155,9 @@ module Playwright
291
155
 
292
156
  # If `runBeforeUnload` is `false`, does not run any unload handlers and waits for the page to be closed. If
293
157
  # `runBeforeUnload` is `true` the method will run unload handlers, but will **not** wait for the page to close.
294
- #
158
+ #
295
159
  # By default, `page.close()` **does not** run `beforeunload` handlers.
296
- #
160
+ #
297
161
  # > NOTE: if `runBeforeUnload` is passed as true, a `beforeunload` dialog might be summoned and should be handled manually
298
162
  # via [`event: Page.dialog`] event.
299
163
  def close(runBeforeUnload: nil)
@@ -318,12 +182,12 @@ module Playwright
318
182
  # 1. Use [`property: Page.mouse`] to double click in the center of the element, or the specified `position`.
319
183
  # 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set. Note that if the
320
184
  # first click of the `dblclick()` triggers a navigation event, this method will throw.
321
- #
185
+ #
322
186
  # When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
323
187
  # zero timeout disables this.
324
- #
188
+ #
325
189
  # > NOTE: `page.dblclick()` dispatches two `click` events and a single `dblclick` event.
326
- #
190
+ #
327
191
  # Shortcut for main frame's [`method: Frame.dblclick`].
328
192
  def dblclick(
329
193
  selector,
@@ -341,31 +205,14 @@ module Playwright
341
205
  # The snippet below dispatches the `click` event on the element. Regardless of the visibility state of the element,
342
206
  # `click` is dispatched. This is equivalent to calling
343
207
  # [element.click()](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click).
344
- #
345
208
  #
346
- # ```js
347
- # await page.dispatchEvent('button#submit', 'click');
348
- # ```
349
- #
350
- # ```java
351
- # page.dispatchEvent("button#submit", "click");
352
- # ```
353
- #
354
- # ```python async
355
- # await page.dispatch_event("button#submit", "click")
356
- # ```
357
- #
358
209
  # ```python sync
359
210
  # page.dispatch_event("button#submit", "click")
360
211
  # ```
361
- #
362
- # ```csharp
363
- # await page.DispatchEventAsync("button#submit", "click");
364
- # ```
365
- #
212
+ #
366
213
  # Under the hood, it creates an instance of an event based on the given `type`, initializes it with `eventInit` properties
367
214
  # and dispatches it on the element. Events are `composed`, `cancelable` and bubble by default.
368
- #
215
+ #
369
216
  # Since `eventInit` is event-specific, please refer to the events documentation for the lists of initial properties:
370
217
  # - [DragEvent](https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent)
371
218
  # - [FocusEvent](https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent)
@@ -374,174 +221,40 @@ module Playwright
374
221
  # - [PointerEvent](https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent)
375
222
  # - [TouchEvent](https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent)
376
223
  # - [Event](https://developer.mozilla.org/en-US/docs/Web/API/Event/Event)
377
- #
224
+ #
378
225
  # You can also specify `JSHandle` as the property value if you want live objects to be passed into the event:
379
- #
380
226
  #
381
- # ```js
382
- # // Note you can only create DataTransfer in Chromium and Firefox
383
- # const dataTransfer = await page.evaluateHandle(() => new DataTransfer());
384
- # await page.dispatchEvent('#source', 'dragstart', { dataTransfer });
385
- # ```
386
- #
387
- # ```java
388
- # // Note you can only create DataTransfer in Chromium and Firefox
389
- # JSHandle dataTransfer = page.evaluateHandle("() => new DataTransfer()");
390
- # Map<String, Object> arg = new HashMap<>();
391
- # arg.put("dataTransfer", dataTransfer);
392
- # page.dispatchEvent("#source", "dragstart", arg);
393
- # ```
394
- #
395
- # ```python async
396
- # # note you can only create data_transfer in chromium and firefox
397
- # data_transfer = await page.evaluate_handle("new DataTransfer()")
398
- # await page.dispatch_event("#source", "dragstart", { "dataTransfer": data_transfer })
399
- # ```
400
- #
401
227
  # ```python sync
402
228
  # # note you can only create data_transfer in chromium and firefox
403
229
  # data_transfer = page.evaluate_handle("new DataTransfer()")
404
230
  # page.dispatch_event("#source", "dragstart", { "dataTransfer": data_transfer })
405
231
  # ```
406
- #
407
- # ```csharp
408
- # var dataTransfer = await page.EvaluateHandleAsync("() => new DataTransfer()");
409
- # await page.DispatchEventAsync("#source", "dragstart", new { dataTransfer });
410
- # ```
411
232
  def dispatch_event(selector, type, eventInit: nil, timeout: nil)
412
233
  wrap_impl(@impl.dispatch_event(unwrap_impl(selector), unwrap_impl(type), eventInit: unwrap_impl(eventInit), timeout: unwrap_impl(timeout)))
413
234
  end
414
235
 
415
236
  # This method changes the `CSS media type` through the `media` argument, and/or the `'prefers-colors-scheme'` media
416
237
  # feature, using the `colorScheme` argument.
417
- #
418
- #
419
- # ```js
420
- # await page.evaluate(() => matchMedia('screen').matches);
421
- # // → true
422
- # await page.evaluate(() => matchMedia('print').matches);
423
- # // → false
424
- #
425
- # await page.emulateMedia({ media: 'print' });
426
- # await page.evaluate(() => matchMedia('screen').matches);
427
- # // → false
428
- # await page.evaluate(() => matchMedia('print').matches);
429
- # // → true
430
- #
431
- # await page.emulateMedia({});
432
- # await page.evaluate(() => matchMedia('screen').matches);
433
- # // → true
434
- # await page.evaluate(() => matchMedia('print').matches);
435
- # // → false
436
- # ```
437
- #
438
- # ```java
439
- # page.evaluate("() => matchMedia('screen').matches");
440
- # // → true
441
- # page.evaluate("() => matchMedia('print').matches");
442
- # // → false
443
- #
444
- # page.emulateMedia(new Page.EmulateMediaOptions().setMedia(Media.PRINT));
445
- # page.evaluate("() => matchMedia('screen').matches");
446
- # // → false
447
- # page.evaluate("() => matchMedia('print').matches");
448
- # // → true
449
- #
450
- # page.emulateMedia(new Page.EmulateMediaOptions());
451
- # page.evaluate("() => matchMedia('screen').matches");
452
- # // → true
453
- # page.evaluate("() => matchMedia('print').matches");
454
- # // → false
455
- # ```
456
- #
457
- # ```python async
458
- # await page.evaluate("matchMedia('screen').matches")
459
- # # → True
460
- # await page.evaluate("matchMedia('print').matches")
461
- # # → False
462
- #
463
- # await page.emulate_media(media="print")
464
- # await page.evaluate("matchMedia('screen').matches")
465
- # # → False
466
- # await page.evaluate("matchMedia('print').matches")
467
- # # → True
468
- #
469
- # await page.emulate_media()
470
- # await page.evaluate("matchMedia('screen').matches")
471
- # # → True
472
- # await page.evaluate("matchMedia('print').matches")
473
- # # → False
474
- # ```
475
- #
238
+ #
476
239
  # ```python sync
477
240
  # page.evaluate("matchMedia('screen').matches")
478
241
  # # → True
479
242
  # page.evaluate("matchMedia('print').matches")
480
243
  # # → False
481
- #
244
+ #
482
245
  # page.emulate_media(media="print")
483
246
  # page.evaluate("matchMedia('screen').matches")
484
247
  # # → False
485
248
  # page.evaluate("matchMedia('print').matches")
486
249
  # # → True
487
- #
250
+ #
488
251
  # page.emulate_media()
489
252
  # page.evaluate("matchMedia('screen').matches")
490
253
  # # → True
491
254
  # page.evaluate("matchMedia('print').matches")
492
255
  # # → False
493
256
  # ```
494
- #
495
- # ```csharp
496
- # await page.EvaluateAsync("() => matchMedia('screen').matches");
497
- # // → true
498
- # await page.EvaluateAsync("() => matchMedia('print').matches");
499
- # // → false
500
- #
501
- # await page.EmulateMediaAsync(Media.Print);
502
- # await page.EvaluateAsync("() => matchMedia('screen').matches");
503
- # // → false
504
- # await page.EvaluateAsync("() => matchMedia('print').matches");
505
- # // → true
506
- #
507
- # await page.EmulateMediaAsync(Media.Screen);
508
- # await page.EvaluateAsync("() => matchMedia('screen').matches");
509
- # // → true
510
- # await page.EvaluateAsync("() => matchMedia('print').matches");
511
- # // → false
512
- # ```
513
- #
514
- #
515
- # ```js
516
- # await page.emulateMedia({ colorScheme: 'dark' });
517
- # await page.evaluate(() => matchMedia('(prefers-color-scheme: dark)').matches);
518
- # // → true
519
- # await page.evaluate(() => matchMedia('(prefers-color-scheme: light)').matches);
520
- # // → false
521
- # await page.evaluate(() => matchMedia('(prefers-color-scheme: no-preference)').matches);
522
- # // → false
523
- # ```
524
- #
525
- # ```java
526
- # page.emulateMedia(new Page.EmulateMediaOptions().setColorScheme(ColorScheme.DARK));
527
- # page.evaluate("() => matchMedia('(prefers-color-scheme: dark)').matches");
528
- # // → true
529
- # page.evaluate("() => matchMedia('(prefers-color-scheme: light)').matches");
530
- # // → false
531
- # page.evaluate("() => matchMedia('(prefers-color-scheme: no-preference)').matches");
532
- # // → false
533
- # ```
534
- #
535
- # ```python async
536
- # await page.emulate_media(color_scheme="dark")
537
- # await page.evaluate("matchMedia('(prefers-color-scheme: dark)').matches")
538
- # # → True
539
- # await page.evaluate("matchMedia('(prefers-color-scheme: light)').matches")
540
- # # → False
541
- # await page.evaluate("matchMedia('(prefers-color-scheme: no-preference)').matches")
542
- # # → False
543
- # ```
544
- #
257
+ #
545
258
  # ```python sync
546
259
  # page.emulate_media(color_scheme="dark")
547
260
  # page.evaluate("matchMedia('(prefers-color-scheme: dark)').matches")
@@ -550,59 +263,24 @@ module Playwright
550
263
  # # → False
551
264
  # page.evaluate("matchMedia('(prefers-color-scheme: no-preference)').matches")
552
265
  # ```
553
- #
554
- # ```csharp
555
- # await page.EmulateMediaAsync(colorScheme: ColorScheme.Dark);
556
- # await page.EvaluateAsync("matchMedia('(prefers-color-scheme: dark)').matches");
557
- # // → true
558
- # await page.EvaluateAsync("matchMedia('(prefers-color-scheme: light)').matches");
559
- # // → false
560
- # await page.EvaluateAsync("matchMedia('(prefers-color-scheme: no-preference)').matches");
561
- # // → false
562
- # ```
563
266
  def emulate_media(colorScheme: nil, media: nil)
564
267
  wrap_impl(@impl.emulate_media(colorScheme: unwrap_impl(colorScheme), media: unwrap_impl(media)))
565
268
  end
566
269
 
567
270
  # The method finds an element matching the specified selector within the page and passes it as a first argument to
568
271
  # `expression`. If no elements match the selector, the method throws an error. Returns the value of `expression`.
569
- #
272
+ #
570
273
  # If `expression` returns a [Promise], then [`method: Page.evalOnSelector`] would wait for the promise to resolve and
571
274
  # return its value.
572
- #
275
+ #
573
276
  # Examples:
574
- #
575
277
  #
576
- # ```js
577
- # const searchValue = await page.$eval('#search', el => el.value);
578
- # const preloadHref = await page.$eval('link[rel=preload]', el => el.href);
579
- # const html = await page.$eval('.main-container', (e, suffix) => e.outerHTML + suffix, 'hello');
580
- # ```
581
- #
582
- # ```java
583
- # String searchValue = (String) page.evalOnSelector("#search", "el => el.value");
584
- # String preloadHref = (String) page.evalOnSelector("link[rel=preload]", "el => el.href");
585
- # String html = (String) page.evalOnSelector(".main-container", "(e, suffix) => e.outerHTML + suffix", "hello");
586
- # ```
587
- #
588
- # ```python async
589
- # search_value = await page.eval_on_selector("#search", "el => el.value")
590
- # preload_href = await page.eval_on_selector("link[rel=preload]", "el => el.href")
591
- # html = await page.eval_on_selector(".main-container", "(e, suffix) => e.outer_html + suffix", "hello")
592
- # ```
593
- #
594
278
  # ```python sync
595
279
  # search_value = page.eval_on_selector("#search", "el => el.value")
596
280
  # preload_href = page.eval_on_selector("link[rel=preload]", "el => el.href")
597
281
  # html = page.eval_on_selector(".main-container", "(e, suffix) => e.outer_html + suffix", "hello")
598
282
  # ```
599
- #
600
- # ```csharp
601
- # var searchValue = await page.EvalOnSelectorAsync<string>("#search", "el => el.value");
602
- # var preloadHref = await page.EvalOnSelectorAsync<string>("link[rel=preload]", "el => el.href");
603
- # var html = await page.EvalOnSelectorAsync(".main-container", "(e, suffix) => e.outerHTML + suffix", "hello");
604
- # ```
605
- #
283
+ #
606
284
  # Shortcut for main frame's [`method: Frame.evalOnSelector`].
607
285
  def eval_on_selector(selector, expression, arg: nil)
608
286
  wrap_impl(@impl.eval_on_selector(unwrap_impl(selector), unwrap_impl(expression), arg: unwrap_impl(arg)))
@@ -610,238 +288,83 @@ module Playwright
610
288
 
611
289
  # The method finds all elements matching the specified selector within the page and passes an array of matched elements as
612
290
  # a first argument to `expression`. Returns the result of `expression` invocation.
613
- #
291
+ #
614
292
  # If `expression` returns a [Promise], then [`method: Page.evalOnSelectorAll`] would wait for the promise to resolve and
615
293
  # return its value.
616
- #
294
+ #
617
295
  # Examples:
618
- #
619
296
  #
620
- # ```js
621
- # const divCounts = await page.$$eval('div', (divs, min) => divs.length >= min, 10);
622
- # ```
623
- #
624
- # ```java
625
- # boolean divCounts = (boolean) page.evalOnSelectorAll("div", "(divs, min) => divs.length >= min", 10);
626
- # ```
627
- #
628
- # ```python async
629
- # div_counts = await page.eval_on_selector_all("div", "(divs, min) => divs.length >= min", 10)
630
- # ```
631
- #
632
297
  # ```python sync
633
298
  # div_counts = page.eval_on_selector_all("div", "(divs, min) => divs.length >= min", 10)
634
299
  # ```
635
- #
636
- # ```csharp
637
- # var divsCount = await page.EvalOnSelectorAllAsync<bool>("div", "(divs, min) => divs.length >= min", 10);
638
- # ```
639
300
  def eval_on_selector_all(selector, expression, arg: nil)
640
301
  wrap_impl(@impl.eval_on_selector_all(unwrap_impl(selector), unwrap_impl(expression), arg: unwrap_impl(arg)))
641
302
  end
642
303
 
643
304
  # Returns the value of the `expression` invocation.
644
- #
305
+ #
645
306
  # If the function passed to the [`method: Page.evaluate`] returns a [Promise], then [`method: Page.evaluate`] would wait
646
307
  # for the promise to resolve and return its value.
647
- #
308
+ #
648
309
  # If the function passed to the [`method: Page.evaluate`] returns a non-[Serializable] value, then
649
310
  # [`method: Page.evaluate`] resolves to `undefined`. Playwright also supports transferring some additional values that are
650
311
  # not serializable by `JSON`: `-0`, `NaN`, `Infinity`, `-Infinity`.
651
- #
312
+ #
652
313
  # Passing argument to `expression`:
653
- #
654
314
  #
655
- # ```js
656
- # const result = await page.evaluate(([x, y]) => {
657
- # return Promise.resolve(x * y);
658
- # }, [7, 8]);
659
- # console.log(result); // prints "56"
660
- # ```
661
- #
662
- # ```java
663
- # Object result = page.evaluate("([x, y]) => {\n" +
664
- # " return Promise.resolve(x * y);\n" +
665
- # "}", Arrays.asList(7, 8));
666
- # System.out.println(result); // prints "56"
667
- # ```
668
- #
669
- # ```python async
670
- # result = await page.evaluate("([x, y]) => Promise.resolve(x * y)", [7, 8])
671
- # print(result) # prints "56"
672
- # ```
673
- #
674
315
  # ```python sync
675
316
  # result = page.evaluate("([x, y]) => Promise.resolve(x * y)", [7, 8])
676
317
  # print(result) # prints "56"
677
318
  # ```
678
- #
679
- # ```csharp
680
- # var result = await page.EvaluateAsync<int>("([x, y]) => Promise.resolve(x * y)", new[] { 7, 8 });
681
- # Console.WriteLine(result);
682
- # ```
683
- #
319
+ #
684
320
  # A string can also be passed in instead of a function:
685
- #
686
321
  #
687
- # ```js
688
- # console.log(await page.evaluate('1 + 2')); // prints "3"
689
- # const x = 10;
690
- # console.log(await page.evaluate(`1 + ${x}`)); // prints "11"
691
- # ```
692
- #
693
- # ```java
694
- # System.out.println(page.evaluate("1 + 2")); // prints "3"
695
- # ```
696
- #
697
- # ```python async
698
- # print(await page.evaluate("1 + 2")) # prints "3"
699
- # x = 10
700
- # print(await page.evaluate(f"1 + {x}")) # prints "11"
701
- # ```
702
- #
703
322
  # ```python sync
704
323
  # print(page.evaluate("1 + 2")) # prints "3"
705
324
  # x = 10
706
325
  # print(page.evaluate(f"1 + {x}")) # prints "11"
707
326
  # ```
708
- #
709
- # ```csharp
710
- # Console.WriteLine(await page.EvaluateAsync<int>("1 + 2")); // prints "3"
711
- # ```
712
- #
327
+ #
713
328
  # `ElementHandle` instances can be passed as an argument to the [`method: Page.evaluate`]:
714
- #
715
329
  #
716
- # ```js
717
- # const bodyHandle = await page.$('body');
718
- # const html = await page.evaluate(([body, suffix]) => body.innerHTML + suffix, [bodyHandle, 'hello']);
719
- # await bodyHandle.dispose();
720
- # ```
721
- #
722
- # ```java
723
- # ElementHandle bodyHandle = page.querySelector("body");
724
- # String html = (String) page.evaluate("([body, suffix]) => body.innerHTML + suffix", Arrays.asList(bodyHandle, "hello"));
725
- # bodyHandle.dispose();
726
- # ```
727
- #
728
- # ```python async
729
- # body_handle = await page.query_selector("body")
730
- # html = await page.evaluate("([body, suffix]) => body.innerHTML + suffix", [body_handle, "hello"])
731
- # await body_handle.dispose()
732
- # ```
733
- #
734
330
  # ```python sync
735
331
  # body_handle = page.query_selector("body")
736
332
  # html = page.evaluate("([body, suffix]) => body.innerHTML + suffix", [body_handle, "hello"])
737
333
  # body_handle.dispose()
738
334
  # ```
739
- #
740
- # ```csharp
741
- # var bodyHandle = await page.QuerySelectorAsync("body");
742
- # var html = await page.EvaluateAsync<string>("([body, suffix]) => body.innerHTML + suffix", new object [] { bodyHandle, "hello" });
743
- # await bodyHandle.DisposeAsync();
744
- # ```
745
- #
335
+ #
746
336
  # Shortcut for main frame's [`method: Frame.evaluate`].
747
337
  def evaluate(expression, arg: nil)
748
338
  wrap_impl(@impl.evaluate(unwrap_impl(expression), arg: unwrap_impl(arg)))
749
339
  end
750
340
 
751
341
  # Returns the value of the `expression` invocation as a `JSHandle`.
752
- #
342
+ #
753
343
  # The only difference between [`method: Page.evaluate`] and [`method: Page.evaluateHandle`] is that
754
344
  # [`method: Page.evaluateHandle`] returns `JSHandle`.
755
- #
345
+ #
756
346
  # If the function passed to the [`method: Page.evaluateHandle`] returns a [Promise], then [`method: Page.evaluateHandle`]
757
347
  # would wait for the promise to resolve and return its value.
758
- #
759
348
  #
760
- # ```js
761
- # const aWindowHandle = await page.evaluateHandle(() => Promise.resolve(window));
762
- # aWindowHandle; // Handle for the window object.
763
- # ```
764
- #
765
- # ```java
766
- # // Handle for the window object.
767
- # JSHandle aWindowHandle = page.evaluateHandle("() => Promise.resolve(window)");
768
- # ```
769
- #
770
- # ```python async
771
- # a_window_handle = await page.evaluate_handle("Promise.resolve(window)")
772
- # a_window_handle # handle for the window object.
773
- # ```
774
- #
775
349
  # ```python sync
776
350
  # a_window_handle = page.evaluate_handle("Promise.resolve(window)")
777
351
  # a_window_handle # handle for the window object.
778
352
  # ```
779
- #
780
- # ```csharp
781
- # // Handle for the window object.
782
- # var aWindowHandle = await page.EvaluateHandleAsync("() => Promise.resolve(window)");
783
- # ```
784
- #
353
+ #
785
354
  # A string can also be passed in instead of a function:
786
- #
787
355
  #
788
- # ```js
789
- # const aHandle = await page.evaluateHandle('document'); // Handle for the 'document'
790
- # ```
791
- #
792
- # ```java
793
- # JSHandle aHandle = page.evaluateHandle("document"); // Handle for the "document".
794
- # ```
795
- #
796
- # ```python async
797
- # a_handle = await page.evaluate_handle("document") # handle for the "document"
798
- # ```
799
- #
800
356
  # ```python sync
801
357
  # a_handle = page.evaluate_handle("document") # handle for the "document"
802
358
  # ```
803
- #
804
- # ```csharp
805
- # var docHandle = await page.EvalueHandleAsync("document"); // Handle for the `document`
806
- # ```
807
- #
359
+ #
808
360
  # `JSHandle` instances can be passed as an argument to the [`method: Page.evaluateHandle`]:
809
- #
810
361
  #
811
- # ```js
812
- # const aHandle = await page.evaluateHandle(() => document.body);
813
- # const resultHandle = await page.evaluateHandle(body => body.innerHTML, aHandle);
814
- # console.log(await resultHandle.jsonValue());
815
- # await resultHandle.dispose();
816
- # ```
817
- #
818
- # ```java
819
- # JSHandle aHandle = page.evaluateHandle("() => document.body");
820
- # JSHandle resultHandle = page.evaluateHandle("([body, suffix]) => body.innerHTML + suffix", Arrays.asList(aHandle, "hello"));
821
- # System.out.println(resultHandle.jsonValue());
822
- # resultHandle.dispose();
823
- # ```
824
- #
825
- # ```python async
826
- # a_handle = await page.evaluate_handle("document.body")
827
- # result_handle = await page.evaluate_handle("body => body.innerHTML", a_handle)
828
- # print(await result_handle.json_value())
829
- # await result_handle.dispose()
830
- # ```
831
- #
832
362
  # ```python sync
833
363
  # a_handle = page.evaluate_handle("document.body")
834
364
  # result_handle = page.evaluate_handle("body => body.innerHTML", a_handle)
835
365
  # print(result_handle.json_value())
836
366
  # result_handle.dispose()
837
367
  # ```
838
- #
839
- # ```csharp
840
- # var handle = await page.EvaluateHandleAsync("() => document.body");
841
- # var resultHandle = await page.EvaluateHandleAsync("([body, suffix]) => body.innerHTML + suffix", new object[] { handle, "hello" });
842
- # Console.WriteLine(await resultHandle.JsonValueAsync<string>());
843
- # await resultHandle.DisposeAsync();
844
- # ```
845
368
  def evaluate_handle(expression, arg: nil)
846
369
  wrap_impl(@impl.evaluate_handle(unwrap_impl(expression), arg: unwrap_impl(arg)))
847
370
  end
@@ -849,92 +372,19 @@ module Playwright
849
372
  # The method adds a function called `name` on the `window` object of every frame in this page. When called, the function
850
373
  # executes `callback` and returns a [Promise] which resolves to the return value of `callback`. If the `callback` returns
851
374
  # a [Promise], it will be awaited.
852
- #
375
+ #
853
376
  # The first argument of the `callback` function contains information about the caller: `{ browserContext: BrowserContext,
854
377
  # page: Page, frame: Frame }`.
855
- #
378
+ #
856
379
  # See [`method: BrowserContext.exposeBinding`] for the context-wide version.
857
- #
380
+ #
858
381
  # > NOTE: Functions installed via [`method: Page.exposeBinding`] survive navigations.
859
- #
382
+ #
860
383
  # An example of exposing page URL to all frames in a page:
861
- #
862
- #
863
- # ```js
864
- # const { webkit } = require('playwright'); // Or 'chromium' or 'firefox'.
865
- #
866
- # (async () => {
867
- # const browser = await webkit.launch({ headless: false });
868
- # const context = await browser.newContext();
869
- # const page = await context.newPage();
870
- # await page.exposeBinding('pageURL', ({ page }) => page.url());
871
- # await page.setContent(`
872
- # <script>
873
- # async function onClick() {
874
- # document.querySelector('div').textContent = await window.pageURL();
875
- # }
876
- # </script>
877
- # <button onclick="onClick()">Click me</button>
878
- # <div></div>
879
- # `);
880
- # await page.click('button');
881
- # })();
882
- # ```
883
- #
884
- # ```java
885
- # import com.microsoft.playwright.*;
886
- #
887
- # public class Example {
888
- # public static void main(String[] args) {
889
- # try (Playwright playwright = Playwright.create()) {
890
- # BrowserType webkit = playwright.webkit();
891
- # Browser browser = webkit.launch({ headless: false });
892
- # BrowserContext context = browser.newContext();
893
- # Page page = context.newPage();
894
- # page.exposeBinding("pageURL", (source, args) -> source.page().url());
895
- # page.setContent("<script>\n" +
896
- # " async function onClick() {\n" +
897
- # " document.querySelector('div').textContent = await window.pageURL();\n" +
898
- # " }\n" +
899
- # "</script>\n" +
900
- # "<button onclick=\"onClick()\">Click me</button>\n" +
901
- # "<div></div>");
902
- # page.click("button");
903
- # }
904
- # }
905
- # }
906
- # ```
907
- #
908
- # ```python async
909
- # import asyncio
910
- # from playwright.async_api import async_playwright
911
- #
912
- # async def run(playwright):
913
- # webkit = playwright.webkit
914
- # browser = await webkit.launch(headless=false)
915
- # context = await browser.new_context()
916
- # page = await context.new_page()
917
- # await page.expose_binding("pageURL", lambda source: source["page"].url)
918
- # await page.set_content("""
919
- # <script>
920
- # async function onClick() {
921
- # document.querySelector('div').textContent = await window.pageURL();
922
- # }
923
- # </script>
924
- # <button onclick="onClick()">Click me</button>
925
- # <div></div>
926
- # """)
927
- # await page.click("button")
928
- #
929
- # async def main():
930
- # async with async_playwright() as playwright:
931
- # await run(playwright)
932
- # asyncio.run(main())
933
- # ```
934
- #
384
+ #
935
385
  # ```python sync
936
386
  # from playwright.sync_api import sync_playwright
937
- #
387
+ #
938
388
  # def run(playwright):
939
389
  # webkit = playwright.webkit
940
390
  # browser = webkit.launch(headless=false)
@@ -951,85 +401,17 @@ module Playwright
951
401
  # <div></div>
952
402
  # """)
953
403
  # page.click("button")
954
- #
404
+ #
955
405
  # with sync_playwright() as playwright:
956
406
  # run(playwright)
957
407
  # ```
958
- #
959
- # ```csharp
960
- # using Microsoft.Playwright;
961
- # using System.Threading.Tasks;
962
- #
963
- # class PageExamples
964
- # {
965
- # public static async Task Main()
966
- # {
967
- # using var playwright = await Playwright.CreateAsync();
968
- # await using var browser = await playwright.Webkit.LaunchAsync(headless: false);
969
- # var page = await browser.NewPageAsync();
970
- #
971
- # await page.ExposeBindingAsync("pageUrl", (source) => source.Page.Url);
972
- # await page.SetContentAsync("<script>\n" +
973
- # " async function onClick() {\n" +
974
- # " document.querySelector('div').textContent = await window.pageURL();\n" +
975
- # " }\n" +
976
- # "</script>\n" +
977
- # "<button onclick=\"onClick()\">Click me</button>\n" +
978
- # "<div></div>");
979
- #
980
- # await page.ClickAsync("button");
981
- # }
982
- # }
983
- # ```
984
- #
408
+ #
985
409
  # An example of passing an element handle:
986
- #
987
410
  #
988
- # ```js
989
- # await page.exposeBinding('clicked', async (source, element) => {
990
- # console.log(await element.textContent());
991
- # }, { handle: true });
992
- # await page.setContent(`
993
- # <script>
994
- # document.addEventListener('click', event => window.clicked(event.target));
995
- # </script>
996
- # <div>Click me</div>
997
- # <div>Or click me</div>
998
- # `);
999
- # ```
1000
- #
1001
- # ```java
1002
- # page.exposeBinding("clicked", (source, args) -> {
1003
- # ElementHandle element = (ElementHandle) args[0];
1004
- # System.out.println(element.textContent());
1005
- # return null;
1006
- # }, new Page.ExposeBindingOptions().setHandle(true));
1007
- # page.setContent("" +
1008
- # "<script>\n" +
1009
- # " document.addEventListener('click', event => window.clicked(event.target));\n" +
1010
- # "</script>\n" +
1011
- # "<div>Click me</div>\n" +
1012
- # "<div>Or click me</div>\n");
1013
- # ```
1014
- #
1015
- # ```python async
1016
- # async def print(source, element):
1017
- # print(await element.text_content())
1018
- #
1019
- # await page.expose_binding("clicked", print, handle=true)
1020
- # await page.set_content("""
1021
- # <script>
1022
- # document.addEventListener('click', event => window.clicked(event.target));
1023
- # </script>
1024
- # <div>Click me</div>
1025
- # <div>Or click me</div>
1026
- # """)
1027
- # ```
1028
- #
1029
411
  # ```python sync
1030
412
  # def print(source, element):
1031
413
  # print(element.text_content())
1032
- #
414
+ #
1033
415
  # page.expose_binding("clicked", print, handle=true)
1034
416
  # page.set_content("""
1035
417
  # <script>
@@ -1039,141 +421,31 @@ module Playwright
1039
421
  # <div>Or click me</div>
1040
422
  # """)
1041
423
  # ```
1042
- #
1043
- # ```csharp
1044
- # var result = new TaskCompletionSource<string>();
1045
- # await page.ExposeBindingAsync("clicked", async (BindingSource _, IJSHandle t) =>
1046
- # {
1047
- # return result.TrySetResult(await t.AsElement.TextContentAsync());
1048
- # });
1049
- #
1050
- # await page.SetContentAsync("<script>\n" +
1051
- # " document.addEventListener('click', event => window.clicked(event.target));\n" +
1052
- # "</script>\n" +
1053
- # "<div>Click me</div>\n" +
1054
- # "<div>Or click me</div>\n");
1055
- #
1056
- # await page.ClickAsync("div");
1057
- # Console.WriteLine(await result.Task);
1058
- # ```
1059
424
  def expose_binding(name, callback, handle: nil)
1060
425
  wrap_impl(@impl.expose_binding(unwrap_impl(name), unwrap_impl(callback), handle: unwrap_impl(handle)))
1061
426
  end
1062
427
 
1063
428
  # The method adds a function called `name` on the `window` object of every frame in the page. When called, the function
1064
429
  # executes `callback` and returns a [Promise] which resolves to the return value of `callback`.
1065
- #
430
+ #
1066
431
  # If the `callback` returns a [Promise], it will be awaited.
1067
- #
432
+ #
1068
433
  # See [`method: BrowserContext.exposeFunction`] for context-wide exposed function.
1069
- #
434
+ #
1070
435
  # > NOTE: Functions installed via [`method: Page.exposeFunction`] survive navigations.
1071
- #
436
+ #
1072
437
  # An example of adding an `sha1` function to the page:
1073
- #
1074
- #
1075
- # ```js
1076
- # const { webkit } = require('playwright'); // Or 'chromium' or 'firefox'.
1077
- # const crypto = require('crypto');
1078
- #
1079
- # (async () => {
1080
- # const browser = await webkit.launch({ headless: false });
1081
- # const page = await browser.newPage();
1082
- # await page.exposeFunction('sha1', text => crypto.createHash('sha1').update(text).digest('hex'));
1083
- # await page.setContent(`
1084
- # <script>
1085
- # async function onClick() {
1086
- # document.querySelector('div').textContent = await window.sha1('PLAYWRIGHT');
1087
- # }
1088
- # </script>
1089
- # <button onclick="onClick()">Click me</button>
1090
- # <div></div>
1091
- # `);
1092
- # await page.click('button');
1093
- # })();
1094
- # ```
1095
- #
1096
- # ```java
1097
- # import com.microsoft.playwright.*;
1098
- #
1099
- # import java.nio.charset.StandardCharsets;
1100
- # import java.security.MessageDigest;
1101
- # import java.security.NoSuchAlgorithmException;
1102
- # import java.util.Base64;
1103
- #
1104
- # public class Example {
1105
- # public static void main(String[] args) {
1106
- # try (Playwright playwright = Playwright.create()) {
1107
- # BrowserType webkit = playwright.webkit();
1108
- # Browser browser = webkit.launch({ headless: false });
1109
- # Page page = browser.newPage();
1110
- # page.exposeFunction("sha1", args -> {
1111
- # String text = (String) args[0];
1112
- # MessageDigest crypto;
1113
- # try {
1114
- # crypto = MessageDigest.getInstance("SHA-1");
1115
- # } catch (NoSuchAlgorithmException e) {
1116
- # return null;
1117
- # }
1118
- # byte[] token = crypto.digest(text.getBytes(StandardCharsets.UTF_8));
1119
- # return Base64.getEncoder().encodeToString(token);
1120
- # });
1121
- # page.setContent("<script>\n" +
1122
- # " async function onClick() {\n" +
1123
- # " document.querySelector('div').textContent = await window.sha1('PLAYWRIGHT');\n" +
1124
- # " }\n" +
1125
- # "</script>\n" +
1126
- # "<button onclick=\"onClick()\">Click me</button>\n" +
1127
- # "<div></div>\n");
1128
- # page.click("button");
1129
- # }
1130
- # }
1131
- # }
1132
- # ```
1133
- #
1134
- # ```python async
1135
- # import asyncio
1136
- # import hashlib
1137
- # from playwright.async_api import async_playwright
1138
- #
1139
- # async def sha1(text):
1140
- # m = hashlib.sha1()
1141
- # m.update(bytes(text, "utf8"))
1142
- # return m.hexdigest()
1143
- #
1144
- #
1145
- # async def run(playwright):
1146
- # webkit = playwright.webkit
1147
- # browser = await webkit.launch(headless=False)
1148
- # page = await browser.new_page()
1149
- # await page.expose_function("sha1", sha1)
1150
- # await page.set_content("""
1151
- # <script>
1152
- # async function onClick() {
1153
- # document.querySelector('div').textContent = await window.sha1('PLAYWRIGHT');
1154
- # }
1155
- # </script>
1156
- # <button onclick="onClick()">Click me</button>
1157
- # <div></div>
1158
- # """)
1159
- # await page.click("button")
1160
- #
1161
- # async def main():
1162
- # async with async_playwright() as playwright:
1163
- # await run(playwright)
1164
- # asyncio.run(main())
1165
- # ```
1166
- #
438
+ #
1167
439
  # ```python sync
1168
440
  # import hashlib
1169
441
  # from playwright.sync_api import sync_playwright
1170
- #
442
+ #
1171
443
  # def sha1(text):
1172
444
  # m = hashlib.sha1()
1173
445
  # m.update(bytes(text, "utf8"))
1174
446
  # return m.hexdigest()
1175
- #
1176
- #
447
+ #
448
+ #
1177
449
  # def run(playwright):
1178
450
  # webkit = playwright.webkit
1179
451
  # browser = webkit.launch(headless=False)
@@ -1189,46 +461,10 @@ module Playwright
1189
461
  # <div></div>
1190
462
  # """)
1191
463
  # page.click("button")
1192
- #
464
+ #
1193
465
  # with sync_playwright() as playwright:
1194
466
  # run(playwright)
1195
467
  # ```
1196
- #
1197
- # ```csharp
1198
- # using Microsoft.Playwright;
1199
- # using System;
1200
- # using System.Security.Cryptography;
1201
- # using System.Threading.Tasks;
1202
- #
1203
- # class PageExamples
1204
- # {
1205
- # public static async Task Main()
1206
- # {
1207
- # using var playwright = await Playwright.CreateAsync();
1208
- # await using var browser = await playwright.Webkit.LaunchAsync(headless: false);
1209
- # var page = await browser.NewPageAsync();
1210
- #
1211
- # // NOTE: md5 is inherently insecure, and we strongly discourage using
1212
- # // this in production in any shape or form
1213
- # await page.ExposeFunctionAsync("sha1", (string input) =>
1214
- # {
1215
- # return Convert.ToBase64String(
1216
- # MD5.Create().ComputeHash(System.Text.Encoding.UTF8.GetBytes(input)));
1217
- # });
1218
- #
1219
- # await page.SetContentAsync("<script>\n" +
1220
- # " async function onClick() {\n" +
1221
- # " document.querySelector('div').textContent = await window.sha1('PLAYWRIGHT');\n" +
1222
- # " }\n" +
1223
- # "</script>\n" +
1224
- # "<button onclick=\"onClick()\">Click me</button>\n" +
1225
- # "<div></div>");
1226
- #
1227
- # await page.ClickAsync("button");
1228
- # Console.WriteLine(await page.TextContentAsync("div"));
1229
- # }
1230
- # }
1231
- # ```
1232
468
  def expose_function(name, callback)
1233
469
  wrap_impl(@impl.expose_function(unwrap_impl(name), unwrap_impl(callback)))
1234
470
  end
@@ -1236,14 +472,14 @@ module Playwright
1236
472
  # This method waits for an element matching `selector`, waits for [actionability](./actionability.md) checks, focuses the
1237
473
  # element, fills it and triggers an `input` event after filling. Note that you can pass an empty string to clear the input
1238
474
  # field.
1239
- #
475
+ #
1240
476
  # If the target element is not an `<input>`, `<textarea>` or `[contenteditable]` element, this method throws an error.
1241
477
  # However, if the element is inside the `<label>` element that has an associated
1242
478
  # [control](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control), the control will be filled
1243
479
  # instead.
1244
- #
480
+ #
1245
481
  # To send fine-grained keyboard events, use [`method: Page.type`].
1246
- #
482
+ #
1247
483
  # Shortcut for main frame's [`method: Frame.fill`].
1248
484
  def fill(selector, value, noWaitAfter: nil, timeout: nil)
1249
485
  wrap_impl(@impl.fill(unwrap_impl(selector), unwrap_impl(value), noWaitAfter: unwrap_impl(noWaitAfter), timeout: unwrap_impl(timeout)))
@@ -1251,47 +487,21 @@ module Playwright
1251
487
 
1252
488
  # This method fetches an element with `selector` and focuses it. If there's no element matching `selector`, the method
1253
489
  # waits until a matching element appears in the DOM.
1254
- #
490
+ #
1255
491
  # Shortcut for main frame's [`method: Frame.focus`].
1256
492
  def focus(selector, timeout: nil)
1257
493
  wrap_impl(@impl.focus(unwrap_impl(selector), timeout: unwrap_impl(timeout)))
1258
494
  end
1259
495
 
1260
496
  # Returns frame matching the specified criteria. Either `name` or `url` must be specified.
1261
- #
1262
497
  #
1263
- # ```js
1264
- # const frame = page.frame('frame-name');
1265
- # ```
1266
- #
1267
- # ```java
1268
- # Frame frame = page.frame("frame-name");
1269
- # ```
1270
- #
1271
498
  # ```py
1272
499
  # frame = page.frame(name="frame-name")
1273
500
  # ```
1274
- #
1275
- # ```csharp
1276
- # var frame = page.Frame("frame-name");
1277
- # ```
1278
- #
1279
501
  #
1280
- # ```js
1281
- # const frame = page.frame({ url: /.*domain.*/ });
1282
- # ```
1283
- #
1284
- # ```java
1285
- # Frame frame = page.frameByUrl(Pattern.compile(".*domain.*");
1286
- # ```
1287
- #
1288
502
  # ```py
1289
503
  # frame = page.frame(url=r".*domain.*")
1290
504
  # ```
1291
- #
1292
- # ```csharp
1293
- # var frame = page.FrameByUrl(".*domain.*");
1294
- # ```
1295
505
  def frame(name: nil, url: nil)
1296
506
  wrap_impl(@impl.frame(name: unwrap_impl(name), url: unwrap_impl(url)))
1297
507
  end
@@ -1308,7 +518,7 @@ module Playwright
1308
518
 
1309
519
  # Returns the main resource response. In case of multiple redirects, the navigation will resolve with the response of the
1310
520
  # last redirect. If can not go back, returns `null`.
1311
- #
521
+ #
1312
522
  # Navigate to the previous page in history.
1313
523
  def go_back(timeout: nil, waitUntil: nil)
1314
524
  wrap_impl(@impl.go_back(timeout: unwrap_impl(timeout), waitUntil: unwrap_impl(waitUntil)))
@@ -1316,7 +526,7 @@ module Playwright
1316
526
 
1317
527
  # Returns the main resource response. In case of multiple redirects, the navigation will resolve with the response of the
1318
528
  # last redirect. If can not go forward, returns `null`.
1319
- #
529
+ #
1320
530
  # Navigate to the next page in history.
1321
531
  def go_forward(timeout: nil, waitUntil: nil)
1322
532
  wrap_impl(@impl.go_forward(timeout: unwrap_impl(timeout), waitUntil: unwrap_impl(waitUntil)))
@@ -1324,23 +534,23 @@ module Playwright
1324
534
 
1325
535
  # Returns the main resource response. In case of multiple redirects, the navigation will resolve with the response of the
1326
536
  # last redirect.
1327
- #
537
+ #
1328
538
  # `page.goto` will throw an error if:
1329
539
  # - there's an SSL error (e.g. in case of self-signed certificates).
1330
540
  # - target URL is invalid.
1331
541
  # - the `timeout` is exceeded during navigation.
1332
542
  # - the remote server does not respond or is unreachable.
1333
543
  # - the main resource failed to load.
1334
- #
544
+ #
1335
545
  # `page.goto` will not throw an error when any valid HTTP status code is returned by the remote server, including 404 "Not
1336
546
  # Found" and 500 "Internal Server Error". The status code for such responses can be retrieved by calling
1337
547
  # [`method: Response.status`].
1338
- #
548
+ #
1339
549
  # > NOTE: `page.goto` either throws an error or returns a main resource response. The only exceptions are navigation to
1340
550
  # `about:blank` or navigation to the same URL with a different hash, which would succeed and return `null`.
1341
551
  # > NOTE: Headless mode doesn't support navigation to a PDF document. See the
1342
552
  # [upstream issue](https://bugs.chromium.org/p/chromium/issues/detail?id=761295).
1343
- #
553
+ #
1344
554
  # Shortcut for main frame's [`method: Frame.goto`]
1345
555
  def goto(url, referer: nil, timeout: nil, waitUntil: nil)
1346
556
  wrap_impl(@impl.goto(unwrap_impl(url), referer: unwrap_impl(referer), timeout: unwrap_impl(timeout), waitUntil: unwrap_impl(waitUntil)))
@@ -1353,10 +563,10 @@ module Playwright
1353
563
  # 1. Scroll the element into view if needed.
1354
564
  # 1. Use [`property: Page.mouse`] to hover over the center of the element, or the specified `position`.
1355
565
  # 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
1356
- #
566
+ #
1357
567
  # When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
1358
568
  # zero timeout disables this.
1359
- #
569
+ #
1360
570
  # Shortcut for main frame's [`method: Frame.hover`].
1361
571
  def hover(
1362
572
  selector,
@@ -1427,10 +637,10 @@ module Playwright
1427
637
 
1428
638
  # Pauses script execution. Playwright will stop executing the script and wait for the user to either press 'Resume' button
1429
639
  # in the page overlay or to call `playwright.resume()` in the DevTools console.
1430
- #
640
+ #
1431
641
  # User can inspect selectors or perform manual steps while paused. Resume will continue running the original script from
1432
642
  # the place it was paused.
1433
- #
643
+ #
1434
644
  # > NOTE: This method requires Playwright to be started in a headed mode, with a falsy `headless` value in the
1435
645
  # [`method: BrowserType.launch`].
1436
646
  def pause
@@ -1438,60 +648,35 @@ module Playwright
1438
648
  end
1439
649
 
1440
650
  # Returns the PDF buffer.
1441
- #
651
+ #
1442
652
  # > NOTE: Generating a pdf is currently only supported in Chromium headless.
1443
- #
653
+ #
1444
654
  # `page.pdf()` generates a pdf of the page with `print` css media. To generate a pdf with `screen` media, call
1445
655
  # [`method: Page.emulateMedia`] before calling `page.pdf()`:
1446
- #
656
+ #
1447
657
  # > NOTE: By default, `page.pdf()` generates a pdf with modified colors for printing. Use the
1448
658
  # [`-webkit-print-color-adjust`](https://developer.mozilla.org/en-US/docs/Web/CSS/-webkit-print-color-adjust) property to
1449
659
  # force rendering of exact colors.
1450
- #
1451
660
  #
1452
- # ```js
1453
- # // Generates a PDF with 'screen' media type.
1454
- # await page.emulateMedia({media: 'screen'});
1455
- # await page.pdf({path: 'page.pdf'});
1456
- # ```
1457
- #
1458
- # ```java
1459
- # // Generates a PDF with "screen" media type.
1460
- # page.emulateMedia(new Page.EmulateMediaOptions().setMedia(Media.SCREEN));
1461
- # page.pdf(new Page.PdfOptions().setPath(Paths.get("page.pdf")));
1462
- # ```
1463
- #
1464
- # ```python async
1465
- # # generates a pdf with "screen" media type.
1466
- # await page.emulate_media(media="screen")
1467
- # await page.pdf(path="page.pdf")
1468
- # ```
1469
- #
1470
661
  # ```python sync
1471
662
  # # generates a pdf with "screen" media type.
1472
663
  # page.emulate_media(media="screen")
1473
664
  # page.pdf(path="page.pdf")
1474
665
  # ```
1475
- #
1476
- # ```csharp
1477
- # // Generates a PDF with 'screen' media type
1478
- # await page.EmulateMediaAsync(Media.Screen);
1479
- # await page.PdfAsync("page.pdf");
1480
- # ```
1481
- #
666
+ #
1482
667
  # The `width`, `height`, and `margin` options accept values labeled with units. Unlabeled values are treated as pixels.
1483
- #
668
+ #
1484
669
  # A few examples:
1485
670
  # - `page.pdf({width: 100})` - prints with width set to 100 pixels
1486
671
  # - `page.pdf({width: '100px'})` - prints with width set to 100 pixels
1487
672
  # - `page.pdf({width: '10cm'})` - prints with width set to 10 centimeters.
1488
- #
673
+ #
1489
674
  # All possible units are:
1490
675
  # - `px` - pixel
1491
676
  # - `in` - inch
1492
677
  # - `cm` - centimeter
1493
678
  # - `mm` - millimeter
1494
- #
679
+ #
1495
680
  # The `format` options are:
1496
681
  # - `Letter`: 8.5in x 11in
1497
682
  # - `Legal`: 8.5in x 14in
@@ -1504,7 +689,7 @@ module Playwright
1504
689
  # - `A4`: 8.27in x 11.7in
1505
690
  # - `A5`: 5.83in x 8.27in
1506
691
  # - `A6`: 4.13in x 5.83in
1507
- #
692
+ #
1508
693
  # > NOTE: `headerTemplate` and `footerTemplate` markup have the following limitations: > 1. Script tags inside templates
1509
694
  # are not evaluated. > 2. Page styles are not visible inside templates.
1510
695
  def pdf(
@@ -1525,60 +710,24 @@ module Playwright
1525
710
  end
1526
711
 
1527
712
  # Focuses the element, and then uses [`method: Keyboard.down`] and [`method: Keyboard.up`].
1528
- #
713
+ #
1529
714
  # `key` can specify the intended [keyboardEvent.key](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key)
1530
715
  # value or a single character to generate the text for. A superset of the `key` values can be found
1531
716
  # [here](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values). Examples of the keys are:
1532
- #
717
+ #
1533
718
  # `F1` - `F12`, `Digit0`- `Digit9`, `KeyA`- `KeyZ`, `Backquote`, `Minus`, `Equal`, `Backslash`, `Backspace`, `Tab`,
1534
719
  # `Delete`, `Escape`, `ArrowDown`, `End`, `Enter`, `Home`, `Insert`, `PageDown`, `PageUp`, `ArrowRight`, `ArrowUp`, etc.
1535
- #
720
+ #
1536
721
  # Following modification shortcuts are also supported: `Shift`, `Control`, `Alt`, `Meta`, `ShiftLeft`.
1537
- #
722
+ #
1538
723
  # Holding down `Shift` will type the text that corresponds to the `key` in the upper case.
1539
- #
724
+ #
1540
725
  # If `key` is a single character, it is case-sensitive, so the values `a` and `A` will generate different respective
1541
726
  # texts.
1542
- #
727
+ #
1543
728
  # Shortcuts such as `key: "Control+o"` or `key: "Control+Shift+T"` are supported as well. When specified with the
1544
729
  # modifier, modifier is pressed and being held while the subsequent key is being pressed.
1545
- #
1546
- #
1547
- # ```js
1548
- # const page = await browser.newPage();
1549
- # await page.goto('https://keycode.info');
1550
- # await page.press('body', 'A');
1551
- # await page.screenshot({ path: 'A.png' });
1552
- # await page.press('body', 'ArrowLeft');
1553
- # await page.screenshot({ path: 'ArrowLeft.png' });
1554
- # await page.press('body', 'Shift+O');
1555
- # await page.screenshot({ path: 'O.png' });
1556
- # await browser.close();
1557
- # ```
1558
- #
1559
- # ```java
1560
- # Page page = browser.newPage();
1561
- # page.navigate("https://keycode.info");
1562
- # page.press("body", "A");
1563
- # page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get("A.png")));
1564
- # page.press("body", "ArrowLeft");
1565
- # page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get("ArrowLeft.png" )));
1566
- # page.press("body", "Shift+O");
1567
- # page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get("O.png" )));
1568
- # ```
1569
- #
1570
- # ```python async
1571
- # page = await browser.new_page()
1572
- # await page.goto("https://keycode.info")
1573
- # await page.press("body", "A")
1574
- # await page.screenshot(path="a.png")
1575
- # await page.press("body", "ArrowLeft")
1576
- # await page.screenshot(path="arrow_left.png")
1577
- # await page.press("body", "Shift+O")
1578
- # await page.screenshot(path="o.png")
1579
- # await browser.close()
1580
- # ```
1581
- #
730
+ #
1582
731
  # ```python sync
1583
732
  # page = browser.new_page()
1584
733
  # page.goto("https://keycode.info")
@@ -1590,18 +739,6 @@ module Playwright
1590
739
  # page.screenshot(path="o.png")
1591
740
  # browser.close()
1592
741
  # ```
1593
- #
1594
- # ```csharp
1595
- # await using var browser = await playwright.Webkit.LaunchAsync(headless: false);
1596
- # var page = await browser.NewPageAsync();
1597
- # await page.GotoAsync("https://keycode.info");
1598
- # await page.PressAsync("body", "A");
1599
- # await page.ScreenshotAsync("A.png");
1600
- # await page.PressAsync("body", "ArrowLeft");
1601
- # await page.ScreenshotAsync("ArrowLeft.png");
1602
- # await page.PressAsync("body", "Shift+O");
1603
- # await page.ScreenshotAsync("O.png");
1604
- # ```
1605
742
  def press(
1606
743
  selector,
1607
744
  key,
@@ -1613,7 +750,7 @@ module Playwright
1613
750
 
1614
751
  # The method finds an element matching the specified selector within the page. If no elements match the selector, the
1615
752
  # return value resolves to `null`. To wait for an element on the page, use [`method: Page.waitForSelector`].
1616
- #
753
+ #
1617
754
  # Shortcut for main frame's [`method: Frame.querySelector`].
1618
755
  def query_selector(selector)
1619
756
  wrap_impl(@impl.query_selector(unwrap_impl(selector)))
@@ -1621,7 +758,7 @@ module Playwright
1621
758
 
1622
759
  # The method finds all elements matching the specified selector within the page. If no elements match the selector, the
1623
760
  # return value resolves to `[]`.
1624
- #
761
+ #
1625
762
  # Shortcut for main frame's [`method: Frame.querySelectorAll`].
1626
763
  def query_selector_all(selector)
1627
764
  wrap_impl(@impl.query_selector_all(unwrap_impl(selector)))
@@ -1634,118 +771,32 @@ module Playwright
1634
771
  end
1635
772
 
1636
773
  # Routing provides the capability to modify network requests that are made by a page.
1637
- #
774
+ #
1638
775
  # Once routing is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted.
1639
- #
776
+ #
1640
777
  # > NOTE: The handler will only be called for the first url if the response is a redirect.
1641
- #
778
+ #
1642
779
  # An example of a naive handler that aborts all image requests:
1643
- #
1644
780
  #
1645
- # ```js
1646
- # const page = await browser.newPage();
1647
- # await page.route('**/*.{png,jpg,jpeg}', route => route.abort());
1648
- # await page.goto('https://example.com');
1649
- # await browser.close();
1650
- # ```
1651
- #
1652
- # ```java
1653
- # Page page = browser.newPage();
1654
- # page.route("**/*.{png,jpg,jpeg}", route -> route.abort());
1655
- # page.navigate("https://example.com");
1656
- # browser.close();
1657
- # ```
1658
- #
1659
- # ```python async
1660
- # page = await browser.new_page()
1661
- # await page.route("**/*.{png,jpg,jpeg}", lambda route: route.abort())
1662
- # await page.goto("https://example.com")
1663
- # await browser.close()
1664
- # ```
1665
- #
1666
781
  # ```python sync
1667
782
  # page = browser.new_page()
1668
783
  # page.route("**/*.{png,jpg,jpeg}", lambda route: route.abort())
1669
784
  # page.goto("https://example.com")
1670
785
  # browser.close()
1671
786
  # ```
1672
- #
1673
- # ```csharp
1674
- # await using var browser = await playwright.Webkit.LaunchAsync();
1675
- # var page = await browser.NewPageAsync();
1676
- # await page.RouteAsync("**/*.{png,jpg,jpeg}", async r => await r.AbortAsync());
1677
- # await page.GotoAsync("https://www.microsoft.com");
1678
- # ```
1679
- #
787
+ #
1680
788
  # or the same snippet using a regex pattern instead:
1681
- #
1682
789
  #
1683
- # ```js
1684
- # const page = await browser.newPage();
1685
- # await page.route(/(\.png$)|(\.jpg$)/, route => route.abort());
1686
- # await page.goto('https://example.com');
1687
- # await browser.close();
1688
- # ```
1689
- #
1690
- # ```java
1691
- # Page page = browser.newPage();
1692
- # page.route(Pattern.compile("(\\.png$)|(\\.jpg$)"),route -> route.abort());
1693
- # page.navigate("https://example.com");
1694
- # browser.close();
1695
- # ```
1696
- #
1697
- # ```python async
1698
- # page = await browser.new_page()
1699
- # await page.route(re.compile(r"(\.png$)|(\.jpg$)"), lambda route: route.abort())
1700
- # await page.goto("https://example.com")
1701
- # await browser.close()
1702
- # ```
1703
- #
1704
790
  # ```python sync
1705
791
  # page = browser.new_page()
1706
792
  # page.route(re.compile(r"(\.png$)|(\.jpg$)"), lambda route: route.abort())
1707
793
  # page.goto("https://example.com")
1708
794
  # browser.close()
1709
795
  # ```
1710
- #
1711
- # ```csharp
1712
- # await using var browser = await playwright.Webkit.LaunchAsync();
1713
- # var page = await browser.NewPageAsync();
1714
- # await page.RouteAsync(new Regex("(\\.png$)|(\\.jpg$)"), async r => await r.AbortAsync());
1715
- # await page.GotoAsync("https://www.microsoft.com");
1716
- # ```
1717
- #
796
+ #
1718
797
  # It is possible to examine the request to decide the route action. For example, mocking all requests that contain some
1719
798
  # post data, and leaving all other requests as is:
1720
- #
1721
799
  #
1722
- # ```js
1723
- # await page.route('/api/**', route => {
1724
- # if (route.request().postData().includes('my-string'))
1725
- # route.fulfill({ body: 'mocked-data' });
1726
- # else
1727
- # route.continue();
1728
- # });
1729
- # ```
1730
- #
1731
- # ```java
1732
- # page.route("/api/**", route -> {
1733
- # if (route.request().postData().contains("my-string"))
1734
- # route.fulfill(new Route.FulfillOptions().setBody("mocked-data"));
1735
- # else
1736
- # route.resume();
1737
- # });
1738
- # ```
1739
- #
1740
- # ```python async
1741
- # def handle_route(route):
1742
- # if ("my-string" in route.request.post_data)
1743
- # route.fulfill(body="mocked-data")
1744
- # else
1745
- # route.continue_()
1746
- # await page.route("/api/**", handle_route)
1747
- # ```
1748
- #
1749
800
  # ```python sync
1750
801
  # def handle_route(route):
1751
802
  # if ("my-string" in route.request.post_data)
@@ -1754,22 +805,12 @@ module Playwright
1754
805
  # route.continue_()
1755
806
  # page.route("/api/**", handle_route)
1756
807
  # ```
1757
- #
1758
- # ```csharp
1759
- # await page.RouteAsync("/api/**", async r =>
1760
- # {
1761
- # if (r.Request.PostData.Contains("my-string"))
1762
- # await r.FulfillAsync(body: "mocked-data");
1763
- # else
1764
- # await r.ContinueAsync();
1765
- # });
1766
- # ```
1767
- #
808
+ #
1768
809
  # Page routes take precedence over browser context routes (set up with [`method: BrowserContext.route`]) when request
1769
810
  # matches both handlers.
1770
- #
811
+ #
1771
812
  # To remove a route with its handler you can use [`method: Page.unroute`].
1772
- #
813
+ #
1773
814
  # > NOTE: Enabling routing disables http cache.
1774
815
  def route(url, handler)
1775
816
  wrap_impl(@impl.route(unwrap_impl(url), unwrap_impl(handler)))
@@ -1789,46 +830,15 @@ module Playwright
1789
830
 
1790
831
  # This method waits for an element matching `selector`, waits for [actionability](./actionability.md) checks, waits until
1791
832
  # all specified options are present in the `<select>` element and selects these options.
1792
- #
833
+ #
1793
834
  # If the target element is not a `<select>` element, this method throws an error. However, if the element is inside the
1794
835
  # `<label>` element that has an associated
1795
836
  # [control](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control), the control will be used instead.
1796
- #
837
+ #
1797
838
  # Returns the array of option values that have been successfully selected.
1798
- #
839
+ #
1799
840
  # Triggers a `change` and `input` event once all the provided options have been selected.
1800
- #
1801
- #
1802
- # ```js
1803
- # // single selection matching the value
1804
- # page.selectOption('select#colors', 'blue');
1805
- #
1806
- # // single selection matching the label
1807
- # page.selectOption('select#colors', { label: 'Blue' });
1808
- #
1809
- # // multiple selection
1810
- # page.selectOption('select#colors', ['red', 'green', 'blue']);
1811
- #
1812
- # ```
1813
- #
1814
- # ```java
1815
- # // single selection matching the value
1816
- # page.selectOption("select#colors", "blue");
1817
- # // single selection matching both the value and the label
1818
- # page.selectOption("select#colors", new SelectOption().setLabel("Blue"));
1819
- # // multiple selection
1820
- # page.selectOption("select#colors", new String[] {"red", "green", "blue"});
1821
- # ```
1822
- #
1823
- # ```python async
1824
- # # single selection matching the value
1825
- # await page.select_option("select#colors", "blue")
1826
- # # single selection matching the label
1827
- # await page.select_option("select#colors", label="blue")
1828
- # # multiple selection
1829
- # await page.select_option("select#colors", value=["red", "green", "blue"])
1830
- # ```
1831
- #
841
+ #
1832
842
  # ```python sync
1833
843
  # # single selection matching the value
1834
844
  # page.select_option("select#colors", "blue")
@@ -1837,16 +847,7 @@ module Playwright
1837
847
  # # multiple selection
1838
848
  # page.select_option("select#colors", value=["red", "green", "blue"])
1839
849
  # ```
1840
- #
1841
- # ```csharp
1842
- # // single selection matching the value
1843
- # await page.SelectOptionAsync("select#colors", new[] { "blue" });
1844
- # // single selection matching both the value and the label
1845
- # await page.SelectOptionAsync("select#colors", new[] { new SelectOptionValue() { Label = "blue" } });
1846
- # // multiple
1847
- # await page.SelectOptionAsync("select#colors", new[] { "red", "green", "blue" });
1848
- # ```
1849
- #
850
+ #
1850
851
  # Shortcut for main frame's [`method: Frame.selectOption`].
1851
852
  def select_option(
1852
853
  selector,
@@ -1872,7 +873,7 @@ module Playwright
1872
873
  # - [`method: Page.setContent`]
1873
874
  # - [`method: Page.waitForNavigation`]
1874
875
  # - [`method: Page.waitForURL`]
1875
- #
876
+ #
1876
877
  # > NOTE: [`method: Page.setDefaultNavigationTimeout`] takes priority over [`method: Page.setDefaultTimeout`],
1877
878
  # [`method: BrowserContext.setDefaultTimeout`] and [`method: BrowserContext.setDefaultNavigationTimeout`].
1878
879
  def set_default_navigation_timeout(timeout)
@@ -1881,7 +882,7 @@ module Playwright
1881
882
  alias_method :default_navigation_timeout=, :set_default_navigation_timeout
1882
883
 
1883
884
  # This setting will change the default maximum time for all the methods accepting `timeout` option.
1884
- #
885
+ #
1885
886
  # > NOTE: [`method: Page.setDefaultNavigationTimeout`] takes priority over [`method: Page.setDefaultTimeout`].
1886
887
  def set_default_timeout(timeout)
1887
888
  wrap_impl(@impl.set_default_timeout(unwrap_impl(timeout)))
@@ -1889,7 +890,7 @@ module Playwright
1889
890
  alias_method :default_timeout=, :set_default_timeout
1890
891
 
1891
892
  # The extra HTTP headers will be sent with every request the page initiates.
1892
- #
893
+ #
1893
894
  # > NOTE: [`method: Page.setExtraHTTPHeaders`] does not guarantee the order of headers in the outgoing requests.
1894
895
  def set_extra_http_headers(headers)
1895
896
  wrap_impl(@impl.set_extra_http_headers(unwrap_impl(headers)))
@@ -1898,7 +899,7 @@ module Playwright
1898
899
 
1899
900
  # This method expects `selector` to point to an
1900
901
  # [input element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input).
1901
- #
902
+ #
1902
903
  # Sets the value of the file input to these file paths or files. If some of the `filePaths` are relative paths, then they
1903
904
  # are resolved relative to the the current working directory. For empty array, clears the selected files.
1904
905
  def set_input_files(selector, files, noWaitAfter: nil, timeout: nil)
@@ -1907,43 +908,15 @@ module Playwright
1907
908
 
1908
909
  # In the case of multiple pages in a single browser, each page can have its own viewport size. However,
1909
910
  # [`method: Browser.newContext`] allows to set viewport size (and more) for all pages in the context at once.
1910
- #
911
+ #
1911
912
  # `page.setViewportSize` will resize the page. A lot of websites don't expect phones to change size, so you should set the
1912
913
  # viewport size before navigating to the page.
1913
- #
1914
- #
1915
- # ```js
1916
- # const page = await browser.newPage();
1917
- # await page.setViewportSize({
1918
- # width: 640,
1919
- # height: 480,
1920
- # });
1921
- # await page.goto('https://example.com');
1922
- # ```
1923
- #
1924
- # ```java
1925
- # Page page = browser.newPage();
1926
- # page.setViewportSize(640, 480);
1927
- # page.navigate("https://example.com");
1928
- # ```
1929
- #
1930
- # ```python async
1931
- # page = await browser.new_page()
1932
- # await page.set_viewport_size({"width": 640, "height": 480})
1933
- # await page.goto("https://example.com")
1934
- # ```
1935
- #
914
+ #
1936
915
  # ```python sync
1937
916
  # page = browser.new_page()
1938
917
  # page.set_viewport_size({"width": 640, "height": 480})
1939
918
  # page.goto("https://example.com")
1940
919
  # ```
1941
- #
1942
- # ```csharp
1943
- # var page = await browser.NewPageAsync();
1944
- # await page.SetViewportSizeAsync(640, 480);
1945
- # await page.GotoAsync("https://www.microsoft.com");
1946
- # ```
1947
920
  def set_viewport_size(viewportSize)
1948
921
  wrap_impl(@impl.set_viewport_size(unwrap_impl(viewportSize)))
1949
922
  end
@@ -1956,12 +929,12 @@ module Playwright
1956
929
  # 1. Scroll the element into view if needed.
1957
930
  # 1. Use [`property: Page.touchscreen`] to tap the center of the element, or the specified `position`.
1958
931
  # 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
1959
- #
932
+ #
1960
933
  # When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
1961
934
  # zero timeout disables this.
1962
- #
935
+ #
1963
936
  # > NOTE: [`method: Page.tap`] requires that the `hasTouch` option of the browser context be set to true.
1964
- #
937
+ #
1965
938
  # Shortcut for main frame's [`method: Frame.tap`].
1966
939
  def tap_point(
1967
940
  selector,
@@ -1986,37 +959,14 @@ module Playwright
1986
959
 
1987
960
  # Sends a `keydown`, `keypress`/`input`, and `keyup` event for each character in the text. `page.type` can be used to send
1988
961
  # fine-grained keyboard events. To fill values in form fields, use [`method: Page.fill`].
1989
- #
962
+ #
1990
963
  # To press a special key, like `Control` or `ArrowDown`, use [`method: Keyboard.press`].
1991
- #
1992
964
  #
1993
- # ```js
1994
- # await page.type('#mytextarea', 'Hello'); // Types instantly
1995
- # await page.type('#mytextarea', 'World', {delay: 100}); // Types slower, like a user
1996
- # ```
1997
- #
1998
- # ```java
1999
- # // Types instantly
2000
- # page.type("#mytextarea", "Hello");
2001
- # // Types slower, like a user
2002
- # page.type("#mytextarea", "World", new Page.TypeOptions().setDelay(100));
2003
- # ```
2004
- #
2005
- # ```python async
2006
- # await page.type("#mytextarea", "hello") # types instantly
2007
- # await page.type("#mytextarea", "world", delay=100) # types slower, like a user
2008
- # ```
2009
- #
2010
965
  # ```python sync
2011
966
  # page.type("#mytextarea", "hello") # types instantly
2012
967
  # page.type("#mytextarea", "world", delay=100) # types slower, like a user
2013
968
  # ```
2014
- #
2015
- # ```csharp
2016
- # await page.TypeAsync("#mytextarea", "hello"); // types instantly
2017
- # await page.TypeAsync("#mytextarea", "world"); // types slower, like a user
2018
- # ```
2019
- #
969
+ #
2020
970
  # Shortcut for main frame's [`method: Frame.type`].
2021
971
  def type(
2022
972
  selector,
@@ -2037,10 +987,10 @@ module Playwright
2037
987
  # 1. Use [`property: Page.mouse`] to click in the center of the element.
2038
988
  # 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
2039
989
  # 1. Ensure that the element is now unchecked. If not, this method throws.
2040
- #
990
+ #
2041
991
  # When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
2042
992
  # zero timeout disables this.
2043
- #
993
+ #
2044
994
  # Shortcut for main frame's [`method: Frame.uncheck`].
2045
995
  def uncheck(
2046
996
  selector,
@@ -2087,32 +1037,12 @@ module Playwright
2087
1037
 
2088
1038
  # Waits for event to fire and passes its value into the predicate function. Returns when the predicate returns truthy
2089
1039
  # value. Will throw an error if the page is closed before the event is fired. Returns the event data value.
2090
- #
2091
1040
  #
2092
- # ```js
2093
- # const [frame, _] = await Promise.all([
2094
- # page.waitForEvent('framenavigated'),
2095
- # page.click('button')
2096
- # ]);
2097
- # ```
2098
- #
2099
- # ```python async
2100
- # async with page.expect_event("framenavigated") as event_info:
2101
- # await page.click("button")
2102
- # frame = await event_info.value
2103
- # ```
2104
- #
2105
1041
  # ```python sync
2106
1042
  # with page.expect_event("framenavigated") as event_info:
2107
1043
  # page.click("button")
2108
1044
  # frame = event_info.value
2109
1045
  # ```
2110
- #
2111
- # ```csharp
2112
- # var waitTask = page.WaitForEventAsync(PageEvent.FrameNavigated);
2113
- # await page.ClickAsync("button");
2114
- # var frame = await waitTask;
2115
- # ```
2116
1046
  def expect_event(event, predicate: nil, timeout: nil, &block)
2117
1047
  wrap_impl(@impl.expect_event(unwrap_impl(event), predicate: unwrap_impl(predicate), timeout: unwrap_impl(timeout), &wrap_block_call(block)))
2118
1048
  end
@@ -2125,61 +1055,12 @@ module Playwright
2125
1055
  end
2126
1056
 
2127
1057
  # Returns when the `expression` returns a truthy value. It resolves to a JSHandle of the truthy value.
2128
- #
1058
+ #
2129
1059
  # The [`method: Page.waitForFunction`] can be used to observe viewport size change:
2130
- #
2131
- #
2132
- # ```js
2133
- # const { webkit } = require('playwright'); // Or 'chromium' or 'firefox'.
2134
- #
2135
- # (async () => {
2136
- # const browser = await webkit.launch();
2137
- # const page = await browser.newPage();
2138
- # const watchDog = page.waitForFunction(() => window.innerWidth < 100);
2139
- # await page.setViewportSize({width: 50, height: 50});
2140
- # await watchDog;
2141
- # await browser.close();
2142
- # })();
2143
- # ```
2144
- #
2145
- # ```java
2146
- # import com.microsoft.playwright.*;
2147
- #
2148
- # public class Example {
2149
- # public static void main(String[] args) {
2150
- # try (Playwright playwright = Playwright.create()) {
2151
- # BrowserType webkit = playwright.webkit();
2152
- # Browser browser = webkit.launch();
2153
- # Page page = browser.newPage();
2154
- # page.setViewportSize(50, 50);
2155
- # page.waitForFunction("() => window.innerWidth < 100");
2156
- # browser.close();
2157
- # }
2158
- # }
2159
- # }
2160
- # ```
2161
- #
2162
- # ```python async
2163
- # import asyncio
2164
- # from playwright.async_api import async_playwright
2165
- #
2166
- # async def run(playwright):
2167
- # webkit = playwright.webkit
2168
- # browser = await webkit.launch()
2169
- # page = await browser.new_page()
2170
- # await page.evaluate("window.x = 0; setTimeout(() => { window.x = 100 }, 1000);")
2171
- # await page.wait_for_function("() => window.x > 0")
2172
- # await browser.close()
2173
- #
2174
- # async def main():
2175
- # async with async_playwright() as playwright:
2176
- # await run(playwright)
2177
- # asyncio.run(main())
2178
- # ```
2179
- #
1060
+ #
2180
1061
  # ```python sync
2181
1062
  # from playwright.sync_api import sync_playwright
2182
- #
1063
+ #
2183
1064
  # def run(playwright):
2184
1065
  # webkit = playwright.webkit
2185
1066
  # browser = webkit.launch()
@@ -2187,119 +1068,33 @@ module Playwright
2187
1068
  # page.evaluate("window.x = 0; setTimeout(() => { window.x = 100 }, 1000);")
2188
1069
  # page.wait_for_function("() => window.x > 0")
2189
1070
  # browser.close()
2190
- #
1071
+ #
2191
1072
  # with sync_playwright() as playwright:
2192
1073
  # run(playwright)
2193
1074
  # ```
2194
- #
2195
- # ```csharp
2196
- # using Microsoft.Playwright;
2197
- # using System.Threading.Tasks;
2198
- #
2199
- # class FrameExamples
2200
- # {
2201
- # public static async Task WaitForFunction()
2202
- # {
2203
- # using var playwright = await Playwright.CreateAsync();
2204
- # await using var browser = await playwright.Webkit.LaunchAsync();
2205
- # var page = await browser.NewPageAsync();
2206
- # await page.SetViewportSizeAsync(50, 50);
2207
- # await page.MainFrame.WaitForFunctionAsync("window.innerWidth < 100");
2208
- # }
2209
- # }
2210
- # ```
2211
- #
1075
+ #
2212
1076
  # To pass an argument to the predicate of [`method: Page.waitForFunction`] function:
2213
- #
2214
1077
  #
2215
- # ```js
2216
- # const selector = '.foo';
2217
- # await page.waitForFunction(selector => !!document.querySelector(selector), selector);
2218
- # ```
2219
- #
2220
- # ```java
2221
- # String selector = ".foo";
2222
- # page.waitForFunction("selector => !!document.querySelector(selector)", selector);
2223
- # ```
2224
- #
2225
- # ```python async
2226
- # selector = ".foo"
2227
- # await page.wait_for_function("selector => !!document.querySelector(selector)", selector)
2228
- # ```
2229
- #
2230
1078
  # ```python sync
2231
1079
  # selector = ".foo"
2232
1080
  # page.wait_for_function("selector => !!document.querySelector(selector)", selector)
2233
1081
  # ```
2234
- #
2235
- # ```csharp
2236
- # var selector = ".foo";
2237
- # await page.WaitForFunctionAsync("selector => !!document.querySelector(selector)", selector);
2238
- # ```
2239
- #
1082
+ #
2240
1083
  # Shortcut for main frame's [`method: Frame.waitForFunction`].
2241
1084
  def wait_for_function(expression, arg: nil, polling: nil, timeout: nil)
2242
1085
  wrap_impl(@impl.wait_for_function(unwrap_impl(expression), arg: unwrap_impl(arg), polling: unwrap_impl(polling), timeout: unwrap_impl(timeout)))
2243
1086
  end
2244
1087
 
2245
1088
  # Returns when the required load state has been reached.
2246
- #
1089
+ #
2247
1090
  # This resolves when the page reaches a required load state, `load` by default. The navigation must have been committed
2248
1091
  # when this method is called. If current document has already reached the required state, resolves immediately.
2249
- #
2250
1092
  #
2251
- # ```js
2252
- # await page.click('button'); // Click triggers navigation.
2253
- # await page.waitForLoadState(); // The promise resolves after 'load' event.
2254
- # ```
2255
- #
2256
- # ```java
2257
- # page.click("button"); // Click triggers navigation.
2258
- # page.waitForLoadState(); // The promise resolves after "load" event.
2259
- # ```
2260
- #
2261
- # ```python async
2262
- # await page.click("button") # click triggers navigation.
2263
- # await page.wait_for_load_state() # the promise resolves after "load" event.
2264
- # ```
2265
- #
2266
1093
  # ```python sync
2267
1094
  # page.click("button") # click triggers navigation.
2268
1095
  # page.wait_for_load_state() # the promise resolves after "load" event.
2269
1096
  # ```
2270
- #
2271
- # ```csharp
2272
- # await page.ClickAsync("button"); // Click triggers navigation.
2273
- # await page.WaitForLoadStateAsync(); // The promise resolves after 'load' event.
2274
- # ```
2275
- #
2276
- #
2277
- # ```js
2278
- # const [popup] = await Promise.all([
2279
- # page.waitForEvent('popup'),
2280
- # page.click('button'), // Click triggers a popup.
2281
- # ])
2282
- # await popup.waitForLoadState('domcontentloaded'); // The promise resolves after 'domcontentloaded' event.
2283
- # console.log(await popup.title()); // Popup is ready to use.
2284
- # ```
2285
- #
2286
- # ```java
2287
- # Page popup = page.waitForPopup(() -> {
2288
- # page.click("button"); // Click triggers a popup.
2289
- # });
2290
- # popup.waitForLoadState(LoadState.DOMCONTENTLOADED);
2291
- # System.out.println(popup.title()); // Popup is ready to use.
2292
- # ```
2293
- #
2294
- # ```python async
2295
- # async with page.expect_popup() as page_info:
2296
- # await page.click("button") # click triggers a popup.
2297
- # popup = await page_info.value
2298
- # # Following resolves after "domcontentloaded" event.
2299
- # await popup.wait_for_load_state("domcontentloaded")
2300
- # print(await popup.title()) # popup is ready to use.
2301
- # ```
2302
- #
1097
+ #
2303
1098
  # ```python sync
2304
1099
  # with page.expect_popup() as page_info:
2305
1100
  # page.click("button") # click triggers a popup.
@@ -2308,15 +1103,7 @@ module Playwright
2308
1103
  # popup.wait_for_load_state("domcontentloaded")
2309
1104
  # print(popup.title()) # popup is ready to use.
2310
1105
  # ```
2311
- #
2312
- # ```csharp
2313
- # var popupTask = page.WaitForPopupAsync();
2314
- # await page.ClickAsync("button"); // click triggers the popup/
2315
- # var popup = await popupTask;
2316
- # await popup.WaitForLoadStateAsync(LoadState.DOMContentLoaded);
2317
- # Console.WriteLine(await popup.TitleAsync()); // popup is ready to use.
2318
- # ```
2319
- #
1106
+ #
2320
1107
  # Shortcut for main frame's [`method: Frame.waitForLoadState`].
2321
1108
  def wait_for_load_state(state: nil, timeout: nil)
2322
1109
  wrap_impl(@impl.wait_for_load_state(state: unwrap_impl(state), timeout: unwrap_impl(timeout)))
@@ -2325,47 +1112,20 @@ module Playwright
2325
1112
  # Waits for the main frame navigation and returns the main resource response. In case of multiple redirects, the
2326
1113
  # navigation will resolve with the response of the last redirect. In case of navigation to a different anchor or
2327
1114
  # navigation due to History API usage, the navigation will resolve with `null`.
2328
- #
1115
+ #
2329
1116
  # This resolves when the page navigates to a new URL or reloads. It is useful for when you run code which will indirectly
2330
1117
  # cause the page to navigate. e.g. The click target has an `onclick` handler that triggers navigation from a `setTimeout`.
2331
1118
  # Consider this example:
2332
- #
2333
1119
  #
2334
- # ```js
2335
- # const [response] = await Promise.all([
2336
- # page.waitForNavigation(), // The promise resolves after navigation has finished
2337
- # page.click('a.delayed-navigation'), // Clicking the link will indirectly cause a navigation
2338
- # ]);
2339
- # ```
2340
- #
2341
- # ```java
2342
- # // The method returns after navigation has finished
2343
- # Response response = page.waitForNavigation(() -> {
2344
- # page.click("a.delayed-navigation"); // Clicking the link will indirectly cause a navigation
2345
- # });
2346
- # ```
2347
- #
2348
- # ```python async
2349
- # async with page.expect_navigation():
2350
- # await page.click("a.delayed-navigation") # clicking the link will indirectly cause a navigation
2351
- # # Resolves after navigation has finished
2352
- # ```
2353
- #
2354
1120
  # ```python sync
2355
1121
  # with page.expect_navigation():
2356
1122
  # page.click("a.delayed-navigation") # clicking the link will indirectly cause a navigation
2357
1123
  # # Resolves after navigation has finished
2358
1124
  # ```
2359
- #
2360
- # ```csharp
2361
- # await Task.WhenAll(page.WaitForNavigationAsync(),
2362
- # frame.ClickAsync("a.delayed-navigation")); // clicking the link will indirectly cause a navigation
2363
- # // The method continues after navigation has finished
2364
- # ```
2365
- #
1125
+ #
2366
1126
  # > NOTE: Usage of the [History API](https://developer.mozilla.org/en-US/docs/Web/API/History_API) to change the URL is
2367
1127
  # considered a navigation.
2368
- #
1128
+ #
2369
1129
  # Shortcut for main frame's [`method: Frame.waitForNavigation`].
2370
1130
  def expect_navigation(timeout: nil, url: nil, waitUntil: nil, &block)
2371
1131
  wrap_impl(@impl.expect_navigation(timeout: unwrap_impl(timeout), url: unwrap_impl(url), waitUntil: unwrap_impl(waitUntil), &wrap_block_call(block)))
@@ -2380,224 +1140,51 @@ module Playwright
2380
1140
 
2381
1141
  # Waits for the matching request and returns it. See [waiting for event](./events.md#waiting-for-event) for more details
2382
1142
  # about events.
2383
- #
2384
- #
2385
- # ```js
2386
- # // Note that Promise.all prevents a race condition
2387
- # // between clicking and waiting for the request.
2388
- # const [request] = await Promise.all([
2389
- # // Waits for the next request with the specified url
2390
- # page.waitForRequest('https://example.com/resource'),
2391
- # // Triggers the request
2392
- # page.click('button.triggers-request'),
2393
- # ]);
2394
- #
2395
- # // Alternative way with a predicate.
2396
- # const [request] = await Promise.all([
2397
- # // Waits for the next request matching some conditions
2398
- # page.waitForRequest(request => request.url() === 'https://example.com' && request.method() === 'GET'),
2399
- # // Triggers the request
2400
- # page.click('button.triggers-request'),
2401
- # ]);
2402
- # ```
2403
- #
2404
- # ```java
2405
- # // Waits for the next response with the specified url
2406
- # Request request = page.waitForRequest("https://example.com/resource", () -> {
2407
- # // Triggers the request
2408
- # page.click("button.triggers-request");
2409
- # });
2410
- #
2411
- # // Waits for the next request matching some conditions
2412
- # Request request = page.waitForRequest(request -> "https://example.com".equals(request.url()) && "GET".equals(request.method()), () -> {
2413
- # // Triggers the request
2414
- # page.click("button.triggers-request");
2415
- # });
2416
- # ```
2417
- #
2418
- # ```python async
2419
- # async with page.expect_request("http://example.com/resource") as first:
2420
- # await page.click('button')
2421
- # first_request = await first.value
2422
- #
2423
- # # or with a lambda
2424
- # async with page.expect_request(lambda request: request.url == "http://example.com" and request.method == "get") as second:
2425
- # await page.click('img')
2426
- # second_request = await second.value
2427
- # ```
2428
- #
1143
+ #
2429
1144
  # ```python sync
2430
1145
  # with page.expect_request("http://example.com/resource") as first:
2431
1146
  # page.click('button')
2432
1147
  # first_request = first.value
2433
- #
1148
+ #
2434
1149
  # # or with a lambda
2435
1150
  # with page.expect_request(lambda request: request.url == "http://example.com" and request.method == "get") as second:
2436
1151
  # page.click('img')
2437
1152
  # second_request = second.value
2438
1153
  # ```
2439
- #
2440
- # ```csharp
2441
- # // Waits for the next response with the specified url
2442
- # await Task.WhenAll(page.WaitForRequestAsync("https://example.com/resource"),
2443
- # page.ClickAsync("button.triggers-request"));
2444
- #
2445
- # // Waits for the next request matching some conditions
2446
- # await Task.WhenAll(page.WaitForRequestAsync(r => "https://example.com".Equals(r.Url) && "GET" == r.Method),
2447
- # page.ClickAsync("button.triggers-request"));
2448
- # ```
2449
- #
2450
- #
2451
- # ```js
2452
- # await page.waitForRequest(request => request.url().searchParams.get('foo') === 'bar' && request.url().searchParams.get('foo2') === 'bar2');
2453
- # ```
2454
1154
  def expect_request(urlOrPredicate, timeout: nil)
2455
1155
  wrap_impl(@impl.expect_request(unwrap_impl(urlOrPredicate), timeout: unwrap_impl(timeout)))
2456
1156
  end
2457
1157
 
2458
1158
  # Returns the matched response. See [waiting for event](./events.md#waiting-for-event) for more details about events.
2459
- #
2460
- #
2461
- # ```js
2462
- # // Note that Promise.all prevents a race condition
2463
- # // between clicking and waiting for the response.
2464
- # const [response] = await Promise.all([
2465
- # // Waits for the next response with the specified url
2466
- # page.waitForResponse('https://example.com/resource'),
2467
- # // Triggers the response
2468
- # page.click('button.triggers-response'),
2469
- # ]);
2470
- #
2471
- # // Alternative way with a predicate.
2472
- # const [response] = await Promise.all([
2473
- # // Waits for the next response matching some conditions
2474
- # page.waitForResponse(response => response.url() === 'https://example.com' && response.status() === 200),
2475
- # // Triggers the response
2476
- # page.click('button.triggers-response'),
2477
- # ]);
2478
- # ```
2479
- #
2480
- # ```java
2481
- # // Waits for the next response with the specified url
2482
- # Response response = page.waitForResponse("https://example.com/resource", () -> {
2483
- # // Triggers the response
2484
- # page.click("button.triggers-response");
2485
- # });
2486
- #
2487
- # // Waits for the next response matching some conditions
2488
- # Response response = page.waitForResponse(response -> "https://example.com".equals(response.url()) && response.status() == 200, () -> {
2489
- # // Triggers the response
2490
- # page.click("button.triggers-response");
2491
- # });
2492
- # ```
2493
- #
2494
- # ```python async
2495
- # async with page.expect_response("https://example.com/resource") as response_info:
2496
- # await page.click("input")
2497
- # response = response_info.value
2498
- # return response.ok
2499
- #
2500
- # # or with a lambda
2501
- # async with page.expect_response(lambda response: response.url == "https://example.com" and response.status === 200) as response_info:
2502
- # await page.click("input")
2503
- # response = response_info.value
2504
- # return response.ok
2505
- # ```
2506
- #
1159
+ #
2507
1160
  # ```python sync
2508
1161
  # with page.expect_response("https://example.com/resource") as response_info:
2509
1162
  # page.click("input")
2510
1163
  # response = response_info.value
2511
1164
  # return response.ok
2512
- #
1165
+ #
2513
1166
  # # or with a lambda
2514
1167
  # with page.expect_response(lambda response: response.url == "https://example.com" and response.status === 200) as response_info:
2515
1168
  # page.click("input")
2516
1169
  # response = response_info.value
2517
1170
  # return response.ok
2518
1171
  # ```
2519
- #
2520
- # ```csharp
2521
- # // Waits for the next response with the specified url
2522
- # await Task.WhenAll(page.WaitForResponseAsync("https://example.com/resource"),
2523
- # page.ClickAsync("button.triggers-response"));
2524
- #
2525
- # // Waits for the next response matching some conditions
2526
- # await Task.WhenAll(page.WaitForResponseAsync(r => "https://example.com".Equals(r.Url) && r.Status == 200),
2527
- # page.ClickAsync("button.triggers-response"));
2528
- # ```
2529
1172
  def expect_response(urlOrPredicate, timeout: nil)
2530
1173
  wrap_impl(@impl.expect_response(unwrap_impl(urlOrPredicate), timeout: unwrap_impl(timeout)))
2531
1174
  end
2532
1175
 
2533
1176
  # Returns when element specified by selector satisfies `state` option. Returns `null` if waiting for `hidden` or
2534
1177
  # `detached`.
2535
- #
1178
+ #
2536
1179
  # Wait for the `selector` to satisfy `state` option (either appear/disappear from dom, or become visible/hidden). If at
2537
1180
  # the moment of calling the method `selector` already satisfies the condition, the method will return immediately. If the
2538
1181
  # selector doesn't satisfy the condition for the `timeout` milliseconds, the function will throw.
2539
- #
1182
+ #
2540
1183
  # This method works across navigations:
2541
- #
2542
- #
2543
- # ```js
2544
- # const { chromium } = require('playwright'); // Or 'firefox' or 'webkit'.
2545
- #
2546
- # (async () => {
2547
- # const browser = await chromium.launch();
2548
- # const page = await browser.newPage();
2549
- # for (let currentURL of ['https://google.com', 'https://bbc.com']) {
2550
- # await page.goto(currentURL);
2551
- # const element = await page.waitForSelector('img');
2552
- # console.log('Loaded image: ' + await element.getAttribute('src'));
2553
- # }
2554
- # await browser.close();
2555
- # })();
2556
- # ```
2557
- #
2558
- # ```java
2559
- # import com.microsoft.playwright.*;
2560
- #
2561
- # public class Example {
2562
- # public static void main(String[] args) {
2563
- # try (Playwright playwright = Playwright.create()) {
2564
- # BrowserType chromium = playwright.chromium();
2565
- # Browser browser = chromium.launch();
2566
- # Page page = browser.newPage();
2567
- # for (String currentURL : Arrays.asList("https://google.com", "https://bbc.com")) {
2568
- # page.navigate(currentURL);
2569
- # ElementHandle element = page.waitForSelector("img");
2570
- # System.out.println("Loaded image: " + element.getAttribute("src"));
2571
- # }
2572
- # browser.close();
2573
- # }
2574
- # }
2575
- # }
2576
- # ```
2577
- #
2578
- # ```python async
2579
- # import asyncio
2580
- # from playwright.async_api import async_playwright
2581
- #
2582
- # async def run(playwright):
2583
- # chromium = playwright.chromium
2584
- # browser = await chromium.launch()
2585
- # page = await browser.new_page()
2586
- # for current_url in ["https://google.com", "https://bbc.com"]:
2587
- # await page.goto(current_url, wait_until="domcontentloaded")
2588
- # element = await page.wait_for_selector("img")
2589
- # print("Loaded image: " + str(await element.get_attribute("src")))
2590
- # await browser.close()
2591
- #
2592
- # async def main():
2593
- # async with async_playwright() as playwright:
2594
- # await run(playwright)
2595
- # asyncio.run(main())
2596
- # ```
2597
- #
1184
+ #
2598
1185
  # ```python sync
2599
1186
  # from playwright.sync_api import sync_playwright
2600
- #
1187
+ #
2601
1188
  # def run(playwright):
2602
1189
  # chromium = playwright.chromium
2603
1190
  # browser = chromium.launch()
@@ -2607,103 +1194,36 @@ module Playwright
2607
1194
  # element = page.wait_for_selector("img")
2608
1195
  # print("Loaded image: " + str(element.get_attribute("src")))
2609
1196
  # browser.close()
2610
- #
1197
+ #
2611
1198
  # with sync_playwright() as playwright:
2612
1199
  # run(playwright)
2613
1200
  # ```
2614
- #
2615
- # ```csharp
2616
- # using Microsoft.Playwright;
2617
- # using System;
2618
- # using System.Threading.Tasks;
2619
- #
2620
- # class FrameExamples
2621
- # {
2622
- # public static async Task Images()
2623
- # {
2624
- # using var playwright = await Playwright.CreateAsync();
2625
- # await using var browser = await playwright.Chromium.LaunchAsync();
2626
- # var page = await browser.NewPageAsync();
2627
- #
2628
- # foreach (var currentUrl in new[] { "https://www.google.com", "https://bbc.com" })
2629
- # {
2630
- # await page.GotoAsync(currentUrl);
2631
- # var element = await page.WaitForSelectorAsync("img");
2632
- # Console.WriteLine($"Loaded image: {await element.GetAttributeAsync("src")}");
2633
- # }
2634
- #
2635
- # await browser.CloseAsync();
2636
- # }
2637
- # }
2638
- # ```
2639
1201
  def wait_for_selector(selector, state: nil, timeout: nil)
2640
1202
  wrap_impl(@impl.wait_for_selector(unwrap_impl(selector), state: unwrap_impl(state), timeout: unwrap_impl(timeout)))
2641
1203
  end
2642
1204
 
2643
1205
  # Waits for the given `timeout` in milliseconds.
2644
- #
1206
+ #
2645
1207
  # Note that `page.waitForTimeout()` should only be used for debugging. Tests using the timer in production are going to be
2646
1208
  # flaky. Use signals such as network events, selectors becoming visible and others instead.
2647
- #
2648
1209
  #
2649
- # ```js
2650
- # // wait for 1 second
2651
- # await page.waitForTimeout(1000);
2652
- # ```
2653
- #
2654
- # ```java
2655
- # // wait for 1 second
2656
- # page.waitForTimeout(1000);
2657
- # ```
2658
- #
2659
- # ```python async
2660
- # # wait for 1 second
2661
- # await page.wait_for_timeout(1000)
2662
- # ```
2663
- #
2664
1210
  # ```python sync
2665
1211
  # # wait for 1 second
2666
1212
  # page.wait_for_timeout(1000)
2667
1213
  # ```
2668
- #
2669
- # ```csharp
2670
- # // Wait for 1 second
2671
- # await page.WaitForTimeoutAsync(1000);
2672
- # ```
2673
- #
1214
+ #
2674
1215
  # Shortcut for main frame's [`method: Frame.waitForTimeout`].
2675
1216
  def wait_for_timeout(timeout)
2676
1217
  raise NotImplementedError.new('wait_for_timeout is not implemented yet.')
2677
1218
  end
2678
1219
 
2679
1220
  # Waits for the main frame to navigate to the given URL.
2680
- #
2681
1221
  #
2682
- # ```js
2683
- # await page.click('a.delayed-navigation'); // Clicking the link will indirectly cause a navigation
2684
- # await page.waitForURL('**/target.html');
2685
- # ```
2686
- #
2687
- # ```java
2688
- # page.click("a.delayed-navigation"); // Clicking the link will indirectly cause a navigation
2689
- # page.waitForURL("**/target.html");
2690
- # ```
2691
- #
2692
- # ```python async
2693
- # await page.click("a.delayed-navigation") # clicking the link will indirectly cause a navigation
2694
- # await page.wait_for_url("**/target.html")
2695
- # ```
2696
- #
2697
1222
  # ```python sync
2698
1223
  # page.click("a.delayed-navigation") # clicking the link will indirectly cause a navigation
2699
1224
  # page.wait_for_url("**/target.html")
2700
1225
  # ```
2701
- #
2702
- # ```csharp
2703
- # await page.ClickAsync("a.delayed-navigation"); // clicking the link will indirectly cause a navigation
2704
- # await page.WaitForURLAsync("**/target.html");
2705
- # ```
2706
- #
1226
+ #
2707
1227
  # Shortcut for main frame's [`method: Frame.waitForURL`].
2708
1228
  def wait_for_url(url, timeout: nil, waitUntil: nil)
2709
1229
  wrap_impl(@impl.wait_for_url(unwrap_impl(url), timeout: unwrap_impl(timeout), waitUntil: unwrap_impl(waitUntil)))
@@ -2718,16 +1238,16 @@ module Playwright
2718
1238
 
2719
1239
  # This method returns all of the dedicated [WebWorkers](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API)
2720
1240
  # associated with the page.
2721
- #
1241
+ #
2722
1242
  # > NOTE: This does not contain ServiceWorkers
2723
1243
  def workers
2724
1244
  raise NotImplementedError.new('workers is not implemented yet.')
2725
1245
  end
2726
1246
 
2727
1247
  # > NOTE: In most cases, you should use [`method: Page.waitForEvent`].
2728
- #
1248
+ #
2729
1249
  # Waits for given `event` to fire. If predicate is provided, it passes event's value into the `predicate` function and
2730
- # waits for `predicate(event)` to return a truthy value. Will throw an error if the socket is closed before the `event` is
1250
+ # waits for `predicate(event)` to return a truthy value. Will throw an error if the page is closed before the `event` is
2731
1251
  # fired.
2732
1252
  def wait_for_event(event, predicate: nil, timeout: nil)
2733
1253
  raise NotImplementedError.new('wait_for_event is not implemented yet.')
@@ -2749,13 +1269,13 @@ module Playwright
2749
1269
  end
2750
1270
 
2751
1271
  # @nodoc
2752
- def start_css_coverage(resetOnNavigation: nil, reportAnonymousScripts: nil)
2753
- wrap_impl(@impl.start_css_coverage(resetOnNavigation: unwrap_impl(resetOnNavigation), reportAnonymousScripts: unwrap_impl(reportAnonymousScripts)))
1272
+ def stop_css_coverage
1273
+ wrap_impl(@impl.stop_css_coverage)
2754
1274
  end
2755
1275
 
2756
1276
  # @nodoc
2757
- def stop_css_coverage
2758
- wrap_impl(@impl.stop_css_coverage)
1277
+ def start_css_coverage(resetOnNavigation: nil, reportAnonymousScripts: nil)
1278
+ wrap_impl(@impl.start_css_coverage(resetOnNavigation: unwrap_impl(resetOnNavigation), reportAnonymousScripts: unwrap_impl(reportAnonymousScripts)))
2759
1279
  end
2760
1280
 
2761
1281
  # @nodoc
@@ -2765,20 +1285,20 @@ module Playwright
2765
1285
 
2766
1286
  # -- inherited from EventEmitter --
2767
1287
  # @nodoc
2768
- def off(event, callback)
2769
- event_emitter_proxy.off(event, callback)
1288
+ def on(event, callback)
1289
+ event_emitter_proxy.on(event, callback)
2770
1290
  end
2771
1291
 
2772
1292
  # -- inherited from EventEmitter --
2773
1293
  # @nodoc
2774
- def once(event, callback)
2775
- event_emitter_proxy.once(event, callback)
1294
+ def off(event, callback)
1295
+ event_emitter_proxy.off(event, callback)
2776
1296
  end
2777
1297
 
2778
1298
  # -- inherited from EventEmitter --
2779
1299
  # @nodoc
2780
- def on(event, callback)
2781
- event_emitter_proxy.on(event, callback)
1300
+ def once(event, callback)
1301
+ event_emitter_proxy.once(event, callback)
2782
1302
  end
2783
1303
 
2784
1304
  private def event_emitter_proxy