playwright-ruby-client 0.5.9 → 0.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/documentation/README.md +33 -0
- data/documentation/babel.config.js +3 -0
- data/documentation/docs/api/accessibility.md +7 -0
- data/documentation/docs/api/browser.md +187 -0
- data/documentation/docs/api/browser_context.md +397 -0
- data/documentation/docs/api/browser_type.md +105 -0
- data/documentation/docs/api/cdp_session.md +7 -0
- data/documentation/docs/api/console_message.md +41 -0
- data/documentation/docs/api/dialog.md +71 -0
- data/documentation/docs/api/element_handle.md +618 -0
- data/documentation/docs/api/experimental/_category_.yml +3 -0
- data/documentation/docs/api/experimental/android.md +25 -0
- data/documentation/docs/api/experimental/android_device.md +92 -0
- data/documentation/docs/api/experimental/android_input.md +38 -0
- data/documentation/docs/api/experimental/android_socket.md +7 -0
- data/documentation/docs/api/experimental/android_web_view.md +7 -0
- data/documentation/docs/api/file_chooser.md +50 -0
- data/documentation/docs/api/frame.md +866 -0
- data/documentation/docs/api/js_handle.md +113 -0
- data/documentation/docs/api/keyboard.md +157 -0
- data/documentation/docs/api/mouse.md +69 -0
- data/documentation/docs/api/page.md +1402 -0
- data/documentation/docs/api/playwright.md +63 -0
- data/documentation/docs/api/request.md +188 -0
- data/documentation/docs/api/response.md +97 -0
- data/documentation/docs/api/route.md +80 -0
- data/documentation/docs/api/selectors.md +23 -0
- data/documentation/docs/api/touchscreen.md +8 -0
- data/documentation/docs/api/tracing.md +54 -0
- data/documentation/docs/api/web_socket.md +7 -0
- data/documentation/docs/api/worker.md +24 -0
- data/documentation/docs/article/api_coverage.mdx +11 -0
- data/documentation/docs/article/getting_started.md +152 -0
- data/documentation/docs/article/guides/_category_.yml +3 -0
- data/documentation/docs/article/guides/download_playwright_driver.md +49 -0
- data/documentation/docs/article/guides/launch_browser.md +119 -0
- data/documentation/docs/article/guides/rails_integration.md +162 -0
- data/{docs → documentation/docs/include}/api_coverage.md +12 -1
- data/documentation/docusaurus.config.js +107 -0
- data/documentation/package.json +39 -0
- data/documentation/sidebars.js +15 -0
- data/documentation/src/components/HomepageFeatures.js +61 -0
- data/documentation/src/components/HomepageFeatures.module.css +13 -0
- data/documentation/src/css/custom.css +44 -0
- data/documentation/src/pages/index.js +50 -0
- data/documentation/src/pages/index.module.css +41 -0
- data/documentation/src/pages/markdown-page.md +7 -0
- data/documentation/static/.nojekyll +0 -0
- data/documentation/static/img/playwright-logo.svg +9 -0
- data/documentation/static/img/undraw_dropdown_menu.svg +1 -0
- data/documentation/static/img/undraw_web_development.svg +1 -0
- data/documentation/static/img/undraw_windows.svg +1 -0
- data/documentation/yarn.lock +8805 -0
- data/lib/playwright/channel_owners/binding_call.rb +33 -0
- data/lib/playwright/channel_owners/browser.rb +11 -2
- data/lib/playwright/channel_owners/browser_context.rb +58 -6
- data/lib/playwright/channel_owners/browser_type.rb +8 -1
- data/lib/playwright/channel_owners/element_handle.rb +17 -16
- data/lib/playwright/channel_owners/frame.rb +24 -34
- data/lib/playwright/channel_owners/js_handle.rb +2 -10
- data/lib/playwright/channel_owners/page.rb +37 -52
- data/lib/playwright/channel_owners/worker.rb +4 -0
- data/lib/playwright/download.rb +3 -2
- data/lib/playwright/events.rb +4 -0
- data/lib/playwright/input_files.rb +0 -8
- data/lib/playwright/javascript.rb +0 -10
- data/lib/playwright/javascript/expression.rb +2 -7
- data/lib/playwright/playwright_api.rb +16 -1
- data/lib/playwright/tracing_impl.rb +31 -0
- data/lib/playwright/version.rb +2 -1
- data/lib/playwright_api/accessibility.rb +7 -88
- data/lib/playwright_api/android.rb +2 -59
- data/lib/playwright_api/android_device.rb +6 -5
- data/lib/playwright_api/browser.rb +13 -122
- data/lib/playwright_api/browser_context.rb +66 -433
- data/lib/playwright_api/browser_type.rb +28 -78
- data/lib/playwright_api/cdp_session.rb +2 -25
- data/lib/playwright_api/console_message.rb +2 -0
- data/lib/playwright_api/dialog.rb +5 -63
- data/lib/playwright_api/element_handle.rb +96 -294
- data/lib/playwright_api/file_chooser.rb +0 -21
- data/lib/playwright_api/frame.rb +98 -564
- data/lib/playwright_api/js_handle.rb +10 -67
- data/lib/playwright_api/keyboard.rb +22 -166
- data/lib/playwright_api/mouse.rb +1 -45
- data/lib/playwright_api/page.rb +223 -1224
- data/lib/playwright_api/playwright.rb +8 -93
- data/lib/playwright_api/request.rb +9 -87
- data/lib/playwright_api/response.rb +1 -1
- data/lib/playwright_api/route.rb +3 -80
- data/lib/playwright_api/selectors.rb +0 -66
- data/lib/playwright_api/tracing.rb +39 -0
- data/lib/playwright_api/web_socket.rb +1 -1
- data/lib/playwright_api/worker.rb +28 -42
- data/playwright.gemspec +2 -2
- metadata +60 -20
- data/lib/playwright/javascript/function.rb +0 -67
|
@@ -1,72 +1,32 @@
|
|
|
1
1
|
module Playwright
|
|
2
2
|
# - extends: [EventEmitter]
|
|
3
|
-
#
|
|
3
|
+
#
|
|
4
4
|
# BrowserContexts provide a way to operate multiple independent browser sessions.
|
|
5
|
-
#
|
|
5
|
+
#
|
|
6
6
|
# If a page opens another page, e.g. with a `window.open` call, the popup will belong to the parent page's browser
|
|
7
7
|
# context.
|
|
8
|
-
#
|
|
8
|
+
#
|
|
9
9
|
# Playwright allows creation of "incognito" browser contexts with `browser.newContext()` method. "Incognito" browser
|
|
10
10
|
# contexts don't write any browsing data to disk.
|
|
11
|
-
#
|
|
12
11
|
#
|
|
13
|
-
# ```js
|
|
14
|
-
# // Create a new incognito browser context
|
|
15
|
-
# const context = await browser.newContext();
|
|
16
|
-
# // Create a new page inside context.
|
|
17
|
-
# const page = await context.newPage();
|
|
18
|
-
# await page.goto('https://example.com');
|
|
19
|
-
# // Dispose context once it's no longer needed.
|
|
20
|
-
# await context.close();
|
|
21
|
-
# ```
|
|
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
|
-
#
|
|
33
|
-
# ```python async
|
|
34
|
-
# # create a new incognito browser context
|
|
35
|
-
# context = await browser.new_context()
|
|
36
|
-
# # create a new page inside context.
|
|
37
|
-
# page = await context.new_page()
|
|
38
|
-
# await page.goto("https://example.com")
|
|
39
|
-
# # dispose context once it"s no longer needed.
|
|
40
|
-
# await context.close()
|
|
41
|
-
# ```
|
|
42
|
-
#
|
|
43
12
|
# ```python sync
|
|
44
13
|
# # create a new incognito browser context
|
|
45
14
|
# context = browser.new_context()
|
|
46
15
|
# # create a new page inside context.
|
|
47
16
|
# page = context.new_page()
|
|
48
17
|
# page.goto("https://example.com")
|
|
49
|
-
# # dispose context once it
|
|
18
|
+
# # dispose context once it is no longer needed.
|
|
50
19
|
# context.close()
|
|
51
20
|
# ```
|
|
52
21
|
class BrowserContext < PlaywrightApi
|
|
53
22
|
|
|
23
|
+
def tracing # property
|
|
24
|
+
wrap_impl(@impl.tracing)
|
|
25
|
+
end
|
|
26
|
+
|
|
54
27
|
# Adds cookies into this browser context. All pages within this context will have these cookies installed. Cookies can be
|
|
55
28
|
# obtained via [`method: BrowserContext.cookies`].
|
|
56
|
-
#
|
|
57
29
|
#
|
|
58
|
-
# ```js
|
|
59
|
-
# await browserContext.addCookies([cookieObject1, cookieObject2]);
|
|
60
|
-
# ```
|
|
61
|
-
#
|
|
62
|
-
# ```java
|
|
63
|
-
# browserContext.addCookies(Arrays.asList(cookieObject1, cookieObject2));
|
|
64
|
-
# ```
|
|
65
|
-
#
|
|
66
|
-
# ```python async
|
|
67
|
-
# await browser_context.add_cookies([cookie_object1, cookie_object2])
|
|
68
|
-
# ```
|
|
69
|
-
#
|
|
70
30
|
# ```python sync
|
|
71
31
|
# browser_context.add_cookies([cookie_object1, cookie_object2])
|
|
72
32
|
# ```
|
|
@@ -78,41 +38,17 @@ module Playwright
|
|
|
78
38
|
# - Whenever a page is created in the browser context or is navigated.
|
|
79
39
|
# - Whenever a child frame is attached or navigated in any page in the browser context. In this case, the script is
|
|
80
40
|
# evaluated in the context of the newly attached frame.
|
|
81
|
-
#
|
|
41
|
+
#
|
|
82
42
|
# The script is evaluated after the document was created but before any of its scripts were run. This is useful to amend
|
|
83
43
|
# the JavaScript environment, e.g. to seed `Math.random`.
|
|
84
|
-
#
|
|
85
|
-
# An example of overriding `Math.random` before the page loads:
|
|
86
|
-
#
|
|
87
44
|
#
|
|
88
|
-
#
|
|
89
|
-
# // preload.js
|
|
90
|
-
# Math.random = () => 42;
|
|
91
|
-
# ```
|
|
92
|
-
#
|
|
45
|
+
# An example of overriding `Math.random` before the page loads:
|
|
93
46
|
#
|
|
94
|
-
# ```js
|
|
95
|
-
# // In your playwright script, assuming the preload.js file is in same directory.
|
|
96
|
-
# await browserContext.addInitScript({
|
|
97
|
-
# path: 'preload.js'
|
|
98
|
-
# });
|
|
99
|
-
# ```
|
|
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
|
-
#
|
|
106
|
-
# ```python async
|
|
107
|
-
# # in your playwright script, assuming the preload.js file is in same directory.
|
|
108
|
-
# await browser_context.add_init_script(path="preload.js")
|
|
109
|
-
# ```
|
|
110
|
-
#
|
|
111
47
|
# ```python sync
|
|
112
48
|
# # in your playwright script, assuming the preload.js file is in same directory.
|
|
113
49
|
# browser_context.add_init_script(path="preload.js")
|
|
114
50
|
# ```
|
|
115
|
-
#
|
|
51
|
+
#
|
|
116
52
|
# > NOTE: The order of evaluation of multiple scripts installed via [`method: BrowserContext.addInitScript`] and
|
|
117
53
|
# [`method: Page.addInitScript`] is not defined.
|
|
118
54
|
def add_init_script(path: nil, script: nil)
|
|
@@ -120,7 +56,7 @@ module Playwright
|
|
|
120
56
|
end
|
|
121
57
|
|
|
122
58
|
# > NOTE: Background pages are only supported on Chromium-based browsers.
|
|
123
|
-
#
|
|
59
|
+
#
|
|
124
60
|
# All existing background pages in the context.
|
|
125
61
|
def background_pages
|
|
126
62
|
raise NotImplementedError.new('background_pages is not implemented yet.')
|
|
@@ -137,29 +73,7 @@ module Playwright
|
|
|
137
73
|
end
|
|
138
74
|
|
|
139
75
|
# Clears all permission overrides for the browser context.
|
|
140
|
-
#
|
|
141
76
|
#
|
|
142
|
-
# ```js
|
|
143
|
-
# const context = await browser.newContext();
|
|
144
|
-
# await context.grantPermissions(['clipboard-read']);
|
|
145
|
-
# // do stuff ..
|
|
146
|
-
# context.clearPermissions();
|
|
147
|
-
# ```
|
|
148
|
-
#
|
|
149
|
-
# ```java
|
|
150
|
-
# BrowserContext context = browser.newContext();
|
|
151
|
-
# context.grantPermissions(Arrays.asList("clipboard-read"));
|
|
152
|
-
# // do stuff ..
|
|
153
|
-
# context.clearPermissions();
|
|
154
|
-
# ```
|
|
155
|
-
#
|
|
156
|
-
# ```python async
|
|
157
|
-
# context = await browser.new_context()
|
|
158
|
-
# await context.grant_permissions(["clipboard-read"])
|
|
159
|
-
# # do stuff ..
|
|
160
|
-
# context.clear_permissions()
|
|
161
|
-
# ```
|
|
162
|
-
#
|
|
163
77
|
# ```python sync
|
|
164
78
|
# context = browser.new_context()
|
|
165
79
|
# context.grant_permissions(["clipboard-read"])
|
|
@@ -171,7 +85,7 @@ module Playwright
|
|
|
171
85
|
end
|
|
172
86
|
|
|
173
87
|
# Closes the browser context. All the pages that belong to the browser context will be closed.
|
|
174
|
-
#
|
|
88
|
+
#
|
|
175
89
|
# > NOTE: The default browser context cannot be closed.
|
|
176
90
|
def close
|
|
177
91
|
wrap_impl(@impl.close)
|
|
@@ -186,90 +100,17 @@ module Playwright
|
|
|
186
100
|
# The method adds a function called `name` on the `window` object of every frame in every page in the context. When
|
|
187
101
|
# called, the function executes `callback` and returns a [Promise] which resolves to the return value of `callback`. If
|
|
188
102
|
# the `callback` returns a [Promise], it will be awaited.
|
|
189
|
-
#
|
|
103
|
+
#
|
|
190
104
|
# The first argument of the `callback` function contains information about the caller: `{ browserContext: BrowserContext,
|
|
191
105
|
# page: Page, frame: Frame }`.
|
|
192
|
-
#
|
|
106
|
+
#
|
|
193
107
|
# See [`method: Page.exposeBinding`] for page-only version.
|
|
194
|
-
#
|
|
108
|
+
#
|
|
195
109
|
# An example of exposing page URL to all frames in all pages in the context:
|
|
196
|
-
#
|
|
197
|
-
#
|
|
198
|
-
# ```js
|
|
199
|
-
# const { webkit } = require('playwright'); // Or 'chromium' or 'firefox'.
|
|
200
|
-
#
|
|
201
|
-
# (async () => {
|
|
202
|
-
# const browser = await webkit.launch({ headless: false });
|
|
203
|
-
# const context = await browser.newContext();
|
|
204
|
-
# await context.exposeBinding('pageURL', ({ page }) => page.url());
|
|
205
|
-
# const page = await context.newPage();
|
|
206
|
-
# await page.setContent(`
|
|
207
|
-
# <script>
|
|
208
|
-
# async function onClick() {
|
|
209
|
-
# document.querySelector('div').textContent = await window.pageURL();
|
|
210
|
-
# }
|
|
211
|
-
# </script>
|
|
212
|
-
# <button onclick="onClick()">Click me</button>
|
|
213
|
-
# <div></div>
|
|
214
|
-
# `);
|
|
215
|
-
# await page.click('button');
|
|
216
|
-
# })();
|
|
217
|
-
# ```
|
|
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
|
-
#
|
|
243
|
-
# ```python async
|
|
244
|
-
# import asyncio
|
|
245
|
-
# from playwright.async_api import async_playwright
|
|
246
|
-
#
|
|
247
|
-
# async def run(playwright):
|
|
248
|
-
# webkit = playwright.webkit
|
|
249
|
-
# browser = await webkit.launch(headless=false)
|
|
250
|
-
# context = await browser.new_context()
|
|
251
|
-
# await context.expose_binding("pageURL", lambda source: source["page"].url)
|
|
252
|
-
# page = await context.new_page()
|
|
253
|
-
# await page.set_content("""
|
|
254
|
-
# <script>
|
|
255
|
-
# async function onClick() {
|
|
256
|
-
# document.querySelector('div').textContent = await window.pageURL();
|
|
257
|
-
# }
|
|
258
|
-
# </script>
|
|
259
|
-
# <button onclick="onClick()">Click me</button>
|
|
260
|
-
# <div></div>
|
|
261
|
-
# """)
|
|
262
|
-
# await page.click("button")
|
|
263
|
-
#
|
|
264
|
-
# async def main():
|
|
265
|
-
# async with async_playwright() as playwright:
|
|
266
|
-
# await run(playwright)
|
|
267
|
-
# asyncio.run(main())
|
|
268
|
-
# ```
|
|
269
|
-
#
|
|
110
|
+
#
|
|
270
111
|
# ```python sync
|
|
271
112
|
# from playwright.sync_api import sync_playwright
|
|
272
|
-
#
|
|
113
|
+
#
|
|
273
114
|
# def run(playwright):
|
|
274
115
|
# webkit = playwright.webkit
|
|
275
116
|
# browser = webkit.launch(headless=false)
|
|
@@ -286,59 +127,17 @@ module Playwright
|
|
|
286
127
|
# <div></div>
|
|
287
128
|
# """)
|
|
288
129
|
# page.click("button")
|
|
289
|
-
#
|
|
130
|
+
#
|
|
290
131
|
# with sync_playwright() as playwright:
|
|
291
132
|
# run(playwright)
|
|
292
133
|
# ```
|
|
293
|
-
#
|
|
134
|
+
#
|
|
294
135
|
# An example of passing an element handle:
|
|
295
|
-
#
|
|
296
136
|
#
|
|
297
|
-
# ```js
|
|
298
|
-
# await context.exposeBinding('clicked', async (source, element) => {
|
|
299
|
-
# console.log(await element.textContent());
|
|
300
|
-
# }, { handle: true });
|
|
301
|
-
# await page.setContent(`
|
|
302
|
-
# <script>
|
|
303
|
-
# document.addEventListener('click', event => window.clicked(event.target));
|
|
304
|
-
# </script>
|
|
305
|
-
# <div>Click me</div>
|
|
306
|
-
# <div>Or click me</div>
|
|
307
|
-
# `);
|
|
308
|
-
# ```
|
|
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
|
-
#
|
|
324
|
-
# ```python async
|
|
325
|
-
# async def print(source, element):
|
|
326
|
-
# print(await element.text_content())
|
|
327
|
-
#
|
|
328
|
-
# await context.expose_binding("clicked", print, handle=true)
|
|
329
|
-
# await page.set_content("""
|
|
330
|
-
# <script>
|
|
331
|
-
# document.addEventListener('click', event => window.clicked(event.target));
|
|
332
|
-
# </script>
|
|
333
|
-
# <div>Click me</div>
|
|
334
|
-
# <div>Or click me</div>
|
|
335
|
-
# """)
|
|
336
|
-
# ```
|
|
337
|
-
#
|
|
338
137
|
# ```python sync
|
|
339
138
|
# def print(source, element):
|
|
340
139
|
# print(element.text_content())
|
|
341
|
-
#
|
|
140
|
+
#
|
|
342
141
|
# context.expose_binding("clicked", print, handle=true)
|
|
343
142
|
# page.set_content("""
|
|
344
143
|
# <script>
|
|
@@ -354,136 +153,40 @@ module Playwright
|
|
|
354
153
|
|
|
355
154
|
# The method adds a function called `name` on the `window` object of every frame in every page in the context. When
|
|
356
155
|
# called, the function executes `callback` and returns a [Promise] which resolves to the return value of `callback`.
|
|
357
|
-
#
|
|
156
|
+
#
|
|
358
157
|
# If the `callback` returns a [Promise], it will be awaited.
|
|
359
|
-
#
|
|
158
|
+
#
|
|
360
159
|
# See [`method: Page.exposeFunction`] for page-only version.
|
|
361
|
-
#
|
|
362
|
-
# An example of adding
|
|
363
|
-
#
|
|
364
|
-
#
|
|
365
|
-
# ```js
|
|
366
|
-
# const { webkit } = require('playwright'); // Or 'chromium' or 'firefox'.
|
|
367
|
-
# const crypto = require('crypto');
|
|
368
|
-
#
|
|
369
|
-
# (async () => {
|
|
370
|
-
# const browser = await webkit.launch({ headless: false });
|
|
371
|
-
# const context = await browser.newContext();
|
|
372
|
-
# await context.exposeFunction('md5', text => crypto.createHash('md5').update(text).digest('hex'));
|
|
373
|
-
# const page = await context.newPage();
|
|
374
|
-
# await page.setContent(`
|
|
375
|
-
# <script>
|
|
376
|
-
# async function onClick() {
|
|
377
|
-
# document.querySelector('div').textContent = await window.md5('PLAYWRIGHT');
|
|
378
|
-
# }
|
|
379
|
-
# </script>
|
|
380
|
-
# <button onclick="onClick()">Click me</button>
|
|
381
|
-
# <div></div>
|
|
382
|
-
# `);
|
|
383
|
-
# await page.click('button');
|
|
384
|
-
# })();
|
|
385
|
-
# ```
|
|
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
|
-
#
|
|
425
|
-
# ```python async
|
|
426
|
-
# import asyncio
|
|
427
|
-
# import hashlib
|
|
428
|
-
# from playwright.async_api import async_playwright
|
|
429
|
-
#
|
|
430
|
-
# async def sha1(text):
|
|
431
|
-
# m = hashlib.sha1()
|
|
432
|
-
# m.update(bytes(text, "utf8"))
|
|
433
|
-
# return m.hexdigest()
|
|
434
|
-
#
|
|
435
|
-
#
|
|
436
|
-
# async def run(playwright):
|
|
437
|
-
# webkit = playwright.webkit
|
|
438
|
-
# browser = await webkit.launch(headless=False)
|
|
439
|
-
# context = await browser.new_context()
|
|
440
|
-
# await context.expose_function("sha1", sha1)
|
|
441
|
-
# page = await context.new_page()
|
|
442
|
-
# await page.set_content("""
|
|
443
|
-
# <script>
|
|
444
|
-
# async function onClick() {
|
|
445
|
-
# document.querySelector('div').textContent = await window.sha1('PLAYWRIGHT');
|
|
446
|
-
# }
|
|
447
|
-
# </script>
|
|
448
|
-
# <button onclick="onClick()">Click me</button>
|
|
449
|
-
# <div></div>
|
|
450
|
-
# """)
|
|
451
|
-
# await page.click("button")
|
|
452
|
-
#
|
|
453
|
-
# async def main():
|
|
454
|
-
# async with async_playwright() as playwright:
|
|
455
|
-
# await run(playwright)
|
|
456
|
-
# asyncio.run(main())
|
|
457
|
-
# ```
|
|
458
|
-
#
|
|
160
|
+
#
|
|
161
|
+
# An example of adding a `sha256` function to all pages in the context:
|
|
162
|
+
#
|
|
459
163
|
# ```python sync
|
|
460
164
|
# import hashlib
|
|
461
165
|
# from playwright.sync_api import sync_playwright
|
|
462
|
-
#
|
|
463
|
-
# def
|
|
464
|
-
# m = hashlib.
|
|
166
|
+
#
|
|
167
|
+
# def sha256(text):
|
|
168
|
+
# m = hashlib.sha256()
|
|
465
169
|
# m.update(bytes(text, "utf8"))
|
|
466
170
|
# return m.hexdigest()
|
|
467
|
-
#
|
|
468
|
-
#
|
|
171
|
+
#
|
|
172
|
+
#
|
|
469
173
|
# def run(playwright):
|
|
470
174
|
# webkit = playwright.webkit
|
|
471
175
|
# browser = webkit.launch(headless=False)
|
|
472
176
|
# context = browser.new_context()
|
|
473
|
-
# context.expose_function("
|
|
177
|
+
# context.expose_function("sha256", sha256)
|
|
474
178
|
# page = context.new_page()
|
|
475
|
-
# page.expose_function("sha1", sha1)
|
|
476
179
|
# page.set_content("""
|
|
477
180
|
# <script>
|
|
478
181
|
# async function onClick() {
|
|
479
|
-
# document.querySelector('div').textContent = await window.
|
|
182
|
+
# document.querySelector('div').textContent = await window.sha256('PLAYWRIGHT');
|
|
480
183
|
# }
|
|
481
184
|
# </script>
|
|
482
185
|
# <button onclick="onClick()">Click me</button>
|
|
483
186
|
# <div></div>
|
|
484
187
|
# """)
|
|
485
188
|
# page.click("button")
|
|
486
|
-
#
|
|
189
|
+
#
|
|
487
190
|
# with sync_playwright() as playwright:
|
|
488
191
|
# run(playwright)
|
|
489
192
|
# ```
|
|
@@ -498,7 +201,7 @@ module Playwright
|
|
|
498
201
|
end
|
|
499
202
|
|
|
500
203
|
# > NOTE: CDP sessions are only supported on Chromium-based browsers.
|
|
501
|
-
#
|
|
204
|
+
#
|
|
502
205
|
# Returns the newly created session.
|
|
503
206
|
def new_cdp_session(page)
|
|
504
207
|
raise NotImplementedError.new('new_cdp_session is not implemented yet.')
|
|
@@ -516,34 +219,9 @@ module Playwright
|
|
|
516
219
|
|
|
517
220
|
# Routing provides the capability to modify network requests that are made by any page in the browser context. Once route
|
|
518
221
|
# is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted.
|
|
519
|
-
#
|
|
222
|
+
#
|
|
520
223
|
# An example of a naive handler that aborts all image requests:
|
|
521
|
-
#
|
|
522
|
-
#
|
|
523
|
-
# ```js
|
|
524
|
-
# const context = await browser.newContext();
|
|
525
|
-
# await context.route('**/*.{png,jpg,jpeg}', route => route.abort());
|
|
526
|
-
# const page = await context.newPage();
|
|
527
|
-
# await page.goto('https://example.com');
|
|
528
|
-
# await browser.close();
|
|
529
|
-
# ```
|
|
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
|
-
#
|
|
539
|
-
# ```python async
|
|
540
|
-
# context = await browser.new_context()
|
|
541
|
-
# page = await context.new_page()
|
|
542
|
-
# await context.route("**/*.{png,jpg,jpeg}", lambda route: route.abort())
|
|
543
|
-
# await page.goto("https://example.com")
|
|
544
|
-
# await browser.close()
|
|
545
|
-
# ```
|
|
546
|
-
#
|
|
224
|
+
#
|
|
547
225
|
# ```python sync
|
|
548
226
|
# context = browser.new_context()
|
|
549
227
|
# page = context.new_page()
|
|
@@ -551,35 +229,9 @@ module Playwright
|
|
|
551
229
|
# page.goto("https://example.com")
|
|
552
230
|
# browser.close()
|
|
553
231
|
# ```
|
|
554
|
-
#
|
|
232
|
+
#
|
|
555
233
|
# or the same snippet using a regex pattern instead:
|
|
556
|
-
#
|
|
557
|
-
#
|
|
558
|
-
# ```js
|
|
559
|
-
# const context = await browser.newContext();
|
|
560
|
-
# await context.route(/(\.png$)|(\.jpg$)/, route => route.abort());
|
|
561
|
-
# const page = await context.newPage();
|
|
562
|
-
# await page.goto('https://example.com');
|
|
563
|
-
# await browser.close();
|
|
564
|
-
# ```
|
|
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
|
-
#
|
|
574
|
-
# ```python async
|
|
575
|
-
# context = await browser.new_context()
|
|
576
|
-
# page = await context.new_page()
|
|
577
|
-
# await context.route(re.compile(r"(\.png$)|(\.jpg$)"), lambda route: route.abort())
|
|
578
|
-
# page = await context.new_page()
|
|
579
|
-
# await page.goto("https://example.com")
|
|
580
|
-
# await browser.close()
|
|
581
|
-
# ```
|
|
582
|
-
#
|
|
234
|
+
#
|
|
583
235
|
# ```python sync
|
|
584
236
|
# context = browser.new_context()
|
|
585
237
|
# page = context.new_page()
|
|
@@ -589,19 +241,31 @@ module Playwright
|
|
|
589
241
|
# page.goto("https://example.com")
|
|
590
242
|
# browser.close()
|
|
591
243
|
# ```
|
|
592
|
-
#
|
|
244
|
+
#
|
|
245
|
+
# It is possible to examine the request to decide the route action. For example, mocking all requests that contain some
|
|
246
|
+
# post data, and leaving all other requests as is:
|
|
247
|
+
#
|
|
248
|
+
# ```python sync
|
|
249
|
+
# def handle_route(route):
|
|
250
|
+
# if ("my-string" in route.request.post_data)
|
|
251
|
+
# route.fulfill(body="mocked-data")
|
|
252
|
+
# else
|
|
253
|
+
# route.continue_()
|
|
254
|
+
# context.route("/api/**", handle_route)
|
|
255
|
+
# ```
|
|
256
|
+
#
|
|
593
257
|
# Page routes (set up with [`method: Page.route`]) take precedence over browser context routes when request matches both
|
|
594
258
|
# handlers.
|
|
595
|
-
#
|
|
259
|
+
#
|
|
596
260
|
# To remove a route with its handler you can use [`method: BrowserContext.unroute`].
|
|
597
|
-
#
|
|
261
|
+
#
|
|
598
262
|
# > NOTE: Enabling routing disables http cache.
|
|
599
263
|
def route(url, handler)
|
|
600
264
|
wrap_impl(@impl.route(unwrap_impl(url), unwrap_impl(handler)))
|
|
601
265
|
end
|
|
602
266
|
|
|
603
267
|
# > NOTE: Service workers are only supported on Chromium-based browsers.
|
|
604
|
-
#
|
|
268
|
+
#
|
|
605
269
|
# All existing service workers in the context.
|
|
606
270
|
def service_workers
|
|
607
271
|
raise NotImplementedError.new('service_workers is not implemented yet.')
|
|
@@ -614,7 +278,7 @@ module Playwright
|
|
|
614
278
|
# - [`method: Page.reload`]
|
|
615
279
|
# - [`method: Page.setContent`]
|
|
616
280
|
# - [`method: Page.waitForNavigation`]
|
|
617
|
-
#
|
|
281
|
+
#
|
|
618
282
|
# > NOTE: [`method: Page.setDefaultNavigationTimeout`] and [`method: Page.setDefaultTimeout`] take priority over
|
|
619
283
|
# [`method: BrowserContext.setDefaultNavigationTimeout`].
|
|
620
284
|
def set_default_navigation_timeout(timeout)
|
|
@@ -623,7 +287,7 @@ module Playwright
|
|
|
623
287
|
alias_method :default_navigation_timeout=, :set_default_navigation_timeout
|
|
624
288
|
|
|
625
289
|
# This setting will change the default maximum time for all the methods accepting `timeout` option.
|
|
626
|
-
#
|
|
290
|
+
#
|
|
627
291
|
# > NOTE: [`method: Page.setDefaultNavigationTimeout`], [`method: Page.setDefaultTimeout`] and
|
|
628
292
|
# [`method: BrowserContext.setDefaultNavigationTimeout`] take priority over [`method: BrowserContext.setDefaultTimeout`].
|
|
629
293
|
def set_default_timeout(timeout)
|
|
@@ -634,7 +298,7 @@ module Playwright
|
|
|
634
298
|
# The extra HTTP headers will be sent with every request initiated by any page in the context. These headers are merged
|
|
635
299
|
# with page-specific extra HTTP headers set with [`method: Page.setExtraHTTPHeaders`]. If page overrides a particular
|
|
636
300
|
# header, page-specific header value will be used instead of the browser context header value.
|
|
637
|
-
#
|
|
301
|
+
#
|
|
638
302
|
# > NOTE: [`method: BrowserContext.setExtraHTTPHeaders`] does not guarantee the order of headers in the outgoing requests.
|
|
639
303
|
def set_extra_http_headers(headers)
|
|
640
304
|
wrap_impl(@impl.set_extra_http_headers(unwrap_impl(headers)))
|
|
@@ -642,24 +306,11 @@ module Playwright
|
|
|
642
306
|
alias_method :extra_http_headers=, :set_extra_http_headers
|
|
643
307
|
|
|
644
308
|
# Sets the context's geolocation. Passing `null` or `undefined` emulates position unavailable.
|
|
645
|
-
#
|
|
646
309
|
#
|
|
647
|
-
# ```js
|
|
648
|
-
# await browserContext.setGeolocation({latitude: 59.95, longitude: 30.31667});
|
|
649
|
-
# ```
|
|
650
|
-
#
|
|
651
|
-
# ```java
|
|
652
|
-
# browserContext.setGeolocation(new Geolocation(59.95, 30.31667));
|
|
653
|
-
# ```
|
|
654
|
-
#
|
|
655
|
-
# ```python async
|
|
656
|
-
# await browser_context.set_geolocation({"latitude": 59.95, "longitude": 30.31667})
|
|
657
|
-
# ```
|
|
658
|
-
#
|
|
659
310
|
# ```python sync
|
|
660
311
|
# browser_context.set_geolocation({"latitude": 59.95, "longitude": 30.31667})
|
|
661
312
|
# ```
|
|
662
|
-
#
|
|
313
|
+
#
|
|
663
314
|
# > NOTE: Consider using [`method: BrowserContext.grantPermissions`] to grant permissions for the browser context pages to
|
|
664
315
|
# read its geolocation.
|
|
665
316
|
def set_geolocation(geolocation)
|
|
@@ -685,25 +336,7 @@ module Playwright
|
|
|
685
336
|
|
|
686
337
|
# Waits for event to fire and passes its value into the predicate function. Returns when the predicate returns truthy
|
|
687
338
|
# value. Will throw an error if the context closes before the event is fired. Returns the event data value.
|
|
688
|
-
#
|
|
689
339
|
#
|
|
690
|
-
# ```js
|
|
691
|
-
# const [page, _] = await Promise.all([
|
|
692
|
-
# context.waitForEvent('page'),
|
|
693
|
-
# page.click('button')
|
|
694
|
-
# ]);
|
|
695
|
-
# ```
|
|
696
|
-
#
|
|
697
|
-
# ```java
|
|
698
|
-
# Page newPage = context.waitForPage(() -> page.click("button"));
|
|
699
|
-
# ```
|
|
700
|
-
#
|
|
701
|
-
# ```python async
|
|
702
|
-
# async with context.expect_event("page") as event_info:
|
|
703
|
-
# await page.click("button")
|
|
704
|
-
# page = await event_info.value
|
|
705
|
-
# ```
|
|
706
|
-
#
|
|
707
340
|
# ```python sync
|
|
708
341
|
# with context.expect_event("page") as event_info:
|
|
709
342
|
# page.click("button")
|
|
@@ -721,10 +354,10 @@ module Playwright
|
|
|
721
354
|
end
|
|
722
355
|
|
|
723
356
|
# > NOTE: In most cases, you should use [`method: BrowserContext.waitForEvent`].
|
|
724
|
-
#
|
|
357
|
+
#
|
|
725
358
|
# Waits for given `event` to fire. If predicate is provided, it passes event's value into the `predicate` function and
|
|
726
|
-
# waits for `predicate(event)` to return a truthy value. Will throw an error if the
|
|
727
|
-
# fired.
|
|
359
|
+
# waits for `predicate(event)` to return a truthy value. Will throw an error if the browser context is closed before the
|
|
360
|
+
# `event` is fired.
|
|
728
361
|
def wait_for_event(event, predicate: nil, timeout: nil)
|
|
729
362
|
raise NotImplementedError.new('wait_for_event is not implemented yet.')
|
|
730
363
|
end
|
|
@@ -740,13 +373,13 @@ module Playwright
|
|
|
740
373
|
end
|
|
741
374
|
|
|
742
375
|
# @nodoc
|
|
743
|
-
def
|
|
744
|
-
wrap_impl(@impl.
|
|
376
|
+
def options=(req)
|
|
377
|
+
wrap_impl(@impl.options=(unwrap_impl(req)))
|
|
745
378
|
end
|
|
746
379
|
|
|
747
380
|
# @nodoc
|
|
748
|
-
def
|
|
749
|
-
wrap_impl(@impl.
|
|
381
|
+
def pause
|
|
382
|
+
wrap_impl(@impl.pause)
|
|
750
383
|
end
|
|
751
384
|
|
|
752
385
|
# -- inherited from EventEmitter --
|