playwright-ruby-client 0.3.0 → 0.5.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +17 -5
  3. data/docs/api_coverage.md +14 -25
  4. data/lib/playwright.rb +47 -9
  5. data/lib/playwright/channel.rb +19 -9
  6. data/lib/playwright/channel_owners/artifact.rb +30 -0
  7. data/lib/playwright/channel_owners/browser.rb +21 -0
  8. data/lib/playwright/channel_owners/browser_context.rb +5 -0
  9. data/lib/playwright/channel_owners/browser_type.rb +28 -0
  10. data/lib/playwright/channel_owners/element_handle.rb +7 -7
  11. data/lib/playwright/channel_owners/frame.rb +26 -5
  12. data/lib/playwright/channel_owners/js_handle.rb +2 -2
  13. data/lib/playwright/channel_owners/page.rb +78 -15
  14. data/lib/playwright/channel_owners/playwright.rb +22 -29
  15. data/lib/playwright/channel_owners/stream.rb +15 -0
  16. data/lib/playwright/connection.rb +11 -32
  17. data/lib/playwright/download.rb +27 -0
  18. data/lib/playwright/errors.rb +6 -0
  19. data/lib/playwright/events.rb +2 -5
  20. data/lib/playwright/keyboard_impl.rb +1 -1
  21. data/lib/playwright/mouse_impl.rb +41 -0
  22. data/lib/playwright/playwright_api.rb +5 -3
  23. data/lib/playwright/route_handler_entry.rb +1 -9
  24. data/lib/playwright/select_option_values.rb +31 -22
  25. data/lib/playwright/transport.rb +29 -7
  26. data/lib/playwright/url_matcher.rb +1 -1
  27. data/lib/playwright/utils.rb +8 -0
  28. data/lib/playwright/version.rb +1 -1
  29. data/lib/playwright/video.rb +51 -0
  30. data/lib/playwright/wait_helper.rb +2 -2
  31. data/lib/playwright_api/accessibility.rb +39 -1
  32. data/lib/playwright_api/android.rb +10 -10
  33. data/lib/playwright_api/android_device.rb +10 -9
  34. data/lib/playwright_api/browser.rb +83 -8
  35. data/lib/playwright_api/browser_context.rb +157 -9
  36. data/lib/playwright_api/browser_type.rb +35 -4
  37. data/lib/playwright_api/console_message.rb +6 -6
  38. data/lib/playwright_api/dialog.rb +28 -8
  39. data/lib/playwright_api/element_handle.rb +111 -37
  40. data/lib/playwright_api/file_chooser.rb +5 -0
  41. data/lib/playwright_api/frame.rb +228 -37
  42. data/lib/playwright_api/js_handle.rb +26 -3
  43. data/lib/playwright_api/keyboard.rb +48 -1
  44. data/lib/playwright_api/mouse.rb +26 -5
  45. data/lib/playwright_api/page.rb +454 -46
  46. data/lib/playwright_api/playwright.rb +26 -9
  47. data/lib/playwright_api/request.rb +34 -6
  48. data/lib/playwright_api/response.rb +6 -6
  49. data/lib/playwright_api/route.rb +30 -6
  50. data/lib/playwright_api/selectors.rb +32 -6
  51. data/lib/playwright_api/touchscreen.rb +1 -1
  52. data/lib/playwright_api/worker.rb +25 -1
  53. data/playwright.gemspec +4 -2
  54. metadata +37 -14
  55. data/lib/playwright/channel_owners/chromium_browser.rb +0 -8
  56. data/lib/playwright/channel_owners/chromium_browser_context.rb +0 -8
  57. data/lib/playwright/channel_owners/download.rb +0 -27
  58. data/lib/playwright/channel_owners/firefox_browser.rb +0 -8
  59. data/lib/playwright/channel_owners/webkit_browser.rb +0 -8
  60. data/lib/playwright_api/binding_call.rb +0 -32
  61. data/lib/playwright_api/chromium_browser_context.rb +0 -59
  62. data/lib/playwright_api/download.rb +0 -95
  63. data/lib/playwright_api/video.rb +0 -24
@@ -59,11 +59,12 @@ module Playwright
59
59
  record_har_path: nil,
60
60
  record_video_dir: nil,
61
61
  record_video_size: nil,
62
+ screen: nil,
62
63
  timezoneId: nil,
63
64
  userAgent: nil,
64
65
  viewport: nil,
65
66
  &block)
66
- wrap_impl(@impl.launch_browser(acceptDownloads: unwrap_impl(acceptDownloads), bypassCSP: unwrap_impl(bypassCSP), colorScheme: unwrap_impl(colorScheme), command: unwrap_impl(command), deviceScaleFactor: unwrap_impl(deviceScaleFactor), extraHTTPHeaders: unwrap_impl(extraHTTPHeaders), geolocation: unwrap_impl(geolocation), hasTouch: unwrap_impl(hasTouch), httpCredentials: unwrap_impl(httpCredentials), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), isMobile: unwrap_impl(isMobile), javaScriptEnabled: unwrap_impl(javaScriptEnabled), locale: unwrap_impl(locale), noViewport: unwrap_impl(noViewport), offline: unwrap_impl(offline), permissions: unwrap_impl(permissions), record_har_omit_content: unwrap_impl(record_har_omit_content), record_har_path: unwrap_impl(record_har_path), record_video_dir: unwrap_impl(record_video_dir), record_video_size: unwrap_impl(record_video_size), timezoneId: unwrap_impl(timezoneId), userAgent: unwrap_impl(userAgent), viewport: unwrap_impl(viewport), &wrap_block_call(block)))
67
+ wrap_impl(@impl.launch_browser(acceptDownloads: unwrap_impl(acceptDownloads), bypassCSP: unwrap_impl(bypassCSP), colorScheme: unwrap_impl(colorScheme), command: unwrap_impl(command), deviceScaleFactor: unwrap_impl(deviceScaleFactor), extraHTTPHeaders: unwrap_impl(extraHTTPHeaders), geolocation: unwrap_impl(geolocation), hasTouch: unwrap_impl(hasTouch), httpCredentials: unwrap_impl(httpCredentials), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), isMobile: unwrap_impl(isMobile), javaScriptEnabled: unwrap_impl(javaScriptEnabled), locale: unwrap_impl(locale), noViewport: unwrap_impl(noViewport), offline: unwrap_impl(offline), permissions: unwrap_impl(permissions), record_har_omit_content: unwrap_impl(record_har_omit_content), record_har_path: unwrap_impl(record_har_path), record_video_dir: unwrap_impl(record_video_dir), record_video_size: unwrap_impl(record_video_size), screen: unwrap_impl(screen), timezoneId: unwrap_impl(timezoneId), userAgent: unwrap_impl(userAgent), viewport: unwrap_impl(viewport), &wrap_block_call(block)))
67
68
  end
68
69
 
69
70
  # Performs a long tap on the widget defined by `selector`.
@@ -159,20 +160,14 @@ module Playwright
159
160
  raise NotImplementedError.new('web_views is not implemented yet.')
160
161
  end
161
162
 
162
- # @nodoc
163
- def tree
164
- wrap_impl(@impl.tree)
165
- end
166
-
167
163
  # @nodoc
168
164
  def tap_on(selector, duration: nil, timeout: nil)
169
165
  wrap_impl(@impl.tap_on(unwrap_impl(selector), duration: unwrap_impl(duration), timeout: unwrap_impl(timeout)))
170
166
  end
171
167
 
172
- # -- inherited from EventEmitter --
173
168
  # @nodoc
174
- def off(event, callback)
175
- event_emitter_proxy.off(event, callback)
169
+ def tree
170
+ wrap_impl(@impl.tree)
176
171
  end
177
172
 
178
173
  # -- inherited from EventEmitter --
@@ -187,6 +182,12 @@ module Playwright
187
182
  event_emitter_proxy.on(event, callback)
188
183
  end
189
184
 
185
+ # -- inherited from EventEmitter --
186
+ # @nodoc
187
+ def off(event, callback)
188
+ event_emitter_proxy.off(event, callback)
189
+ end
190
+
190
191
  private def event_emitter_proxy
191
192
  @event_emitter_proxy ||= EventEmitterProxy.new(self, @impl)
192
193
  end
@@ -15,6 +15,22 @@ module Playwright
15
15
  # })();
16
16
  # ```
17
17
  #
18
+ # ```java
19
+ # import com.microsoft.playwright.*;
20
+ #
21
+ # public class Example {
22
+ # public static void main(String[] args) {
23
+ # try (Playwright playwright = Playwright.create()) {
24
+ # BrowserType firefox = playwright.firefox()
25
+ # Browser browser = firefox.launch();
26
+ # Page page = browser.newPage();
27
+ # page.navigate('https://example.com');
28
+ # browser.close();
29
+ # }
30
+ # }
31
+ # }
32
+ # ```
33
+ #
18
34
  # ```python async
19
35
  # import asyncio
20
36
  # from playwright.async_api import async_playwright
@@ -69,6 +85,13 @@ module Playwright
69
85
  # console.log(browser.contexts().length); // prints `1`
70
86
  # ```
71
87
  #
88
+ # ```java
89
+ # Browser browser = pw.webkit().launch();
90
+ # System.out.println(browser.contexts().size()); // prints "0"
91
+ # BrowserContext context = browser.newContext();
92
+ # System.out.println(browser.contexts().size()); // prints "1"
93
+ # ```
94
+ #
72
95
  # ```python async
73
96
  # browser = await pw.webkit.launch()
74
97
  # print(len(browser.contexts())) # prints `0`
@@ -91,6 +114,13 @@ module Playwright
91
114
  wrap_impl(@impl.connected?)
92
115
  end
93
116
 
117
+ # > NOTE: CDP Sessions are only supported on Chromium-based browsers.
118
+ #
119
+ # Returns the newly created browser session.
120
+ def new_browser_cdp_session
121
+ raise NotImplementedError.new('new_browser_cdp_session is not implemented yet.')
122
+ end
123
+
94
124
  # Creates a new browser context. It won't share cookies/cache with other browser contexts.
95
125
  #
96
126
  #
@@ -105,6 +135,15 @@ module Playwright
105
135
  # })();
106
136
  # ```
107
137
  #
138
+ # ```java
139
+ # Browser browser = playwright.firefox().launch(); // Or 'chromium' or 'webkit'.
140
+ # // Create a new incognito browser context.
141
+ # BrowserContext context = browser.newContext();
142
+ # // Create a new page in a pristine context.
143
+ # Page page = context.newPage();
144
+ # page.navigate('https://example.com');
145
+ # ```
146
+ #
108
147
  # ```python async
109
148
  # browser = await playwright.firefox.launch() # or "chromium" or "webkit".
110
149
  # # create a new incognito browser context.
@@ -143,12 +182,13 @@ module Playwright
143
182
  record_har_path: nil,
144
183
  record_video_dir: nil,
145
184
  record_video_size: nil,
185
+ screen: nil,
146
186
  storageState: nil,
147
187
  timezoneId: nil,
148
188
  userAgent: nil,
149
189
  viewport: nil,
150
190
  &block)
151
- wrap_impl(@impl.new_context(acceptDownloads: unwrap_impl(acceptDownloads), bypassCSP: unwrap_impl(bypassCSP), colorScheme: unwrap_impl(colorScheme), deviceScaleFactor: unwrap_impl(deviceScaleFactor), extraHTTPHeaders: unwrap_impl(extraHTTPHeaders), geolocation: unwrap_impl(geolocation), hasTouch: unwrap_impl(hasTouch), httpCredentials: unwrap_impl(httpCredentials), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), isMobile: unwrap_impl(isMobile), javaScriptEnabled: unwrap_impl(javaScriptEnabled), locale: unwrap_impl(locale), noViewport: unwrap_impl(noViewport), offline: unwrap_impl(offline), permissions: unwrap_impl(permissions), proxy: unwrap_impl(proxy), record_har_omit_content: unwrap_impl(record_har_omit_content), record_har_path: unwrap_impl(record_har_path), record_video_dir: unwrap_impl(record_video_dir), record_video_size: unwrap_impl(record_video_size), storageState: unwrap_impl(storageState), timezoneId: unwrap_impl(timezoneId), userAgent: unwrap_impl(userAgent), viewport: unwrap_impl(viewport), &wrap_block_call(block)))
191
+ wrap_impl(@impl.new_context(acceptDownloads: unwrap_impl(acceptDownloads), bypassCSP: unwrap_impl(bypassCSP), colorScheme: unwrap_impl(colorScheme), deviceScaleFactor: unwrap_impl(deviceScaleFactor), extraHTTPHeaders: unwrap_impl(extraHTTPHeaders), geolocation: unwrap_impl(geolocation), hasTouch: unwrap_impl(hasTouch), httpCredentials: unwrap_impl(httpCredentials), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), isMobile: unwrap_impl(isMobile), javaScriptEnabled: unwrap_impl(javaScriptEnabled), locale: unwrap_impl(locale), noViewport: unwrap_impl(noViewport), offline: unwrap_impl(offline), permissions: unwrap_impl(permissions), proxy: unwrap_impl(proxy), record_har_omit_content: unwrap_impl(record_har_omit_content), record_har_path: unwrap_impl(record_har_path), record_video_dir: unwrap_impl(record_video_dir), record_video_size: unwrap_impl(record_video_size), screen: unwrap_impl(screen), storageState: unwrap_impl(storageState), timezoneId: unwrap_impl(timezoneId), userAgent: unwrap_impl(userAgent), viewport: unwrap_impl(viewport), &wrap_block_call(block)))
152
192
  end
153
193
 
154
194
  # Creates a new page in a new browser context. Closing this page will close the context as well.
@@ -177,11 +217,46 @@ module Playwright
177
217
  record_har_path: nil,
178
218
  record_video_dir: nil,
179
219
  record_video_size: nil,
220
+ screen: nil,
180
221
  storageState: nil,
181
222
  timezoneId: nil,
182
223
  userAgent: nil,
183
224
  viewport: nil)
184
- wrap_impl(@impl.new_page(acceptDownloads: unwrap_impl(acceptDownloads), bypassCSP: unwrap_impl(bypassCSP), colorScheme: unwrap_impl(colorScheme), deviceScaleFactor: unwrap_impl(deviceScaleFactor), extraHTTPHeaders: unwrap_impl(extraHTTPHeaders), geolocation: unwrap_impl(geolocation), hasTouch: unwrap_impl(hasTouch), httpCredentials: unwrap_impl(httpCredentials), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), isMobile: unwrap_impl(isMobile), javaScriptEnabled: unwrap_impl(javaScriptEnabled), locale: unwrap_impl(locale), noViewport: unwrap_impl(noViewport), offline: unwrap_impl(offline), permissions: unwrap_impl(permissions), proxy: unwrap_impl(proxy), record_har_omit_content: unwrap_impl(record_har_omit_content), record_har_path: unwrap_impl(record_har_path), record_video_dir: unwrap_impl(record_video_dir), record_video_size: unwrap_impl(record_video_size), storageState: unwrap_impl(storageState), timezoneId: unwrap_impl(timezoneId), userAgent: unwrap_impl(userAgent), viewport: unwrap_impl(viewport)))
225
+ wrap_impl(@impl.new_page(acceptDownloads: unwrap_impl(acceptDownloads), bypassCSP: unwrap_impl(bypassCSP), colorScheme: unwrap_impl(colorScheme), deviceScaleFactor: unwrap_impl(deviceScaleFactor), extraHTTPHeaders: unwrap_impl(extraHTTPHeaders), geolocation: unwrap_impl(geolocation), hasTouch: unwrap_impl(hasTouch), httpCredentials: unwrap_impl(httpCredentials), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), isMobile: unwrap_impl(isMobile), javaScriptEnabled: unwrap_impl(javaScriptEnabled), locale: unwrap_impl(locale), noViewport: unwrap_impl(noViewport), offline: unwrap_impl(offline), permissions: unwrap_impl(permissions), proxy: unwrap_impl(proxy), record_har_omit_content: unwrap_impl(record_har_omit_content), record_har_path: unwrap_impl(record_har_path), record_video_dir: unwrap_impl(record_video_dir), record_video_size: unwrap_impl(record_video_size), screen: unwrap_impl(screen), storageState: unwrap_impl(storageState), timezoneId: unwrap_impl(timezoneId), userAgent: unwrap_impl(userAgent), viewport: unwrap_impl(viewport)))
226
+ end
227
+
228
+ # > NOTE: Tracing is only supported on Chromium-based browsers.
229
+ #
230
+ # You can use [`method: Browser.startTracing`] and [`method: Browser.stopTracing`] to create a trace file that can be
231
+ # opened in Chrome DevTools performance panel.
232
+ #
233
+ #
234
+ # ```js
235
+ # await browser.startTracing(page, {path: 'trace.json'});
236
+ # await page.goto('https://www.google.com');
237
+ # await browser.stopTracing();
238
+ # ```
239
+ #
240
+ # ```python async
241
+ # await browser.start_tracing(page, path="trace.json")
242
+ # await page.goto("https://www.google.com")
243
+ # await browser.stop_tracing()
244
+ # ```
245
+ #
246
+ # ```python sync
247
+ # browser.start_tracing(page, path="trace.json")
248
+ # page.goto("https://www.google.com")
249
+ # browser.stop_tracing()
250
+ # ```
251
+ def start_tracing(page: nil, categories: nil, path: nil, screenshots: nil)
252
+ wrap_impl(@impl.start_tracing(page: unwrap_impl(page), categories: unwrap_impl(categories), path: unwrap_impl(path), screenshots: unwrap_impl(screenshots)))
253
+ end
254
+
255
+ # > NOTE: Tracing is only supported on Chromium-based browsers.
256
+ #
257
+ # Returns the buffer with trace data.
258
+ def stop_tracing
259
+ wrap_impl(@impl.stop_tracing)
185
260
  end
186
261
 
187
262
  # Returns the browser version.
@@ -189,12 +264,6 @@ module Playwright
189
264
  wrap_impl(@impl.version)
190
265
  end
191
266
 
192
- # -- inherited from EventEmitter --
193
- # @nodoc
194
- def off(event, callback)
195
- event_emitter_proxy.off(event, callback)
196
- end
197
-
198
267
  # -- inherited from EventEmitter --
199
268
  # @nodoc
200
269
  def once(event, callback)
@@ -207,6 +276,12 @@ module Playwright
207
276
  event_emitter_proxy.on(event, callback)
208
277
  end
209
278
 
279
+ # -- inherited from EventEmitter --
280
+ # @nodoc
281
+ def off(event, callback)
282
+ event_emitter_proxy.off(event, callback)
283
+ end
284
+
210
285
  private def event_emitter_proxy
211
286
  @event_emitter_proxy ||= EventEmitterProxy.new(self, @impl)
212
287
  end
@@ -20,6 +20,16 @@ module Playwright
20
20
  # await context.close();
21
21
  # ```
22
22
  #
23
+ # ```java
24
+ # // Create a new incognito browser context
25
+ # BrowserContext context = browser.newContext();
26
+ # // Create a new page inside context.
27
+ # Page page = context.newPage();
28
+ # page.navigate("https://example.com");
29
+ # // Dispose context once it"s no longer needed.
30
+ # context.close();
31
+ # ```
32
+ #
23
33
  # ```python async
24
34
  # # create a new incognito browser context
25
35
  # context = await browser.new_context()
@@ -49,6 +59,10 @@ module Playwright
49
59
  # await browserContext.addCookies([cookieObject1, cookieObject2]);
50
60
  # ```
51
61
  #
62
+ # ```java
63
+ # browserContext.addCookies(Arrays.asList(cookieObject1, cookieObject2));
64
+ # ```
65
+ #
52
66
  # ```python async
53
67
  # await browser_context.add_cookies([cookie_object1, cookie_object2])
54
68
  # ```
@@ -84,6 +98,11 @@ module Playwright
84
98
  # });
85
99
  # ```
86
100
  #
101
+ # ```java
102
+ # // In your playwright script, assuming the preload.js file is in same directory.
103
+ # browserContext.addInitScript(Paths.get("preload.js"));
104
+ # ```
105
+ #
87
106
  # ```python async
88
107
  # # in your playwright script, assuming the preload.js file is in same directory.
89
108
  # await browser_context.add_init_script(path="preload.js")
@@ -100,6 +119,13 @@ module Playwright
100
119
  wrap_impl(@impl.add_init_script(path: unwrap_impl(path), script: unwrap_impl(script)))
101
120
  end
102
121
 
122
+ # > NOTE: Background pages are only supported on Chromium-based browsers.
123
+ #
124
+ # All existing background pages in the context.
125
+ def background_pages
126
+ raise NotImplementedError.new('background_pages is not implemented yet.')
127
+ end
128
+
103
129
  # Returns the browser instance of the context. If it was launched as a persistent context null gets returned.
104
130
  def browser
105
131
  wrap_impl(@impl.browser)
@@ -120,6 +146,13 @@ module Playwright
120
146
  # context.clearPermissions();
121
147
  # ```
122
148
  #
149
+ # ```java
150
+ # BrowserContext context = browser.newContext();
151
+ # context.grantPermissions(Arrays.asList("clipboard-read"));
152
+ # // do stuff ..
153
+ # context.clearPermissions();
154
+ # ```
155
+ #
123
156
  # ```python async
124
157
  # context = await browser.new_context()
125
158
  # await context.grant_permissions(["clipboard-read"])
@@ -183,6 +216,30 @@ module Playwright
183
216
  # })();
184
217
  # ```
185
218
  #
219
+ # ```java
220
+ # import com.microsoft.playwright.*;
221
+ #
222
+ # public class Example {
223
+ # public static void main(String[] args) {
224
+ # try (Playwright playwright = Playwright.create()) {
225
+ # BrowserType webkit = playwright.webkit()
226
+ # Browser browser = webkit.launch(new BrowserType.LaunchOptions().setHeadless(false));
227
+ # BrowserContext context = browser.newContext();
228
+ # context.exposeBinding("pageURL", (source, args) -> source.page().url());
229
+ # Page page = context.newPage();
230
+ # page.setContent("<script>\n" +
231
+ # " async function onClick() {\n" +
232
+ # " document.querySelector('div').textContent = await window.pageURL();\n" +
233
+ # " }\n" +
234
+ # "</script>\n" +
235
+ # "<button onclick=\"onClick()\">Click me</button>\n" +
236
+ # "<div></div>");
237
+ # page.click("button");
238
+ # }
239
+ # }
240
+ # }
241
+ # ```
242
+ #
186
243
  # ```python async
187
244
  # import asyncio
188
245
  # from playwright.async_api import async_playwright
@@ -250,6 +307,20 @@ module Playwright
250
307
  # `);
251
308
  # ```
252
309
  #
310
+ # ```java
311
+ # context.exposeBinding("clicked", (source, args) -> {
312
+ # ElementHandle element = (ElementHandle) args[0];
313
+ # System.out.println(element.textContent());
314
+ # return null;
315
+ # }, new BrowserContext.ExposeBindingOptions().setHandle(true));
316
+ # page.setContent("" +
317
+ # "<script>\n" +
318
+ # " document.addEventListener('click', event => window.clicked(event.target));\n" +
319
+ # "</script>\n" +
320
+ # "<div>Click me</div>\n" +
321
+ # "<div>Or click me</div>\n");
322
+ # ```
323
+ #
253
324
  # ```python async
254
325
  # async def print(source, element):
255
326
  # print(await element.text_content())
@@ -313,6 +384,44 @@ module Playwright
313
384
  # })();
314
385
  # ```
315
386
  #
387
+ # ```java
388
+ # import com.microsoft.playwright.*;
389
+ #
390
+ # import java.nio.charset.StandardCharsets;
391
+ # import java.security.MessageDigest;
392
+ # import java.security.NoSuchAlgorithmException;
393
+ # import java.util.Base64;
394
+ #
395
+ # public class Example {
396
+ # public static void main(String[] args) {
397
+ # try (Playwright playwright = Playwright.create()) {
398
+ # BrowserType webkit = playwright.webkit()
399
+ # Browser browser = webkit.launch(new BrowserType.LaunchOptions().setHeadless(false));
400
+ # context.exposeFunction("sha1", args -> {
401
+ # String text = (String) args[0];
402
+ # MessageDigest crypto;
403
+ # try {
404
+ # crypto = MessageDigest.getInstance("SHA-1");
405
+ # } catch (NoSuchAlgorithmException e) {
406
+ # return null;
407
+ # }
408
+ # byte[] token = crypto.digest(text.getBytes(StandardCharsets.UTF_8));
409
+ # return Base64.getEncoder().encodeToString(token);
410
+ # });
411
+ # Page page = context.newPage();
412
+ # page.setContent("<script>\n" +
413
+ # " async function onClick() {\n" +
414
+ # " document.querySelector('div').textContent = await window.sha1('PLAYWRIGHT');\n" +
415
+ # " }\n" +
416
+ # "</script>\n" +
417
+ # "<button onclick=\"onClick()\">Click me</button>\n" +
418
+ # "<div></div>\n");
419
+ # page.click("button");
420
+ # }
421
+ # }
422
+ # }
423
+ # ```
424
+ #
316
425
  # ```python async
317
426
  # import asyncio
318
427
  # import hashlib
@@ -388,13 +497,19 @@ module Playwright
388
497
  wrap_impl(@impl.grant_permissions(unwrap_impl(permissions), origin: unwrap_impl(origin)))
389
498
  end
390
499
 
500
+ # > NOTE: CDP sessions are only supported on Chromium-based browsers.
501
+ #
502
+ # Returns the newly created session.
503
+ def new_cdp_session(page)
504
+ raise NotImplementedError.new('new_cdp_session is not implemented yet.')
505
+ end
506
+
391
507
  # Creates a new page in the browser context.
392
508
  def new_page
393
509
  wrap_impl(@impl.new_page)
394
510
  end
395
511
 
396
- # Returns all open pages in the context. Non visible pages, such as `"background_page"`, will not be listed here. You can
397
- # find them using [`method: ChromiumBrowserContext.backgroundPages`].
512
+ # Returns all open pages in the context.
398
513
  def pages
399
514
  wrap_impl(@impl.pages)
400
515
  end
@@ -402,7 +517,7 @@ module Playwright
402
517
  # Routing provides the capability to modify network requests that are made by any page in the browser context. Once route
403
518
  # is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted.
404
519
  #
405
- # An example of a naïve handler that aborts all image requests:
520
+ # An example of a naive handler that aborts all image requests:
406
521
  #
407
522
  #
408
523
  # ```js
@@ -413,6 +528,14 @@ module Playwright
413
528
  # await browser.close();
414
529
  # ```
415
530
  #
531
+ # ```java
532
+ # BrowserContext context = browser.newContext();
533
+ # context.route("**/*.{png,jpg,jpeg}", route -> route.abort());
534
+ # Page page = context.newPage();
535
+ # page.navigate("https://example.com");
536
+ # browser.close();
537
+ # ```
538
+ #
416
539
  # ```python async
417
540
  # context = await browser.new_context()
418
541
  # page = await context.new_page()
@@ -440,6 +563,14 @@ module Playwright
440
563
  # await browser.close();
441
564
  # ```
442
565
  #
566
+ # ```java
567
+ # BrowserContext context = browser.newContext();
568
+ # context.route(Pattern.compile("(\\.png$)|(\\.jpg$)"), route -> route.abort());
569
+ # Page page = context.newPage();
570
+ # page.navigate("https://example.com");
571
+ # browser.close();
572
+ # ```
573
+ #
443
574
  # ```python async
444
575
  # context = await browser.new_context()
445
576
  # page = await context.new_page()
@@ -462,11 +593,20 @@ module Playwright
462
593
  # Page routes (set up with [`method: Page.route`]) take precedence over browser context routes when request matches both
463
594
  # handlers.
464
595
  #
596
+ # To remove a route with its handler you can use [`method: BrowserContext.unroute`].
597
+ #
465
598
  # > NOTE: Enabling routing disables http cache.
466
599
  def route(url, handler)
467
600
  wrap_impl(@impl.route(unwrap_impl(url), unwrap_impl(handler)))
468
601
  end
469
602
 
603
+ # > NOTE: Service workers are only supported on Chromium-based browsers.
604
+ #
605
+ # All existing service workers in the context.
606
+ def service_workers
607
+ raise NotImplementedError.new('service_workers is not implemented yet.')
608
+ end
609
+
470
610
  # This setting will change the default maximum navigation time for the following methods and related shortcuts:
471
611
  # - [`method: Page.goBack`]
472
612
  # - [`method: Page.goForward`]
@@ -508,6 +648,10 @@ module Playwright
508
648
  # await browserContext.setGeolocation({latitude: 59.95, longitude: 30.31667});
509
649
  # ```
510
650
  #
651
+ # ```java
652
+ # browserContext.setGeolocation(new Geolocation(59.95, 30.31667));
653
+ # ```
654
+ #
511
655
  # ```python async
512
656
  # await browser_context.set_geolocation({"latitude": 59.95, "longitude": 30.31667})
513
657
  # ```
@@ -550,6 +694,10 @@ module Playwright
550
694
  # ]);
551
695
  # ```
552
696
  #
697
+ # ```java
698
+ # Page newPage = context.waitForPage(() -> page.click("button"));
699
+ # ```
700
+ #
553
701
  # ```python async
554
702
  # async with context.expect_event("page") as event_info:
555
703
  # await page.click("button")
@@ -601,12 +749,6 @@ module Playwright
601
749
  wrap_impl(@impl.pause)
602
750
  end
603
751
 
604
- # -- inherited from EventEmitter --
605
- # @nodoc
606
- def off(event, callback)
607
- event_emitter_proxy.off(event, callback)
608
- end
609
-
610
752
  # -- inherited from EventEmitter --
611
753
  # @nodoc
612
754
  def once(event, callback)
@@ -619,6 +761,12 @@ module Playwright
619
761
  event_emitter_proxy.on(event, callback)
620
762
  end
621
763
 
764
+ # -- inherited from EventEmitter --
765
+ # @nodoc
766
+ def off(event, callback)
767
+ event_emitter_proxy.off(event, callback)
768
+ end
769
+
622
770
  private def event_emitter_proxy
623
771
  @event_emitter_proxy ||= EventEmitterProxy.new(self, @impl)
624
772
  end