playwright-ruby-client 0.5.7 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- 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 +185 -0
- data/documentation/docs/api/browser_context.md +398 -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 +74 -0
- data/documentation/docs/api/element_handle.md +640 -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 +91 -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 +51 -0
- data/documentation/docs/api/frame.md +867 -0
- data/documentation/docs/api/js_handle.md +116 -0
- data/documentation/docs/api/keyboard.md +157 -0
- data/documentation/docs/api/mouse.md +69 -0
- data/documentation/docs/api/page.md +1469 -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 +7 -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 +51 -0
- data/{docs → documentation/docs/include}/api_coverage.md +10 -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_owner.rb +3 -0
- data/lib/playwright/channel_owners/binding_call.rb +33 -0
- data/lib/playwright/channel_owners/browser.rb +27 -2
- data/lib/playwright/channel_owners/browser_context.rb +54 -3
- 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 +29 -34
- data/lib/playwright/channel_owners/js_handle.rb +2 -10
- data/lib/playwright/channel_owners/page.rb +29 -45
- 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 +1 -5
- 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 +8 -65
- data/lib/playwright_api/android_device.rb +8 -8
- data/lib/playwright_api/browser.rb +15 -126
- data/lib/playwright_api/browser_context.rb +63 -429
- data/lib/playwright_api/browser_type.rb +33 -84
- data/lib/playwright_api/cdp_session.rb +2 -25
- data/lib/playwright_api/console_message.rb +8 -6
- data/lib/playwright_api/dialog.rb +11 -69
- data/lib/playwright_api/element_handle.rb +102 -300
- data/lib/playwright_api/file_chooser.rb +0 -21
- data/lib/playwright_api/frame.rb +105 -571
- data/lib/playwright_api/js_handle.rb +16 -73
- data/lib/playwright_api/keyboard.rb +22 -166
- data/lib/playwright_api/mouse.rb +1 -45
- data/lib/playwright_api/page.rb +202 -1217
- data/lib/playwright_api/playwright.rb +14 -99
- data/lib/playwright_api/request.rb +15 -93
- data/lib/playwright_api/response.rb +7 -7
- data/lib/playwright_api/route.rb +9 -86
- data/lib/playwright_api/selectors.rb +6 -72
- data/lib/playwright_api/tracing.rb +39 -0
- data/lib/playwright_api/web_socket.rb +1 -1
- data/lib/playwright_api/worker.rb +6 -42
- data/playwright.gemspec +2 -2
- metadata +59 -20
- data/lib/playwright/javascript/function.rb +0 -67
@@ -1,70 +1,13 @@
|
|
1
1
|
module Playwright
|
2
2
|
# Playwright has **experimental** support for Android automation. You can access android namespace via:
|
3
|
-
#
|
4
3
|
#
|
5
|
-
# ```js
|
6
|
-
# const { _android: android } = require('playwright');
|
7
|
-
# ```
|
8
|
-
#
|
9
4
|
# An example of the Android automation script would be:
|
10
|
-
#
|
11
5
|
#
|
12
|
-
# ```js
|
13
|
-
# const { _android: android } = require('playwright');
|
14
|
-
#
|
15
|
-
# (async () => {
|
16
|
-
# // Connect to the device.
|
17
|
-
# const [device] = await android.devices();
|
18
|
-
# console.log(`Model: ${device.model()}`);
|
19
|
-
# console.log(`Serial: ${device.serial()}`);
|
20
|
-
# // Take screenshot of the whole device.
|
21
|
-
# await device.screenshot({ path: 'device.png' });
|
22
|
-
#
|
23
|
-
# {
|
24
|
-
# // --------------------- WebView -----------------------
|
25
|
-
#
|
26
|
-
# // Launch an application with WebView.
|
27
|
-
# await device.shell('am force-stop org.chromium.webview_shell');
|
28
|
-
# await device.shell('am start org.chromium.webview_shell/.WebViewBrowserActivity');
|
29
|
-
# // Get the WebView.
|
30
|
-
# const webview = await device.webView({ pkg: 'org.chromium.webview_shell' });
|
31
|
-
#
|
32
|
-
# // Fill the input box.
|
33
|
-
# await device.fill({ res: 'org.chromium.webview_shell:id/url_field' }, 'github.com/microsoft/playwright');
|
34
|
-
# await device.press({ res: 'org.chromium.webview_shell:id/url_field' }, 'Enter');
|
35
|
-
#
|
36
|
-
# // Work with WebView's page as usual.
|
37
|
-
# const page = await webview.page();
|
38
|
-
# await page.waitForNavigation({ url: /.*microsoft\/playwright.*/ });
|
39
|
-
# console.log(await page.title());
|
40
|
-
# }
|
41
|
-
#
|
42
|
-
# {
|
43
|
-
# // --------------------- Browser -----------------------
|
44
|
-
#
|
45
|
-
# // Launch Chrome browser.
|
46
|
-
# await device.shell('am force-stop com.android.chrome');
|
47
|
-
# const context = await device.launchBrowser();
|
48
|
-
#
|
49
|
-
# // Use BrowserContext as usual.
|
50
|
-
# const page = await context.newPage();
|
51
|
-
# await page.goto('https://webkit.org/');
|
52
|
-
# console.log(await page.evaluate(() => window.location.href));
|
53
|
-
# await page.screenshot({ path: 'page.png' });
|
54
|
-
#
|
55
|
-
# await context.close();
|
56
|
-
# }
|
57
|
-
#
|
58
|
-
# // Close the device.
|
59
|
-
# await device.close();
|
60
|
-
# })();
|
61
|
-
# ```
|
62
|
-
#
|
63
6
|
# Note that since you don't need Playwright to install web browsers when testing Android, you can omit browser download
|
64
7
|
# via setting the following environment variable when installing Playwright:
|
65
|
-
#
|
8
|
+
#
|
66
9
|
# ```sh js
|
67
|
-
#
|
10
|
+
# PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm i -D playwright
|
68
11
|
# ```
|
69
12
|
class Android < PlaywrightApi
|
70
13
|
|
@@ -79,12 +22,6 @@ module Playwright
|
|
79
22
|
end
|
80
23
|
alias_method :default_timeout=, :set_default_timeout
|
81
24
|
|
82
|
-
# -- inherited from EventEmitter --
|
83
|
-
# @nodoc
|
84
|
-
def once(event, callback)
|
85
|
-
event_emitter_proxy.once(event, callback)
|
86
|
-
end
|
87
|
-
|
88
25
|
# -- inherited from EventEmitter --
|
89
26
|
# @nodoc
|
90
27
|
def on(event, callback)
|
@@ -97,6 +34,12 @@ module Playwright
|
|
97
34
|
event_emitter_proxy.off(event, callback)
|
98
35
|
end
|
99
36
|
|
37
|
+
# -- inherited from EventEmitter --
|
38
|
+
# @nodoc
|
39
|
+
def once(event, callback)
|
40
|
+
event_emitter_proxy.once(event, callback)
|
41
|
+
end
|
42
|
+
|
100
43
|
private def event_emitter_proxy
|
101
44
|
@event_emitter_proxy ||= EventEmitterProxy.new(self, @impl)
|
102
45
|
end
|
@@ -160,20 +160,14 @@ module Playwright
|
|
160
160
|
raise NotImplementedError.new('web_views is not implemented yet.')
|
161
161
|
end
|
162
162
|
|
163
|
-
# @nodoc
|
164
|
-
def tap_on(selector, duration: nil, timeout: nil)
|
165
|
-
wrap_impl(@impl.tap_on(unwrap_impl(selector), duration: unwrap_impl(duration), timeout: unwrap_impl(timeout)))
|
166
|
-
end
|
167
|
-
|
168
163
|
# @nodoc
|
169
164
|
def tree
|
170
165
|
wrap_impl(@impl.tree)
|
171
166
|
end
|
172
167
|
|
173
|
-
# -- inherited from EventEmitter --
|
174
168
|
# @nodoc
|
175
|
-
def
|
176
|
-
|
169
|
+
def tap_on(selector, duration: nil, timeout: nil)
|
170
|
+
wrap_impl(@impl.tap_on(unwrap_impl(selector), duration: unwrap_impl(duration), timeout: unwrap_impl(timeout)))
|
177
171
|
end
|
178
172
|
|
179
173
|
# -- inherited from EventEmitter --
|
@@ -188,6 +182,12 @@ module Playwright
|
|
188
182
|
event_emitter_proxy.off(event, callback)
|
189
183
|
end
|
190
184
|
|
185
|
+
# -- inherited from EventEmitter --
|
186
|
+
# @nodoc
|
187
|
+
def once(event, callback)
|
188
|
+
event_emitter_proxy.once(event, callback)
|
189
|
+
end
|
190
|
+
|
191
191
|
private def event_emitter_proxy
|
192
192
|
@event_emitter_proxy ||= EventEmitterProxy.new(self, @impl)
|
193
193
|
end
|
@@ -1,63 +1,18 @@
|
|
1
1
|
module Playwright
|
2
2
|
# - extends: [EventEmitter]
|
3
|
-
#
|
3
|
+
#
|
4
4
|
# A Browser is created via [`method: BrowserType.launch`]. An example of using a `Browser` to create a `Page`:
|
5
|
-
#
|
6
5
|
#
|
7
|
-
# ```js
|
8
|
-
# const { firefox } = require('playwright'); // Or 'chromium' or 'webkit'.
|
9
|
-
#
|
10
|
-
# (async () => {
|
11
|
-
# const browser = await firefox.launch();
|
12
|
-
# const page = await browser.newPage();
|
13
|
-
# await page.goto('https://example.com');
|
14
|
-
# await browser.close();
|
15
|
-
# })();
|
16
|
-
# ```
|
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
|
-
#
|
34
|
-
# ```python async
|
35
|
-
# import asyncio
|
36
|
-
# from playwright.async_api import async_playwright
|
37
|
-
#
|
38
|
-
# async def run(playwright):
|
39
|
-
# firefox = playwright.firefox
|
40
|
-
# browser = await firefox.launch()
|
41
|
-
# page = await browser.new_page()
|
42
|
-
# await page.goto("https://example.com")
|
43
|
-
# await browser.close()
|
44
|
-
#
|
45
|
-
# async def main():
|
46
|
-
# async with async_playwright() as playwright:
|
47
|
-
# await run(playwright)
|
48
|
-
# asyncio.run(main())
|
49
|
-
# ```
|
50
|
-
#
|
51
6
|
# ```python sync
|
52
7
|
# from playwright.sync_api import sync_playwright
|
53
|
-
#
|
8
|
+
#
|
54
9
|
# def run(playwright):
|
55
10
|
# firefox = playwright.firefox
|
56
11
|
# browser = firefox.launch()
|
57
12
|
# page = browser.new_page()
|
58
13
|
# page.goto("https://example.com")
|
59
14
|
# browser.close()
|
60
|
-
#
|
15
|
+
#
|
61
16
|
# with sync_playwright() as playwright:
|
62
17
|
# run(playwright)
|
63
18
|
# ```
|
@@ -65,40 +20,17 @@ module Playwright
|
|
65
20
|
|
66
21
|
# In case this browser is obtained using [`method: BrowserType.launch`], closes the browser and all of its pages (if any
|
67
22
|
# were opened).
|
68
|
-
#
|
23
|
+
#
|
69
24
|
# In case this browser is connected to, clears all created contexts belonging to this browser and disconnects from the
|
70
25
|
# browser server.
|
71
|
-
#
|
26
|
+
#
|
72
27
|
# The `Browser` object itself is considered to be disposed and cannot be used anymore.
|
73
28
|
def close
|
74
29
|
wrap_impl(@impl.close)
|
75
30
|
end
|
76
31
|
|
77
32
|
# Returns an array of all open browser contexts. In a newly created browser, this will return zero browser contexts.
|
78
|
-
#
|
79
33
|
#
|
80
|
-
# ```js
|
81
|
-
# const browser = await pw.webkit.launch();
|
82
|
-
# console.log(browser.contexts().length); // prints `0`
|
83
|
-
#
|
84
|
-
# const context = await browser.newContext();
|
85
|
-
# console.log(browser.contexts().length); // prints `1`
|
86
|
-
# ```
|
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
|
-
#
|
95
|
-
# ```python async
|
96
|
-
# browser = await pw.webkit.launch()
|
97
|
-
# print(len(browser.contexts())) # prints `0`
|
98
|
-
# context = await browser.new_context()
|
99
|
-
# print(len(browser.contexts())) # prints `1`
|
100
|
-
# ```
|
101
|
-
#
|
102
34
|
# ```python sync
|
103
35
|
# browser = pw.webkit.launch()
|
104
36
|
# print(len(browser.contexts())) # prints `0`
|
@@ -115,44 +47,14 @@ module Playwright
|
|
115
47
|
end
|
116
48
|
|
117
49
|
# > NOTE: CDP Sessions are only supported on Chromium-based browsers.
|
118
|
-
#
|
50
|
+
#
|
119
51
|
# Returns the newly created browser session.
|
120
52
|
def new_browser_cdp_session
|
121
53
|
raise NotImplementedError.new('new_browser_cdp_session is not implemented yet.')
|
122
54
|
end
|
123
55
|
|
124
56
|
# Creates a new browser context. It won't share cookies/cache with other browser contexts.
|
125
|
-
#
|
126
57
|
#
|
127
|
-
# ```js
|
128
|
-
# (async () => {
|
129
|
-
# const browser = await playwright.firefox.launch(); // Or 'chromium' or 'webkit'.
|
130
|
-
# // Create a new incognito browser context.
|
131
|
-
# const context = await browser.newContext();
|
132
|
-
# // Create a new page in a pristine context.
|
133
|
-
# const page = await context.newPage();
|
134
|
-
# await page.goto('https://example.com');
|
135
|
-
# })();
|
136
|
-
# ```
|
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
|
-
#
|
147
|
-
# ```python async
|
148
|
-
# browser = await playwright.firefox.launch() # or "chromium" or "webkit".
|
149
|
-
# # create a new incognito browser context.
|
150
|
-
# context = await browser.new_context()
|
151
|
-
# # create a new page in a pristine context.
|
152
|
-
# page = await context.new_page()
|
153
|
-
# await page.goto("https://example.com")
|
154
|
-
# ```
|
155
|
-
#
|
156
58
|
# ```python sync
|
157
59
|
# browser = playwright.firefox.launch() # or "chromium" or "webkit".
|
158
60
|
# # create a new incognito browser context.
|
@@ -192,7 +94,7 @@ module Playwright
|
|
192
94
|
end
|
193
95
|
|
194
96
|
# Creates a new page in a new browser context. Closing this page will close the context as well.
|
195
|
-
#
|
97
|
+
#
|
196
98
|
# This is a convenience API that should only be used for the single-page scenarios and short snippets. Production code and
|
197
99
|
# testing frameworks should explicitly create [`method: Browser.newContext`] followed by the
|
198
100
|
# [`method: BrowserContext.newPage`] to control their exact life times.
|
@@ -226,23 +128,10 @@ module Playwright
|
|
226
128
|
end
|
227
129
|
|
228
130
|
# > NOTE: Tracing is only supported on Chromium-based browsers.
|
229
|
-
#
|
131
|
+
#
|
230
132
|
# You can use [`method: Browser.startTracing`] and [`method: Browser.stopTracing`] to create a trace file that can be
|
231
133
|
# opened in Chrome DevTools performance panel.
|
232
|
-
#
|
233
134
|
#
|
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
135
|
# ```python sync
|
247
136
|
# browser.start_tracing(page, path="trace.json")
|
248
137
|
# page.goto("https://www.google.com")
|
@@ -253,7 +142,7 @@ module Playwright
|
|
253
142
|
end
|
254
143
|
|
255
144
|
# > NOTE: Tracing is only supported on Chromium-based browsers.
|
256
|
-
#
|
145
|
+
#
|
257
146
|
# Returns the buffer with trace data.
|
258
147
|
def stop_tracing
|
259
148
|
wrap_impl(@impl.stop_tracing)
|
@@ -264,12 +153,6 @@ module Playwright
|
|
264
153
|
wrap_impl(@impl.version)
|
265
154
|
end
|
266
155
|
|
267
|
-
# -- inherited from EventEmitter --
|
268
|
-
# @nodoc
|
269
|
-
def once(event, callback)
|
270
|
-
event_emitter_proxy.once(event, callback)
|
271
|
-
end
|
272
|
-
|
273
156
|
# -- inherited from EventEmitter --
|
274
157
|
# @nodoc
|
275
158
|
def on(event, callback)
|
@@ -282,6 +165,12 @@ module Playwright
|
|
282
165
|
event_emitter_proxy.off(event, callback)
|
283
166
|
end
|
284
167
|
|
168
|
+
# -- inherited from EventEmitter --
|
169
|
+
# @nodoc
|
170
|
+
def once(event, callback)
|
171
|
+
event_emitter_proxy.once(event, callback)
|
172
|
+
end
|
173
|
+
|
285
174
|
private def event_emitter_proxy
|
286
175
|
@event_emitter_proxy ||= EventEmitterProxy.new(self, @impl)
|
287
176
|
end
|
@@ -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,118 +153,23 @@ 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
|
-
#
|
160
|
+
#
|
362
161
|
# An example of adding an `md5` function to all pages in the context:
|
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
|
-
#
|
162
|
+
#
|
459
163
|
# ```python sync
|
460
164
|
# import hashlib
|
461
165
|
# from playwright.sync_api import sync_playwright
|
462
|
-
#
|
166
|
+
#
|
463
167
|
# def sha1(text):
|
464
168
|
# m = hashlib.sha1()
|
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)
|
@@ -483,7 +187,7 @@ module Playwright
|
|
483
187
|
# <div></div>
|
484
188
|
# """)
|
485
189
|
# page.click("button")
|
486
|
-
#
|
190
|
+
#
|
487
191
|
# with sync_playwright() as playwright:
|
488
192
|
# run(playwright)
|
489
193
|
# ```
|
@@ -498,7 +202,7 @@ module Playwright
|
|
498
202
|
end
|
499
203
|
|
500
204
|
# > NOTE: CDP sessions are only supported on Chromium-based browsers.
|
501
|
-
#
|
205
|
+
#
|
502
206
|
# Returns the newly created session.
|
503
207
|
def new_cdp_session(page)
|
504
208
|
raise NotImplementedError.new('new_cdp_session is not implemented yet.')
|
@@ -516,34 +220,9 @@ module Playwright
|
|
516
220
|
|
517
221
|
# Routing provides the capability to modify network requests that are made by any page in the browser context. Once route
|
518
222
|
# is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted.
|
519
|
-
#
|
223
|
+
#
|
520
224
|
# 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
|
-
#
|
225
|
+
#
|
547
226
|
# ```python sync
|
548
227
|
# context = browser.new_context()
|
549
228
|
# page = context.new_page()
|
@@ -551,35 +230,9 @@ module Playwright
|
|
551
230
|
# page.goto("https://example.com")
|
552
231
|
# browser.close()
|
553
232
|
# ```
|
554
|
-
#
|
233
|
+
#
|
555
234
|
# 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
|
-
#
|
235
|
+
#
|
583
236
|
# ```python sync
|
584
237
|
# context = browser.new_context()
|
585
238
|
# page = context.new_page()
|
@@ -589,19 +242,31 @@ module Playwright
|
|
589
242
|
# page.goto("https://example.com")
|
590
243
|
# browser.close()
|
591
244
|
# ```
|
592
|
-
#
|
245
|
+
#
|
246
|
+
# It is possible to examine the request to decide the route action. For example, mocking all requests that contain some
|
247
|
+
# post data, and leaving all other requests as is:
|
248
|
+
#
|
249
|
+
# ```python sync
|
250
|
+
# def handle_route(route):
|
251
|
+
# if ("my-string" in route.request.post_data)
|
252
|
+
# route.fulfill(body="mocked-data")
|
253
|
+
# else
|
254
|
+
# route.continue_()
|
255
|
+
# context.route("/api/**", handle_route)
|
256
|
+
# ```
|
257
|
+
#
|
593
258
|
# Page routes (set up with [`method: Page.route`]) take precedence over browser context routes when request matches both
|
594
259
|
# handlers.
|
595
|
-
#
|
260
|
+
#
|
596
261
|
# To remove a route with its handler you can use [`method: BrowserContext.unroute`].
|
597
|
-
#
|
262
|
+
#
|
598
263
|
# > NOTE: Enabling routing disables http cache.
|
599
264
|
def route(url, handler)
|
600
265
|
wrap_impl(@impl.route(unwrap_impl(url), unwrap_impl(handler)))
|
601
266
|
end
|
602
267
|
|
603
268
|
# > NOTE: Service workers are only supported on Chromium-based browsers.
|
604
|
-
#
|
269
|
+
#
|
605
270
|
# All existing service workers in the context.
|
606
271
|
def service_workers
|
607
272
|
raise NotImplementedError.new('service_workers is not implemented yet.')
|
@@ -614,7 +279,7 @@ module Playwright
|
|
614
279
|
# - [`method: Page.reload`]
|
615
280
|
# - [`method: Page.setContent`]
|
616
281
|
# - [`method: Page.waitForNavigation`]
|
617
|
-
#
|
282
|
+
#
|
618
283
|
# > NOTE: [`method: Page.setDefaultNavigationTimeout`] and [`method: Page.setDefaultTimeout`] take priority over
|
619
284
|
# [`method: BrowserContext.setDefaultNavigationTimeout`].
|
620
285
|
def set_default_navigation_timeout(timeout)
|
@@ -623,7 +288,7 @@ module Playwright
|
|
623
288
|
alias_method :default_navigation_timeout=, :set_default_navigation_timeout
|
624
289
|
|
625
290
|
# This setting will change the default maximum time for all the methods accepting `timeout` option.
|
626
|
-
#
|
291
|
+
#
|
627
292
|
# > NOTE: [`method: Page.setDefaultNavigationTimeout`], [`method: Page.setDefaultTimeout`] and
|
628
293
|
# [`method: BrowserContext.setDefaultNavigationTimeout`] take priority over [`method: BrowserContext.setDefaultTimeout`].
|
629
294
|
def set_default_timeout(timeout)
|
@@ -634,7 +299,7 @@ module Playwright
|
|
634
299
|
# The extra HTTP headers will be sent with every request initiated by any page in the context. These headers are merged
|
635
300
|
# with page-specific extra HTTP headers set with [`method: Page.setExtraHTTPHeaders`]. If page overrides a particular
|
636
301
|
# header, page-specific header value will be used instead of the browser context header value.
|
637
|
-
#
|
302
|
+
#
|
638
303
|
# > NOTE: [`method: BrowserContext.setExtraHTTPHeaders`] does not guarantee the order of headers in the outgoing requests.
|
639
304
|
def set_extra_http_headers(headers)
|
640
305
|
wrap_impl(@impl.set_extra_http_headers(unwrap_impl(headers)))
|
@@ -642,24 +307,11 @@ module Playwright
|
|
642
307
|
alias_method :extra_http_headers=, :set_extra_http_headers
|
643
308
|
|
644
309
|
# Sets the context's geolocation. Passing `null` or `undefined` emulates position unavailable.
|
645
|
-
#
|
646
310
|
#
|
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
311
|
# ```python sync
|
660
312
|
# browser_context.set_geolocation({"latitude": 59.95, "longitude": 30.31667})
|
661
313
|
# ```
|
662
|
-
#
|
314
|
+
#
|
663
315
|
# > NOTE: Consider using [`method: BrowserContext.grantPermissions`] to grant permissions for the browser context pages to
|
664
316
|
# read its geolocation.
|
665
317
|
def set_geolocation(geolocation)
|
@@ -685,25 +337,7 @@ module Playwright
|
|
685
337
|
|
686
338
|
# Waits for event to fire and passes its value into the predicate function. Returns when the predicate returns truthy
|
687
339
|
# value. Will throw an error if the context closes before the event is fired. Returns the event data value.
|
688
|
-
#
|
689
340
|
#
|
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
341
|
# ```python sync
|
708
342
|
# with context.expect_event("page") as event_info:
|
709
343
|
# page.click("button")
|
@@ -721,10 +355,10 @@ module Playwright
|
|
721
355
|
end
|
722
356
|
|
723
357
|
# > NOTE: In most cases, you should use [`method: BrowserContext.waitForEvent`].
|
724
|
-
#
|
358
|
+
#
|
725
359
|
# 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.
|
360
|
+
# waits for `predicate(event)` to return a truthy value. Will throw an error if the browser context is closed before the
|
361
|
+
# `event` is fired.
|
728
362
|
def wait_for_event(event, predicate: nil, timeout: nil)
|
729
363
|
raise NotImplementedError.new('wait_for_event is not implemented yet.')
|
730
364
|
end
|
@@ -749,12 +383,6 @@ module Playwright
|
|
749
383
|
wrap_impl(@impl.pause)
|
750
384
|
end
|
751
385
|
|
752
|
-
# -- inherited from EventEmitter --
|
753
|
-
# @nodoc
|
754
|
-
def once(event, callback)
|
755
|
-
event_emitter_proxy.once(event, callback)
|
756
|
-
end
|
757
|
-
|
758
386
|
# -- inherited from EventEmitter --
|
759
387
|
# @nodoc
|
760
388
|
def on(event, callback)
|
@@ -767,6 +395,12 @@ module Playwright
|
|
767
395
|
event_emitter_proxy.off(event, callback)
|
768
396
|
end
|
769
397
|
|
398
|
+
# -- inherited from EventEmitter --
|
399
|
+
# @nodoc
|
400
|
+
def once(event, callback)
|
401
|
+
event_emitter_proxy.once(event, callback)
|
402
|
+
end
|
403
|
+
|
770
404
|
private def event_emitter_proxy
|
771
405
|
@event_emitter_proxy ||= EventEmitterProxy.new(self, @impl)
|
772
406
|
end
|