playwright-ruby-client 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -15
- data/lib/playwright/channel_owners/browser.rb +2 -2
- data/lib/playwright/channel_owners/console_message.rb +25 -0
- data/lib/playwright/channel_owners/element_handle.rb +8 -0
- data/lib/playwright/channel_owners/js_handle.rb +4 -0
- data/lib/playwright/channel_owners/page.rb +14 -1
- data/lib/playwright/version.rb +1 -1
- data/lib/playwright_api/accessibility.rb +20 -6
- data/lib/playwright_api/browser.rb +52 -39
- data/lib/playwright_api/browser_context.rb +94 -44
- data/lib/playwright_api/browser_type.rb +72 -53
- data/lib/playwright_api/cdp_session.rb +10 -7
- data/lib/playwright_api/chromium_browser_context.rb +3 -0
- data/lib/playwright_api/console_message.rb +12 -5
- data/lib/playwright_api/dialog.rb +3 -1
- data/lib/playwright_api/download.rb +13 -4
- data/lib/playwright_api/element_handle.rb +226 -113
- data/lib/playwright_api/file_chooser.rb +4 -2
- data/lib/playwright_api/frame.rb +276 -128
- data/lib/playwright_api/js_handle.rb +30 -10
- data/lib/playwright_api/keyboard.rb +56 -18
- data/lib/playwright_api/mouse.rb +6 -3
- data/lib/playwright_api/page.rb +452 -237
- data/lib/playwright_api/playwright.rb +80 -16
- data/lib/playwright_api/request.rb +35 -15
- data/lib/playwright_api/response.rb +4 -3
- data/lib/playwright_api/route.rb +15 -4
- data/lib/playwright_api/selectors.rb +3 -7
- data/lib/playwright_api/touchscreen.rb +2 -1
- data/lib/playwright_api/video.rb +3 -1
- data/lib/playwright_api/web_socket.rb +4 -2
- data/lib/playwright_api/worker.rb +17 -5
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b77f5e67e8a75aec27eca18c85bcaaf3236fcc0822659de3462a7f4d41d3a1a8
|
4
|
+
data.tar.gz: 7791bc627ddcd7fc39fa36b7ec6f393c855d0cb506b5834922b43f84839dac63
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ffbf8ebba62b54b51534b5f33f45dd02df9f73824b267500b9265827bb09b01898849fb43c461a2798c276801ae69a6beb52018872c4d7740ba56ff8ab99686
|
7
|
+
data.tar.gz: 8b7acc19dd31389c0ea3361a8be430177d2319ec20284ffac65117a9421810b26808c1ab61bc33298e8bfd89c617772750f7c61b21258aebebd6db7d93598923
|
data/README.md
CHANGED
@@ -4,17 +4,20 @@
|
|
4
4
|
|
5
5
|
A Ruby client for Playwright driver.
|
6
6
|
|
7
|
+
Note: Currently, this Gem is just a PoC (Proof of Concept). If you want to develop browser-automation for Chrome with Ruby, consider using [puppeteer-ruby](https://github.com/YusukeIwaki/puppeteer-ruby)
|
8
|
+
|
7
9
|
## Getting Started
|
8
10
|
|
9
11
|
At this point, playwright-ruby-client doesn't include the downloader of playwright-cli, so **we have to install [playwright-cli](https://github.com/microsoft/playwright-cli) in advance**.
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
|
13
|
+
```sh
|
14
|
+
npm install playwright-cli
|
15
|
+
./node_modules/.bin/playwright-cli install
|
16
|
+
```
|
14
17
|
|
15
|
-
|
18
|
+
and then, set `playwright_cli_executable_path: ./node_modules/.bin/playwright-cli` at `Playwright.create`.
|
16
19
|
|
17
|
-
|
20
|
+
Instead of npm install, you can also directly download playwright driver from playwright.azureedge.net/builds/. The URL can be easily detected from [here](https://github.com/microsoft/playwright-python/blob/79f6ce0a6a69c480573372706df84af5ef99c4a4/setup.py#L56-L61)
|
18
21
|
|
19
22
|
### Capture a site
|
20
23
|
|
@@ -30,16 +33,6 @@ Playwright.create(playwright_cli_executable_path: '/path/to/playwright-cli') do
|
|
30
33
|
end
|
31
34
|
```
|
32
35
|
|
33
|
-
## Development
|
34
|
-
|
35
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
36
|
-
|
37
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
38
|
-
|
39
|
-
## Contributing
|
40
|
-
|
41
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/playwright-ruby-client. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
42
|
-
|
43
36
|
## License
|
44
37
|
|
45
38
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Playwright
|
2
|
+
define_channel_owner :ConsoleMessage do
|
3
|
+
def to_s
|
4
|
+
@initializer['text']
|
5
|
+
end
|
6
|
+
|
7
|
+
def type
|
8
|
+
@initializer['type']
|
9
|
+
end
|
10
|
+
|
11
|
+
def text
|
12
|
+
@initializer['text']
|
13
|
+
end
|
14
|
+
|
15
|
+
def args
|
16
|
+
@initializer['args']&.map do |arg|
|
17
|
+
ChannelOwner.from(arg)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def location
|
22
|
+
@initialize['location']
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -11,18 +11,31 @@ module Playwright
|
|
11
11
|
@mouse = Mouse.new(@channel)
|
12
12
|
@touchscreen = Touchscreen.new(@channel)
|
13
13
|
|
14
|
+
@viewport_size = @initializer['viewportSize']
|
14
15
|
@main_frame = ChannelOwners::Frame.from(@initializer['mainFrame'])
|
15
16
|
@main_frame.send(:update_page_from_page, self)
|
16
17
|
@frames = Set.new
|
17
18
|
@frames << @main_frame
|
18
19
|
end
|
19
20
|
|
20
|
-
attr_reader
|
21
|
+
attr_reader \
|
22
|
+
:accessibility,
|
23
|
+
:keyboard,
|
24
|
+
:mouse,
|
25
|
+
:touchscreen,
|
26
|
+
:viewport_size,
|
27
|
+
:main_frame
|
21
28
|
|
22
29
|
def goto(url, timeout: nil, waitUntil: nil, referer: nil)
|
23
30
|
@main_frame.goto(url, timeout: timeout, waitUntil: waitUntil, referer: referer)
|
24
31
|
end
|
25
32
|
|
33
|
+
def set_viewport_size(viewportSize)
|
34
|
+
@viewport_size = viewportSize
|
35
|
+
@channel.send_message_to_server('setViewportSize', { viewportSize: viewportSize })
|
36
|
+
nil
|
37
|
+
end
|
38
|
+
|
26
39
|
def screenshot(
|
27
40
|
path: nil,
|
28
41
|
type: nil,
|
data/lib/playwright/version.rb
CHANGED
@@ -1,21 +1,35 @@
|
|
1
1
|
module Playwright
|
2
|
-
# The Accessibility class provides methods for inspecting Chromium's accessibility tree. The accessibility tree is used by
|
3
|
-
#
|
4
|
-
#
|
5
|
-
#
|
2
|
+
# The Accessibility class provides methods for inspecting Chromium's accessibility tree. The accessibility tree is used by
|
3
|
+
# assistive technology such as [screen readers](https://en.wikipedia.org/wiki/Screen_reader) or
|
4
|
+
# [switches](https://en.wikipedia.org/wiki/Switch_access).
|
5
|
+
#
|
6
|
+
# Accessibility is a very platform-specific thing. On different platforms, there are different screen readers that might
|
7
|
+
# have wildly different output.
|
8
|
+
#
|
9
|
+
# Blink - Chromium's rendering engine - has a concept of "accessibility tree", which is then translated into different
|
10
|
+
# platform-specific APIs. Accessibility namespace gives users access to the Blink Accessibility Tree.
|
11
|
+
#
|
12
|
+
# Most of the accessibility tree gets filtered out when converting from Blink AX Tree to Platform-specific AX-Tree or by
|
13
|
+
# assistive technologies themselves. By default, Playwright tries to approximate this filtering, exposing only the
|
14
|
+
# "interesting" nodes of the tree.
|
6
15
|
class Accessibility < PlaywrightApi
|
7
16
|
|
8
|
-
# Captures the current state of the accessibility tree. The returned object represents the root accessible node of the
|
17
|
+
# Captures the current state of the accessibility tree. The returned object represents the root accessible node of the
|
18
|
+
# page.
|
9
19
|
#
|
10
|
-
# **NOTE** The Chromium accessibility tree contains nodes that go unused on most platforms and by most screen readers.
|
20
|
+
# > **NOTE** The Chromium accessibility tree contains nodes that go unused on most platforms and by most screen readers.
|
21
|
+
# Playwright will discard them as well for an easier to process tree, unless `interestingOnly` is set to `false`.
|
11
22
|
#
|
12
23
|
# An example of dumping the entire accessibility tree:
|
24
|
+
#
|
13
25
|
#
|
14
26
|
# ```js
|
15
27
|
# const snapshot = await page.accessibility.snapshot();
|
16
28
|
# console.log(snapshot);
|
17
29
|
# ```
|
30
|
+
#
|
18
31
|
# An example of logging the focused node's name:
|
32
|
+
#
|
19
33
|
#
|
20
34
|
# ```js
|
21
35
|
# const snapshot = await page.accessibility.snapshot();
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module Playwright
|
2
|
-
#
|
3
|
-
#
|
2
|
+
# - extends: [EventEmitter](https://nodejs.org/api/events.html#events_class_eventemitter)
|
3
|
+
#
|
4
|
+
# A Browser is created via [`method: BrowserType.launch`]. An example of using a `Browser` to create a [Page]:
|
5
|
+
#
|
4
6
|
#
|
5
7
|
# ```js
|
6
8
|
# const { firefox } = require('playwright'); // Or 'chromium' or 'webkit'.
|
@@ -12,17 +14,24 @@ module Playwright
|
|
12
14
|
# await browser.close();
|
13
15
|
# })();
|
14
16
|
# ```
|
15
|
-
#
|
17
|
+
#
|
18
|
+
# See `ChromiumBrowser`, [FirefoxBrowser] and [WebKitBrowser] for browser-specific features. Note that
|
19
|
+
# [`method: BrowserType.launch`] always returns a specific browser instance, based on the browser being launched.
|
16
20
|
class Browser < PlaywrightApi
|
17
21
|
|
18
|
-
# In case this browser is obtained using `
|
19
|
-
#
|
20
|
-
#
|
22
|
+
# In case this browser is obtained using [`method: BrowserType.launch`], closes the browser and all of its pages (if any
|
23
|
+
# were opened).
|
24
|
+
#
|
25
|
+
# In case this browser is connected to, clears all created contexts belonging to this browser and disconnects from the
|
26
|
+
# browser server.
|
27
|
+
#
|
28
|
+
# The `Browser` object itself is considered to be disposed and cannot be used anymore.
|
21
29
|
def close
|
22
30
|
wrap_channel_owner(@channel_owner.close)
|
23
31
|
end
|
24
32
|
|
25
33
|
# Returns an array of all open browser contexts. In a newly created browser, this will return zero browser contexts.
|
34
|
+
#
|
26
35
|
#
|
27
36
|
# ```js
|
28
37
|
# const browser = await pw.webkit.launch();
|
@@ -41,6 +50,7 @@ module Playwright
|
|
41
50
|
end
|
42
51
|
|
43
52
|
# Creates a new browser context. It won't share cookies/cache with other browser contexts.
|
53
|
+
#
|
44
54
|
#
|
45
55
|
# ```js
|
46
56
|
# (async () => {
|
@@ -54,60 +64,63 @@ module Playwright
|
|
54
64
|
# ```
|
55
65
|
def new_context(
|
56
66
|
acceptDownloads: nil,
|
57
|
-
ignoreHTTPSErrors: nil,
|
58
67
|
bypassCSP: nil,
|
59
|
-
|
60
|
-
userAgent: nil,
|
68
|
+
colorScheme: nil,
|
61
69
|
deviceScaleFactor: nil,
|
62
|
-
|
70
|
+
extraHTTPHeaders: nil,
|
71
|
+
geolocation: nil,
|
63
72
|
hasTouch: nil,
|
73
|
+
httpCredentials: nil,
|
74
|
+
ignoreHTTPSErrors: nil,
|
75
|
+
isMobile: nil,
|
64
76
|
javaScriptEnabled: nil,
|
65
|
-
timezoneId: nil,
|
66
|
-
geolocation: nil,
|
67
77
|
locale: nil,
|
68
|
-
permissions: nil,
|
69
|
-
extraHTTPHeaders: nil,
|
70
|
-
offline: nil,
|
71
|
-
httpCredentials: nil,
|
72
|
-
colorScheme: nil,
|
73
78
|
logger: nil,
|
74
|
-
|
75
|
-
|
79
|
+
offline: nil,
|
80
|
+
permissions: nil,
|
81
|
+
proxy: nil,
|
76
82
|
recordHar: nil,
|
77
83
|
recordVideo: nil,
|
78
|
-
|
79
|
-
|
80
|
-
|
84
|
+
storageState: nil,
|
85
|
+
timezoneId: nil,
|
86
|
+
userAgent: nil,
|
87
|
+
videoSize: nil,
|
88
|
+
videosPath: nil,
|
89
|
+
viewport: nil)
|
90
|
+
wrap_channel_owner(@channel_owner.new_context(acceptDownloads: acceptDownloads, bypassCSP: bypassCSP, colorScheme: colorScheme, deviceScaleFactor: deviceScaleFactor, extraHTTPHeaders: extraHTTPHeaders, geolocation: geolocation, hasTouch: hasTouch, httpCredentials: httpCredentials, ignoreHTTPSErrors: ignoreHTTPSErrors, isMobile: isMobile, javaScriptEnabled: javaScriptEnabled, locale: locale, logger: logger, offline: offline, permissions: permissions, proxy: proxy, recordHar: recordHar, recordVideo: recordVideo, storageState: storageState, timezoneId: timezoneId, userAgent: userAgent, videoSize: videoSize, videosPath: videosPath, viewport: viewport))
|
81
91
|
end
|
82
92
|
|
83
93
|
# Creates a new page in a new browser context. Closing this page will close the context as well.
|
84
|
-
#
|
94
|
+
#
|
95
|
+
# This is a convenience API that should only be used for the single-page scenarios and short snippets. Production code and
|
96
|
+
# testing frameworks should explicitly create [`method: Browser.newContext`] followed by the
|
97
|
+
# [`method: BrowserContext.newPage`] to control their exact life times.
|
85
98
|
def new_page(
|
86
99
|
acceptDownloads: nil,
|
87
|
-
ignoreHTTPSErrors: nil,
|
88
100
|
bypassCSP: nil,
|
89
|
-
|
90
|
-
userAgent: nil,
|
101
|
+
colorScheme: nil,
|
91
102
|
deviceScaleFactor: nil,
|
92
|
-
|
103
|
+
extraHTTPHeaders: nil,
|
104
|
+
geolocation: nil,
|
93
105
|
hasTouch: nil,
|
106
|
+
httpCredentials: nil,
|
107
|
+
ignoreHTTPSErrors: nil,
|
108
|
+
isMobile: nil,
|
94
109
|
javaScriptEnabled: nil,
|
95
|
-
timezoneId: nil,
|
96
|
-
geolocation: nil,
|
97
110
|
locale: nil,
|
98
|
-
permissions: nil,
|
99
|
-
extraHTTPHeaders: nil,
|
100
|
-
offline: nil,
|
101
|
-
httpCredentials: nil,
|
102
|
-
colorScheme: nil,
|
103
111
|
logger: nil,
|
104
|
-
|
105
|
-
|
112
|
+
offline: nil,
|
113
|
+
permissions: nil,
|
114
|
+
proxy: nil,
|
106
115
|
recordHar: nil,
|
107
116
|
recordVideo: nil,
|
108
|
-
|
109
|
-
|
110
|
-
|
117
|
+
storageState: nil,
|
118
|
+
timezoneId: nil,
|
119
|
+
userAgent: nil,
|
120
|
+
videoSize: nil,
|
121
|
+
videosPath: nil,
|
122
|
+
viewport: nil)
|
123
|
+
wrap_channel_owner(@channel_owner.new_page(acceptDownloads: acceptDownloads, bypassCSP: bypassCSP, colorScheme: colorScheme, deviceScaleFactor: deviceScaleFactor, extraHTTPHeaders: extraHTTPHeaders, geolocation: geolocation, hasTouch: hasTouch, httpCredentials: httpCredentials, ignoreHTTPSErrors: ignoreHTTPSErrors, isMobile: isMobile, javaScriptEnabled: javaScriptEnabled, locale: locale, logger: logger, offline: offline, permissions: permissions, proxy: proxy, recordHar: recordHar, recordVideo: recordVideo, storageState: storageState, timezoneId: timezoneId, userAgent: userAgent, videoSize: videoSize, videosPath: videosPath, viewport: viewport))
|
111
124
|
end
|
112
125
|
|
113
126
|
# Returns the browser version.
|
@@ -1,7 +1,14 @@
|
|
1
1
|
module Playwright
|
2
|
+
# - extends: [EventEmitter](https://nodejs.org/api/events.html#events_class_eventemitter)
|
3
|
+
#
|
2
4
|
# BrowserContexts provide a way to operate multiple independent browser sessions.
|
3
|
-
#
|
4
|
-
#
|
5
|
+
#
|
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
|
+
# context.
|
8
|
+
#
|
9
|
+
# Playwright allows creation of "incognito" browser contexts with `browser.newContext()` method. "Incognito" browser
|
10
|
+
# contexts don't write any browsing data to disk.
|
11
|
+
#
|
5
12
|
#
|
6
13
|
# ```js
|
7
14
|
# // Create a new incognito browser context
|
@@ -14,7 +21,9 @@ module Playwright
|
|
14
21
|
# ```
|
15
22
|
class BrowserContext < PlaywrightApi
|
16
23
|
|
17
|
-
# Adds cookies into this browser context. All pages within this context will have these cookies installed. Cookies can be
|
24
|
+
# Adds cookies into this browser context. All pages within this context will have these cookies installed. Cookies can be
|
25
|
+
# obtained via [`method: BrowserContext.cookies`].
|
26
|
+
#
|
18
27
|
#
|
19
28
|
# ```js
|
20
29
|
# await browserContext.addCookies([cookieObject1, cookieObject2]);
|
@@ -24,17 +33,21 @@ module Playwright
|
|
24
33
|
end
|
25
34
|
|
26
35
|
# Adds a script which would be evaluated in one of the following scenarios:
|
36
|
+
# - Whenever a page is created in the browser context or is navigated.
|
37
|
+
# - Whenever a child frame is attached or navigated in any page in the browser context. In this case, the script is
|
38
|
+
# evaluated in the context of the newly attached frame.
|
27
39
|
#
|
28
|
-
#
|
29
|
-
#
|
40
|
+
# The script is evaluated after the document was created but before any of its scripts were run. This is useful to amend
|
41
|
+
# the JavaScript environment, e.g. to seed `Math.random`.
|
30
42
|
#
|
31
|
-
# The script is evaluated after the document was created but before any of its scripts were run. This is useful to amend the JavaScript environment, e.g. to seed `Math.random`.
|
32
43
|
# An example of overriding `Math.random` before the page loads:
|
44
|
+
#
|
33
45
|
#
|
34
46
|
# ```js
|
35
47
|
# // preload.js
|
36
48
|
# Math.random = () => 42;
|
37
49
|
# ```
|
50
|
+
#
|
38
51
|
#
|
39
52
|
# ```js
|
40
53
|
# // In your playwright script, assuming the preload.js file is in same directory.
|
@@ -43,7 +56,8 @@ module Playwright
|
|
43
56
|
# });
|
44
57
|
# ```
|
45
58
|
#
|
46
|
-
# **NOTE** The order of evaluation of multiple scripts installed via
|
59
|
+
# > **NOTE** The order of evaluation of multiple scripts installed via [`method: BrowserContext.addInitScript`] and
|
60
|
+
# [`method: Page.addInitScript`] is not defined.
|
47
61
|
def add_init_script(script, arg: nil)
|
48
62
|
raise NotImplementedError.new('add_init_script is not implemented yet.')
|
49
63
|
end
|
@@ -59,6 +73,7 @@ module Playwright
|
|
59
73
|
end
|
60
74
|
|
61
75
|
# Clears all permission overrides for the browser context.
|
76
|
+
#
|
62
77
|
#
|
63
78
|
# ```js
|
64
79
|
# const context = await browser.newContext();
|
@@ -72,20 +87,28 @@ module Playwright
|
|
72
87
|
|
73
88
|
# Closes the browser context. All the pages that belong to the browser context will be closed.
|
74
89
|
#
|
75
|
-
# **NOTE** the default browser context cannot be closed.
|
90
|
+
# > **NOTE** the default browser context cannot be closed.
|
76
91
|
def close
|
77
92
|
raise NotImplementedError.new('close is not implemented yet.')
|
78
93
|
end
|
79
94
|
|
80
|
-
# If no URLs are specified, this method returns all cookies. If URLs are specified, only cookies that affect those URLs
|
95
|
+
# If no URLs are specified, this method returns all cookies. If URLs are specified, only cookies that affect those URLs
|
96
|
+
# are returned.
|
81
97
|
def cookies(urls: nil)
|
82
98
|
raise NotImplementedError.new('cookies is not implemented yet.')
|
83
99
|
end
|
84
100
|
|
85
|
-
# The method adds a function called `name` on the `window` object of every frame in every page in the context. When
|
86
|
-
#
|
87
|
-
#
|
101
|
+
# The method adds a function called `name` on the `window` object of every frame in every page in the context. When
|
102
|
+
# called, the function executes `callback` and returns a [Promise] which resolves to the return value of `callback`. If
|
103
|
+
# the `callback` returns a [Promise], it will be awaited.
|
104
|
+
#
|
105
|
+
# The first argument of the `callback` function contains information about the caller: `{ browserContext: BrowserContext,
|
106
|
+
# page: Page, frame: Frame }`.
|
107
|
+
#
|
108
|
+
# See [`method: Page.exposeBinding`] for page-only version.
|
109
|
+
#
|
88
110
|
# An example of exposing page URL to all frames in all pages in the context:
|
111
|
+
#
|
89
112
|
#
|
90
113
|
# ```js
|
91
114
|
# const { webkit } = require('playwright'); // Or 'chromium' or 'firefox'.
|
@@ -107,7 +130,9 @@ module Playwright
|
|
107
130
|
# await page.click('button');
|
108
131
|
# })();
|
109
132
|
# ```
|
133
|
+
#
|
110
134
|
# An example of passing an element handle:
|
135
|
+
#
|
111
136
|
#
|
112
137
|
# ```js
|
113
138
|
# await context.exposeBinding('clicked', async (source, element) => {
|
@@ -121,14 +146,19 @@ module Playwright
|
|
121
146
|
# <div>Or click me</div>
|
122
147
|
# `);
|
123
148
|
# ```
|
124
|
-
def expose_binding(name,
|
149
|
+
def expose_binding(name, callback, handle: nil)
|
125
150
|
raise NotImplementedError.new('expose_binding is not implemented yet.')
|
126
151
|
end
|
127
152
|
|
128
|
-
# The method adds a function called `name` on the `window` object of every frame in every page in the context. When
|
129
|
-
#
|
130
|
-
#
|
153
|
+
# The method adds a function called `name` on the `window` object of every frame in every page in the context. When
|
154
|
+
# called, the function executes `callback` and returns a [Promise] which resolves to the return value of `callback`.
|
155
|
+
#
|
156
|
+
# If the `callback` returns a [Promise], it will be awaited.
|
157
|
+
#
|
158
|
+
# See [`method: Page.exposeFunction`] for page-only version.
|
159
|
+
#
|
131
160
|
# An example of adding an `md5` function to all pages in the context:
|
161
|
+
#
|
132
162
|
#
|
133
163
|
# ```js
|
134
164
|
# const { webkit } = require('playwright'); // Or 'chromium' or 'firefox'.
|
@@ -151,11 +181,12 @@ module Playwright
|
|
151
181
|
# await page.click('button');
|
152
182
|
# })();
|
153
183
|
# ```
|
154
|
-
def expose_function(name,
|
184
|
+
def expose_function(name, callback)
|
155
185
|
raise NotImplementedError.new('expose_function is not implemented yet.')
|
156
186
|
end
|
157
187
|
|
158
|
-
# Grants specified permissions to the browser context. Only grants corresponding permissions to the given origin if
|
188
|
+
# Grants specified permissions to the browser context. Only grants corresponding permissions to the given origin if
|
189
|
+
# specified.
|
159
190
|
def grant_permissions(permissions, origin: nil)
|
160
191
|
raise NotImplementedError.new('grant_permissions is not implemented yet.')
|
161
192
|
end
|
@@ -165,13 +196,17 @@ module Playwright
|
|
165
196
|
wrap_channel_owner(@channel_owner.new_page)
|
166
197
|
end
|
167
198
|
|
168
|
-
# Returns all open pages in the context. Non visible pages, such as `"background_page"`, will not be listed here. You can
|
199
|
+
# Returns all open pages in the context. Non visible pages, such as `"background_page"`, will not be listed here. You can
|
200
|
+
# find them using [`method: ChromiumBrowserContext.backgroundPages`].
|
169
201
|
def pages
|
170
202
|
raise NotImplementedError.new('pages is not implemented yet.')
|
171
203
|
end
|
172
204
|
|
173
|
-
# Routing provides the capability to modify network requests that are made by any page in the browser context. Once route
|
205
|
+
# Routing provides the capability to modify network requests that are made by any page in the browser context. Once route
|
206
|
+
# is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted.
|
207
|
+
#
|
174
208
|
# An example of a naïve handler that aborts all image requests:
|
209
|
+
#
|
175
210
|
#
|
176
211
|
# ```js
|
177
212
|
# const context = await browser.newContext();
|
@@ -180,7 +215,9 @@ module Playwright
|
|
180
215
|
# await page.goto('https://example.com');
|
181
216
|
# await browser.close();
|
182
217
|
# ```
|
218
|
+
#
|
183
219
|
# or the same snippet using a regex pattern instead:
|
220
|
+
#
|
184
221
|
#
|
185
222
|
# ```js
|
186
223
|
# const context = await browser.newContext();
|
@@ -189,75 +226,88 @@ module Playwright
|
|
189
226
|
# await page.goto('https://example.com');
|
190
227
|
# await browser.close();
|
191
228
|
# ```
|
192
|
-
# Page routes (set up with `page.route(url, handler)`) take precedence over browser context routes when request matches both handlers.
|
193
229
|
#
|
194
|
-
#
|
230
|
+
# Page routes (set up with [`method: Page.route`]) take precedence over browser context routes when request matches both
|
231
|
+
# handlers.
|
232
|
+
#
|
233
|
+
# > **NOTE** Enabling routing disables http cache.
|
195
234
|
def route(url, handler)
|
196
235
|
raise NotImplementedError.new('route is not implemented yet.')
|
197
236
|
end
|
198
237
|
|
199
238
|
# This setting will change the default maximum navigation time for the following methods and related shortcuts:
|
239
|
+
# - [`method: Page.goBack`]
|
240
|
+
# - [`method: Page.goForward`]
|
241
|
+
# - [`method: Page.goto`]
|
242
|
+
# - [`method: Page.reload`]
|
243
|
+
# - [`method: Page.setContent`]
|
244
|
+
# - [`method: Page.waitForNavigation`]
|
200
245
|
#
|
201
|
-
# `
|
202
|
-
# `
|
203
|
-
# `page.goto(url[, options])`
|
204
|
-
# `page.reload([options])`
|
205
|
-
# `page.setContent(html[, options])`
|
206
|
-
# `page.waitForNavigation([options])`
|
207
|
-
#
|
208
|
-
#
|
209
|
-
# **NOTE** `page.setDefaultNavigationTimeout(timeout)` and `page.setDefaultTimeout(timeout)` take priority over `browserContext.setDefaultNavigationTimeout(timeout)`.
|
246
|
+
# > **NOTE** [`method: Page.setDefaultNavigationTimeout`] and [`method: Page.setDefaultTimeout`] take priority over
|
247
|
+
# [`method: BrowserContext.setDefaultNavigationTimeout`].
|
210
248
|
def set_default_navigation_timeout(timeout)
|
211
249
|
raise NotImplementedError.new('set_default_navigation_timeout is not implemented yet.')
|
212
250
|
end
|
251
|
+
alias_method :default_navigation_timeout=, :set_default_navigation_timeout
|
213
252
|
|
214
253
|
# This setting will change the default maximum time for all the methods accepting `timeout` option.
|
215
254
|
#
|
216
|
-
# **NOTE** `
|
255
|
+
# > **NOTE** [`method: Page.setDefaultNavigationTimeout`], [`method: Page.setDefaultTimeout`] and
|
256
|
+
# [`method: BrowserContext.setDefaultNavigationTimeout`] take priority over [`method: BrowserContext.setDefaultTimeout`].
|
217
257
|
def set_default_timeout(timeout)
|
218
258
|
raise NotImplementedError.new('set_default_timeout is not implemented yet.')
|
219
259
|
end
|
260
|
+
alias_method :default_timeout=, :set_default_timeout
|
220
261
|
|
221
|
-
# The extra HTTP headers will be sent with every request initiated by any page in the context. These headers are merged
|
262
|
+
# The extra HTTP headers will be sent with every request initiated by any page in the context. These headers are merged
|
263
|
+
# with page-specific extra HTTP headers set with [`method: Page.setExtraHTTPHeaders`]. If page overrides a particular
|
264
|
+
# header, page-specific header value will be used instead of the browser context header value.
|
222
265
|
#
|
223
|
-
# **NOTE** `browserContext.setExtraHTTPHeaders` does not guarantee the order of headers in the outgoing requests.
|
266
|
+
# > **NOTE** `browserContext.setExtraHTTPHeaders` does not guarantee the order of headers in the outgoing requests.
|
224
267
|
def set_extra_http_headers(headers)
|
225
268
|
raise NotImplementedError.new('set_extra_http_headers is not implemented yet.')
|
226
269
|
end
|
270
|
+
alias_method :extra_http_headers=, :set_extra_http_headers
|
227
271
|
|
228
272
|
# Sets the context's geolocation. Passing `null` or `undefined` emulates position unavailable.
|
273
|
+
#
|
229
274
|
#
|
230
275
|
# ```js
|
231
276
|
# await browserContext.setGeolocation({latitude: 59.95, longitude: 30.31667});
|
232
277
|
# ```
|
233
278
|
#
|
234
|
-
# **NOTE** Consider using `
|
279
|
+
# > **NOTE** Consider using [`method: BrowserContext.grantPermissions`] to grant permissions for the browser context pages
|
280
|
+
# to read its geolocation.
|
235
281
|
def set_geolocation(geolocation)
|
236
282
|
raise NotImplementedError.new('set_geolocation is not implemented yet.')
|
237
283
|
end
|
284
|
+
alias_method :geolocation=, :set_geolocation
|
238
285
|
|
239
|
-
#
|
240
|
-
#
|
241
|
-
# **NOTE** Browsers may cache credentials after successful authentication. Passing different credentials or passing `null` to disable authentication will be unreliable. To remove or replace credentials, create a new browser context instead.
|
286
|
+
# **DEPRECATED** Browsers may cache credentials after successful authentication. Create a new browser context instead.
|
242
287
|
def set_http_credentials(httpCredentials)
|
243
288
|
raise NotImplementedError.new('set_http_credentials is not implemented yet.')
|
244
289
|
end
|
290
|
+
alias_method :http_credentials=, :set_http_credentials
|
245
291
|
|
246
292
|
def set_offline(offline)
|
247
293
|
raise NotImplementedError.new('set_offline is not implemented yet.')
|
248
294
|
end
|
295
|
+
alias_method :offline=, :set_offline
|
249
296
|
|
250
297
|
# Returns storage state for this browser context, contains current cookies and local storage snapshot.
|
251
298
|
def storage_state(path: nil)
|
252
299
|
raise NotImplementedError.new('storage_state is not implemented yet.')
|
253
300
|
end
|
254
301
|
|
255
|
-
# Removes a route created with `
|
302
|
+
# Removes a route created with [`method: BrowserContext.route`]. When `handler` is not specified, removes all routes for
|
303
|
+
# the `url`.
|
256
304
|
def unroute(url, handler: nil)
|
257
305
|
raise NotImplementedError.new('unroute is not implemented yet.')
|
258
306
|
end
|
259
307
|
|
260
|
-
# Waits for event to fire and passes its value into the predicate function. Returns when the predicate returns truthy
|
308
|
+
# Waits for event to fire and passes its value into the predicate function. Returns when the predicate returns truthy
|
309
|
+
# value. Will throw an error if the context closes before the event is fired. Returns the event data value.
|
310
|
+
#
|
261
311
|
#
|
262
312
|
# ```js
|
263
313
|
# const context = await browser.newContext();
|
@@ -268,13 +318,13 @@ module Playwright
|
|
268
318
|
end
|
269
319
|
|
270
320
|
# @nodoc
|
271
|
-
def
|
272
|
-
wrap_channel_owner(@channel_owner.
|
321
|
+
def owner_page=(req)
|
322
|
+
wrap_channel_owner(@channel_owner.owner_page=(req))
|
273
323
|
end
|
274
324
|
|
275
325
|
# @nodoc
|
276
|
-
def
|
277
|
-
wrap_channel_owner(@channel_owner.
|
326
|
+
def browser=(req)
|
327
|
+
wrap_channel_owner(@channel_owner.browser=(req))
|
278
328
|
end
|
279
329
|
|
280
330
|
# @nodoc
|