playwright-ruby-client 1.54.0 → 1.54.1
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/documentation/docs/article/guides/inspector.md +1 -1
- data/documentation/docs/article/guides/playwright_on_alpine_linux.md +9 -69
- data/lib/playwright/channel_owners/browser_type.rb +0 -4
- data/lib/playwright/version.rb +1 -1
- data/lib/playwright/web_socket_client.rb +4 -1
- data/lib/playwright/web_socket_transport.rb +3 -1
- data/lib/playwright.rb +14 -14
- data/lib/playwright_api/frame.rb +5 -5
- data/lib/playwright_api/playwright.rb +4 -4
- data/lib/playwright_api/response.rb +4 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 292b93df8ac7c9ea103673f017935907d53ea53a6e84b66d13723cb41c6c7fd9
|
4
|
+
data.tar.gz: b1d0d3325715881e7ae2ffc9fe04f32e8379189de794a498a041e36d1594ecaf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4bd08ce76baa61e7dc6b3aa724f20cc3d05ff576ab1b42cc93fed1c0a38c3fb205f8fd90530c95dd5349bcd650688104a34d1e79023b40fd1241d6b8c6f8c5d1
|
7
|
+
data.tar.gz: 63d9a00c126ed1fee420e530173b30970f7854522adc15f00e52aaa4049015b2461bd5512210e966ab0178ef18af19ce63de648a3bef88b668ff0cc39330680d
|
@@ -15,7 +15,7 @@ playwright.chromium.launch(headless: false) do |browser|
|
|
15
15
|
# This method call should be put just after creating BrowserContext.
|
16
16
|
context.enable_debug_console!
|
17
17
|
|
18
|
-
page = context.
|
18
|
+
page = context.new_page
|
19
19
|
page.goto('http://example.com/')
|
20
20
|
page.pause
|
21
21
|
end
|
@@ -25,6 +25,8 @@ However we may have trouble with bringing Playwright into:
|
|
25
25
|
|
26
26
|
This article introduces a way to separate environments into client (for executing Playwright script) and server (for working with browsers). The main use-case assumes Docker (using Alpine Linux), however the way can be applied also into other use-cases.
|
27
27
|
|
28
|
+
ref: https://playwright.dev/docs/docker#remote-connection
|
29
|
+
|
28
30
|
## Overview
|
29
31
|
|
30
32
|
Playwright Ruby client is running on Alpine Linux. It just sends/receives JSON messages of Playwright-protocol via WebSocket.
|
@@ -33,48 +35,25 @@ Playwright server is running on a container of [official Docker image](https://h
|
|
33
35
|
|
34
36
|

|
35
37
|
|
36
|
-
|
37
|
-
|
38
|
-
Playwright provides two kind of methods to share the browser environments for clients.
|
39
|
-
|
40
|
-
When you want to share only one browser environment, Browser server is suitable. This feature is officially supported in Playwright.
|
41
|
-
|
42
|
-
- Server can be launched with [BrowserType#launchServer](https://playwright.dev/docs/api/class-browsertype#browser-type-launch-server) instead of `BrowserType#launch`.
|
38
|
+
- Server can be launched with `npx playwright run-server` CLI command.
|
43
39
|
- Client can connect to server with [BrowserType#connect](https://playwright.dev/docs/api/class-browsertype#browser-type-connect). In playwright-ruby-client, `BrowserType#connect` and not implemented yet and use `Playwright#connect_to_browser_server()` instead.
|
44
40
|
|
45
|
-
Another method is sharing all browser environment. This method is very simple, but not an official feature, and can be changed in future.
|
46
|
-
|
47
|
-
- Server can be launched with `playwright run-server` (CLI command).
|
48
|
-
- Client can connect to server with `Playwright.connect_to_playwright_server` instead of `Playwright.create`
|
49
|
-
|
50
|
-
## Playwright server/client
|
51
|
-
|
52
|
-
:::caution
|
53
|
-
|
54
|
-
This method is no longer supported on Playwright driver >= 1.35. See [this issue](https://github.com/YusukeIwaki/playwright-ruby-client/issues/254) for detail, and use Browser server/client method instead.
|
55
|
-
|
56
|
-
:::
|
57
|
-
|
58
41
|
### Client code
|
59
42
|
|
60
|
-
Many example uses `Playwright#create`, which internally uses Pipe (stdin/stdout) transport for Playwright-protocol messaging. Instead, **
|
43
|
+
Many example uses `Playwright#create`, which internally uses Pipe (stdin/stdout) transport for Playwright-protocol messaging. Instead, **use `Playwright#connect_to_browser_server(endpoint)`** for WebSocket transport.
|
61
44
|
|
62
45
|
```ruby {3}
|
63
46
|
require 'playwright'
|
64
47
|
|
65
|
-
Playwright.
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
page.screenshot(path: 'github-microsoft-playwright.png')
|
70
|
-
end
|
48
|
+
Playwright.connect_to_browser_server('wss://example.com:8888/ws') do |browser|
|
49
|
+
page = browser.new_page
|
50
|
+
page.goto('https://github.com/microsoft/playwright')
|
51
|
+
page.screenshot(path: 'github-microsoft-playwright.png')
|
71
52
|
end
|
72
53
|
```
|
73
54
|
|
74
55
|
`wss://example.com:8888/ws` is an example of endpoint URL of the Playwright server. In local development environment, it is typically `"ws://127.0.0.1:#{port}/ws"`.
|
75
56
|
|
76
|
-
Note that `?browser=chromium` is important for server to determine which browser to prepare.
|
77
|
-
|
78
57
|
### Server code
|
79
58
|
|
80
59
|
With the [official Docker image](https://hub.docker.com/_/microsoft-playwright) or in the local development environment with Node.js, just execute `npx playwright install && npx playwright run-server --port $PORT --path /ws`. (`$PORT` is a port number of the server)
|
@@ -91,45 +70,6 @@ ENV PORT 8888
|
|
91
70
|
CMD ["./node_modules/.bin/playwright", "run-server", "--port", "$PORT", "--path", "/ws"]
|
92
71
|
```
|
93
72
|
|
94
|
-
## Browser server/client
|
95
|
-
|
96
|
-
### Client code
|
97
|
-
|
98
|
-
Use `Playwright#connect_to_playwright_server` and pass the WebSocket URL for browser server.
|
99
|
-
Note that this method requires a block with `Browser`, not `Playwright` or `BrowserType`.
|
100
|
-
|
101
|
-
```ruby
|
102
|
-
Playwright.connect_to_playwright_server(ws_url) do |browser|
|
103
|
-
page = browser.new_page
|
104
|
-
page.goto(...)
|
105
|
-
...
|
106
|
-
end
|
107
|
-
```
|
108
|
-
|
109
|
-
### Server code
|
110
|
-
|
111
|
-
For instant use, `npx playwright launch-server --browser chromium` generates a WebSocket endpoint URL with a random path.
|
112
|
-
|
113
|
-
More customization can be done by implementing JavaScript server like below:
|
114
|
-
|
115
|
-
```js
|
116
|
-
const playwright = require("playwright");
|
117
|
-
|
118
|
-
option = {
|
119
|
-
channel: "chrome-canary",
|
120
|
-
headless: false,
|
121
|
-
port: 8080,
|
122
|
-
wsPath: "ws",
|
123
|
-
};
|
124
|
-
playwright.chromium.launchServer(option).then((server) => {
|
125
|
-
console.log(server.wsEndpoint());
|
126
|
-
});
|
127
|
-
```
|
128
|
-
|
129
|
-
`port` and `wsPath` would be useful for generating static WebSocket endpoint URL.
|
130
|
-
Other available options for `BrowserType#launchServer` can be found here:
|
131
|
-
https://playwright.dev/docs/api/class-browsertype#browser-type-launch-server
|
132
|
-
|
133
73
|
## Debugging for connection
|
134
74
|
|
135
75
|
The client and server are really quiet. This chapter shows how to check if the communication on the WebSocket works well or not.
|
@@ -147,7 +87,7 @@ DEBUG=1 bundle exec ruby some-automation-with-playwright.rb
|
|
147
87
|
Just set an environment variable `DEBUG=pw:*` or `DEBUG=pw:server`
|
148
88
|
|
149
89
|
```
|
150
|
-
DEBUG=pw:* npx playwright
|
90
|
+
DEBUG=pw:* npx playwright run-server --browser chromium
|
151
91
|
```
|
152
92
|
|
153
93
|
See [the official documentation](https://playwright.dev/docs/debug/#verbose-api-logs) for details.
|
@@ -93,10 +93,6 @@ module Playwright
|
|
93
93
|
context.send(:update_options, context_options: context_options, browser_options: browser_options)
|
94
94
|
end
|
95
95
|
|
96
|
-
private def did_launch_browser(browser)
|
97
|
-
browser.send(:update_browser_type, self)
|
98
|
-
end
|
99
|
-
|
100
96
|
private def update_with_playwright_selectors_options(options)
|
101
97
|
selectors = @playwright&.selectors
|
102
98
|
if selectors
|
data/lib/playwright/version.rb
CHANGED
@@ -62,9 +62,12 @@ module Playwright
|
|
62
62
|
STATE_CLOSING = 2
|
63
63
|
STATE_CLOSED = 3
|
64
64
|
|
65
|
-
def initialize(url:, max_payload_size:)
|
65
|
+
def initialize(url:, max_payload_size:, headers:)
|
66
66
|
@impl = DriverImpl.new(url)
|
67
67
|
@driver = ::WebSocket::Driver.client(@impl, max_length: max_payload_size)
|
68
|
+
headers.each do |key, value|
|
69
|
+
@driver.set_header(key, value)
|
70
|
+
end
|
68
71
|
|
69
72
|
setup
|
70
73
|
end
|
@@ -6,8 +6,9 @@ module Playwright
|
|
6
6
|
# ref: https://github.com/microsoft/playwright-python/blob/master/playwright/_impl/_transport.py
|
7
7
|
class WebSocketTransport
|
8
8
|
# @param ws_endpoint [String] EndpointURL of WebSocket
|
9
|
-
def initialize(ws_endpoint:)
|
9
|
+
def initialize(ws_endpoint:, headers:)
|
10
10
|
@ws_endpoint = ws_endpoint
|
11
|
+
@headers = headers
|
11
12
|
@debug = ENV['DEBUG'].to_s == 'true' || ENV['DEBUG'].to_s == '1'
|
12
13
|
end
|
13
14
|
|
@@ -63,6 +64,7 @@ module Playwright
|
|
63
64
|
ws = WebSocketClient.new(
|
64
65
|
url: @ws_endpoint,
|
65
66
|
max_payload_size: 256 * 1024 * 1024, # 256MB
|
67
|
+
headers: @headers,
|
66
68
|
)
|
67
69
|
promise = Concurrent::Promises.resolvable_future
|
68
70
|
ws.on_open do
|
data/lib/playwright.rb
CHANGED
@@ -102,14 +102,7 @@ module Playwright
|
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
105
|
-
#
|
106
|
-
#
|
107
|
-
# Playwright.connect_to_playwright_server(...) do |playwright|
|
108
|
-
# browser = playwright.chromium.launch
|
109
|
-
# ...
|
110
|
-
# end
|
111
|
-
#
|
112
|
-
# @experimental
|
105
|
+
# @Deprecated. Playwright >= 1.54 does not support this method.
|
113
106
|
module_function def connect_to_playwright_server(ws_endpoint, &block)
|
114
107
|
require 'playwright/web_socket_client'
|
115
108
|
require 'playwright/web_socket_transport'
|
@@ -138,7 +131,7 @@ module Playwright
|
|
138
131
|
end
|
139
132
|
end
|
140
133
|
|
141
|
-
# Connects to Playwright server, launched by `npx playwright launch-server chromium` or `playwright
|
134
|
+
# Connects to Playwright server, launched by `npx playwright launch-server --browser chromium` or `npx playwright run-server`
|
142
135
|
#
|
143
136
|
# Playwright.connect_to_browser_server('ws://....') do |browser|
|
144
137
|
# page = browser.new_page
|
@@ -146,11 +139,19 @@ module Playwright
|
|
146
139
|
# end
|
147
140
|
#
|
148
141
|
# @experimental
|
149
|
-
module_function def connect_to_browser_server(ws_endpoint, &block)
|
142
|
+
module_function def connect_to_browser_server(ws_endpoint, browser_type: 'chromium', &block)
|
143
|
+
known_browser_types = ['chromium', 'firefox', 'webkit']
|
144
|
+
unless known_browser_types.include?(browser_type)
|
145
|
+
raise ArgumentError, "Unknown browser type: #{browser_type}. Known types are: #{known_browser_types.join(', ')}"
|
146
|
+
end
|
147
|
+
|
150
148
|
require 'playwright/web_socket_client'
|
151
149
|
require 'playwright/web_socket_transport'
|
152
150
|
|
153
|
-
transport = WebSocketTransport.new(
|
151
|
+
transport = WebSocketTransport.new(
|
152
|
+
ws_endpoint: ws_endpoint,
|
153
|
+
headers: { 'x-playwright-browser' => browser_type },
|
154
|
+
)
|
154
155
|
connection = Connection.new(transport)
|
155
156
|
connection.mark_as_remote
|
156
157
|
connection.async_run
|
@@ -159,8 +160,7 @@ module Playwright
|
|
159
160
|
begin
|
160
161
|
playwright = connection.initialize_playwright
|
161
162
|
browser = playwright.send(:pre_launched_browser)
|
162
|
-
browser.send(:
|
163
|
-
browser.browser_type.send(:did_launch_browser, browser)
|
163
|
+
browser.send(:connect_to_browser_type, playwright.send(browser_type), nil)
|
164
164
|
browser.send(:should_close_connection_on_close!)
|
165
165
|
Execution.new(connection, PlaywrightApi.wrap(playwright), PlaywrightApi.wrap(browser))
|
166
166
|
rescue
|
@@ -179,7 +179,7 @@ module Playwright
|
|
179
179
|
end
|
180
180
|
end
|
181
181
|
|
182
|
-
|
182
|
+
# Connects to Playwright server, launched by `npx playwright launch-server --browser _android` or `playwright._android.launchServer()`
|
183
183
|
#
|
184
184
|
# Playwright.connect_to_android_server('ws://....') do |browser|
|
185
185
|
# page = browser.new_page
|
data/lib/playwright_api/frame.rb
CHANGED
@@ -1039,11 +1039,6 @@ module Playwright
|
|
1039
1039
|
wrap_impl(@impl.wait_for_url(unwrap_impl(url), timeout: unwrap_impl(timeout), waitUntil: unwrap_impl(waitUntil)))
|
1040
1040
|
end
|
1041
1041
|
|
1042
|
-
# @nodoc
|
1043
|
-
def detached=(req)
|
1044
|
-
wrap_impl(@impl.detached=(unwrap_impl(req)))
|
1045
|
-
end
|
1046
|
-
|
1047
1042
|
# @nodoc
|
1048
1043
|
def highlight(selector)
|
1049
1044
|
wrap_impl(@impl.highlight(unwrap_impl(selector)))
|
@@ -1054,6 +1049,11 @@ module Playwright
|
|
1054
1049
|
wrap_impl(@impl.expect(unwrap_impl(selector), unwrap_impl(expression), unwrap_impl(options), unwrap_impl(title)))
|
1055
1050
|
end
|
1056
1051
|
|
1052
|
+
# @nodoc
|
1053
|
+
def detached=(req)
|
1054
|
+
wrap_impl(@impl.detached=(unwrap_impl(req)))
|
1055
|
+
end
|
1056
|
+
|
1057
1057
|
# -- inherited from EventEmitter --
|
1058
1058
|
# @nodoc
|
1059
1059
|
def once(event, callback)
|
@@ -94,13 +94,13 @@ module Playwright
|
|
94
94
|
end
|
95
95
|
|
96
96
|
# @nodoc
|
97
|
-
def
|
98
|
-
wrap_impl(@impl.
|
97
|
+
def android
|
98
|
+
wrap_impl(@impl.android)
|
99
99
|
end
|
100
100
|
|
101
101
|
# @nodoc
|
102
|
-
def
|
103
|
-
wrap_impl(@impl.
|
102
|
+
def electron
|
103
|
+
wrap_impl(@impl.electron)
|
104
104
|
end
|
105
105
|
|
106
106
|
# -- inherited from EventEmitter --
|
@@ -118,13 +118,13 @@ module Playwright
|
|
118
118
|
end
|
119
119
|
|
120
120
|
# @nodoc
|
121
|
-
def
|
122
|
-
wrap_impl(@impl.
|
121
|
+
def ok?
|
122
|
+
wrap_impl(@impl.ok?)
|
123
123
|
end
|
124
124
|
|
125
125
|
# @nodoc
|
126
|
-
def
|
127
|
-
wrap_impl(@impl.
|
126
|
+
def from_service_worker?
|
127
|
+
wrap_impl(@impl.from_service_worker?)
|
128
128
|
end
|
129
129
|
|
130
130
|
# -- inherited from EventEmitter --
|