chrome_remote 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -2
- data/lib/chrome_remote/client.rb +14 -10
- data/lib/chrome_remote/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2aa46eb656817f1c7cef04b5b604bbd7da4aaaa
|
4
|
+
data.tar.gz: fbad3f461b01b9bde4f6b90dcf46bc23fa18aa6b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5bce9f49de0bb134ff2cb0ed38a36bf1d4e2241a73682e1cf082aee2437e7c2d1842cbb7be3c66471e1bec6efa0dd23f32f1c1a0edd7fd2ddd6063c710200144
|
7
|
+
data.tar.gz: ce718db0bb534d36a1cc6377ae56150d70ce55f001c50114a1885e1dc4a5f0b16a792dd9e44e061f9726d634b519f6f015fece1f200d84315d789826020a35e0
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# ChromeRemote
|
2
2
|
|
3
|
-
ChromeRemote is a client implementation of the [Chrome DevTools Protocol][1] in Ruby. It lets you instrument, inspect, debug and profile instances of Chrome/Chromium based browsers from your Ruby code.
|
3
|
+
ChromeRemote is a client implementation of the [Chrome DevTools Protocol][1] in Ruby. It lets you remotely control, instrument, inspect, debug and profile instances of Chrome/Chromium based browsers from your Ruby code.
|
4
4
|
|
5
5
|
[1]: https://chromedevtools.github.io/devtools-protocol/
|
6
6
|
|
@@ -90,7 +90,7 @@ To start with, you need an instance of the `ChromeRemote` class.
|
|
90
90
|
|
91
91
|
```ruby
|
92
92
|
chrome = ChromeRemote.client host: 'localhost', # optional, default: localhost
|
93
|
-
port:
|
93
|
+
port: 9222 # optional, default: 9222
|
94
94
|
```
|
95
95
|
|
96
96
|
Now, to send commands, ChromeRemote provides the `ChromeRemote#send_cmd` method. For example, this is how you make Chrome navigate to a url by sending the [Page.navigate][7] command:
|
@@ -129,6 +129,17 @@ chrome.wait_for "Page.loadEventFired"
|
|
129
129
|
# => {:timestamp=>34}
|
130
130
|
```
|
131
131
|
|
132
|
+
You can also use `wait_for` with a block to implement a custom matcher on the event names and params you're waiting for:
|
133
|
+
|
134
|
+
```ruby
|
135
|
+
chrome = ChromeRemote.client
|
136
|
+
chrome.send_cmd "Page.navigate", url: "https://github.com"
|
137
|
+
|
138
|
+
client.wait_for do |event_name, event_params|
|
139
|
+
event_name == "Page.lifecycleEvent" && event_params["name"] == "load"
|
140
|
+
end
|
141
|
+
```
|
142
|
+
|
132
143
|
In certain occasions, after you have subscribed to one or several events, you may just want to process messages indefinitely, and let the event handlers process any event that may happen until you kill your script. For those cases, ChromeRemote provides the `ChromeRemote#listen` method:
|
133
144
|
|
134
145
|
```ruby
|
data/lib/chrome_remote/client.rb
CHANGED
@@ -6,14 +6,14 @@ module ChromeRemote
|
|
6
6
|
|
7
7
|
def initialize(ws_url)
|
8
8
|
@ws = WebSocketClient.new(ws_url)
|
9
|
-
@handlers = Hash.new {|hash, key| hash[key] = [] }
|
9
|
+
@handlers = Hash.new { |hash, key| hash[key] = [] }
|
10
10
|
end
|
11
|
-
|
12
|
-
def send_cmd(command, params = {})
|
11
|
+
|
12
|
+
def send_cmd(command, params = {})
|
13
13
|
msg_id = generate_unique_id
|
14
|
-
|
14
|
+
|
15
15
|
ws.send_msg({method: command, params: params, id: msg_id}.to_json)
|
16
|
-
|
16
|
+
|
17
17
|
msg = read_until { |msg| msg["id"] == msg_id }
|
18
18
|
msg["result"]
|
19
19
|
end
|
@@ -30,13 +30,17 @@ module ChromeRemote
|
|
30
30
|
read_until { false }
|
31
31
|
end
|
32
32
|
|
33
|
-
def wait_for(event_name)
|
34
|
-
|
33
|
+
def wait_for(event_name=nil)
|
34
|
+
if event_name
|
35
|
+
msg = read_until { |msg| msg["method"] == event_name }
|
36
|
+
elsif block_given?
|
37
|
+
msg = read_until { |msg| yield(msg["method"], msg["params"]) }
|
38
|
+
end
|
35
39
|
msg["params"]
|
36
40
|
end
|
37
|
-
|
41
|
+
|
38
42
|
private
|
39
|
-
|
43
|
+
|
40
44
|
def generate_unique_id
|
41
45
|
@last_id ||= 0
|
42
46
|
@last_id += 1
|
@@ -62,4 +66,4 @@ module ChromeRemote
|
|
62
66
|
end
|
63
67
|
end
|
64
68
|
end
|
65
|
-
end
|
69
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chrome_remote
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luismi Cavalle
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: websocket-driver
|