chrome_remote_better 9001.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ffae482f38836bd62ae5863e2a85513be1c037b45a0210c372757af5b7d493de
4
+ data.tar.gz: 46cecbddf0414550855025a926a486ab21d9b2e722127d47ae665c668d54e3cf
5
+ SHA512:
6
+ metadata.gz: b97372e6616f3e46cd08311af6663983a17aa1bd03d6c158e1ddb75695e924dbe9ebc04d3e31021a0fbd169eb7f4175c5669cb1e69a6d32d56078feaca706d05
7
+ data.tar.gz: abe4334feb8012193f0806819e16eb026e4ae1c6842b1c21bf5cb23f398f1a412178688fed5175bce8ea87497acc22283deb7de40cb47196260872c3cf250d49
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,7 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4
5
+ - 2.5
6
+ - 2.6
7
+ - ruby-head
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at luismi@lmcavalle.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in chrome_remote.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Luismi Cavalle
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,213 @@
1
+ # ChromeRemote
2
+
3
+ [![Gem Version](https://img.shields.io/gem/v/chrome_remote.svg?style=for-the-badge)](https://rubygems.org/gems/chrome_remote)
4
+ [![Build Status](https://img.shields.io/travis/cavalle/chrome_remote/master?style=for-the-badge)](https://travis-ci.org/cavalle/chrome_remote)
5
+
6
+ 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.
7
+
8
+ [1]: https://chromedevtools.github.io/devtools-protocol/
9
+
10
+ ## Usage example
11
+
12
+ The following snippet navigates to `https://github.com`, dumps any request made while loading the page, and takes a screenshot once the page is loaded:
13
+
14
+ ```ruby
15
+ require 'chrome_remote'
16
+ require 'base64'
17
+
18
+ chrome = ChromeRemote.client
19
+
20
+ # Enable events
21
+ chrome.send_cmd "Network.enable"
22
+ chrome.send_cmd "Page.enable"
23
+
24
+ # Setup handler to log network requests
25
+ chrome.on "Network.requestWillBeSent" do |params|
26
+ puts params["request"]["url"]
27
+ end
28
+
29
+ # Navigate to github.com and wait for the page to load
30
+ chrome.send_cmd "Page.navigate", url: "https://github.com"
31
+ chrome.wait_for "Page.loadEventFired"
32
+
33
+ # Take page screenshot
34
+ response = chrome.send_cmd "Page.captureScreenshot"
35
+ File.write "screenshot.png", Base64.decode64(response["data"])
36
+ ```
37
+
38
+ ## Installation
39
+
40
+ Add this line to your application's Gemfile:
41
+
42
+ ```ruby
43
+ gem 'chrome_remote'
44
+ ```
45
+
46
+ And then execute:
47
+
48
+ ```
49
+ $ bundle
50
+ ```
51
+
52
+ Or install it yourself as:
53
+
54
+ ```
55
+ $ gem install chrome_remote
56
+ ```
57
+
58
+ ## Usage
59
+
60
+ To use ChromeRemote, you'll need a Chrome instance running on a known port (`localhost:9222` is the default), using the `--remote-debugging-port` flag.
61
+
62
+ In Linux:
63
+
64
+ ```
65
+ $ google-chrome --remote-debugging-port=9222
66
+ ```
67
+
68
+ In macOS:
69
+
70
+ ```
71
+ $ /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222
72
+ ```
73
+
74
+ In Windows 7 or above:
75
+
76
+ ```
77
+ > "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --remote-debugging-port=9222
78
+ ```
79
+
80
+ #### Headless mode
81
+
82
+ Additionally, since version 59, you can use the `--headless` flag to start Chrome in [headless mode][2]
83
+
84
+ [2]: https://developers.google.com/web/updates/2017/04/headless-chrome
85
+
86
+ ### Using the ChromeRemote API
87
+
88
+ The [Chrome DevTools Protocol][1] is divided into a number of domains ([Page][3], [DOM][4], [Debugger][5], [Network][6], etc.). Each domain defines a number of **commands** it supports and **events** it generates.
89
+
90
+ ChromeRemote provides a simple API that lets you send commands, and handle events of any of the domains in the protocol.
91
+
92
+ To start with, you need an instance of the `ChromeRemote` class.
93
+
94
+ ```ruby
95
+ chrome = ChromeRemote.client(
96
+ host: 'localhost', # optional (default: localhost). Host of the Chrome remote server
97
+ port: 9222, # optional (default: 9222). Port of the Chrome remote server
98
+ new_tab: false # optional (default: false). Whether to use the browser's current tab or a new one
99
+ )
100
+ ```
101
+
102
+ 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:
103
+
104
+ ```ruby
105
+ chrome = ChromeRemote.client
106
+ chrome.send_cmd "Page.navigate", url: "https://github.com"
107
+ # => {:frameId=>1234}
108
+ ```
109
+
110
+ To tackle events, you have several options but, first of all, you need to enable events for any domain you're interested in. You only need to do this once per domain:
111
+
112
+ ```ruby
113
+ chrome = ChromeRemote.client
114
+ chrome.send_cmd "Network.enable"
115
+ ```
116
+
117
+ Now, you can use the `ChromeRemote#on` method to subscribe to an event. For instance, this is how you subscribe to the [Network.requestWillBeSent][8] event:
118
+
119
+ ```ruby
120
+ chrome = ChromeRemote.client
121
+ chrome.send_cmd "Network.enable"
122
+
123
+ chrome.on "Network.requestWillBeSent" do |params|
124
+ puts params["request"]["url"]
125
+ end
126
+ ```
127
+
128
+ With the `ChromeRemote#wait_for` method, you can wait until the next time a given event is triggered. For example, the following snippet navigates to a page and waits for the [Page.loadEventFired][9] event to happen:
129
+
130
+ ```ruby
131
+ chrome = ChromeRemote.client
132
+ chrome.send_cmd "Page.navigate", url: "https://github.com"
133
+
134
+ chrome.wait_for "Page.loadEventFired"
135
+ # => {:timestamp=>34}
136
+ ```
137
+
138
+ You can also use `wait_for` with a block to implement a custom matcher on the event names and params you're waiting for:
139
+
140
+ ```ruby
141
+ chrome = ChromeRemote.client
142
+ chrome.send_cmd "Page.navigate", url: "https://github.com"
143
+
144
+ client.wait_for do |event_name, event_params|
145
+ event_name == "Page.lifecycleEvent" && event_params["name"] == "load"
146
+ end
147
+ ```
148
+
149
+ 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:
150
+
151
+ ```ruby
152
+ chrome = ChromeRemote.client
153
+ chrome.send_cmd "Network.enable"
154
+
155
+ chrome.on "Network.requestWillBeSent" do |params|
156
+ puts params["request"]["url"]
157
+ end
158
+
159
+ chrome.listen # will process incoming messages indefinitely
160
+ ```
161
+
162
+ Finally, you have `ChromeRemote#listen_until` that will listen and process incoming messages but only until a certain condition is met. For instance, the following snippet waits until 5 requests are received and then continues:
163
+
164
+ ```ruby
165
+ chrome = ChromeRemote.client
166
+ chrome.send_cmd "Network.enable"
167
+
168
+ requests = 0
169
+ chrome.on "Network.requestWillBeSent" do |params|
170
+ requests += 1
171
+ end
172
+
173
+ chrome.listen_until { requests == 5 }
174
+
175
+ # do other stuff
176
+ ```
177
+
178
+ [3]: https://chromedevtools.github.io/devtools-protocol/tot/Page/
179
+ [4]: https://chromedevtools.github.io/devtools-protocol/tot/DOM/
180
+ [5]: https://chromedevtools.github.io/devtools-protocol/tot/Debugger/
181
+ [6]: https://chromedevtools.github.io/devtools-protocol/tot/Network/
182
+ [7]: https://chromedevtools.github.io/devtools-protocol/tot/Page/#method-navigate
183
+ [8]: https://chromedevtools.github.io/devtools-protocol/tot/Network/#event-requestWillBeSent
184
+ [9]: https://chromedevtools.github.io/devtools-protocol/tot/Page/#event-loadEventFired
185
+
186
+ ### Logger
187
+
188
+ To log all incoming and outgoing messages you can pass [Logger](https://github.com/ruby/logger) compatible instance to client.
189
+
190
+ ```ruby
191
+ client = ChromeRemote.client(logger: Logger.new($stdout))
192
+ client.send_cmd('Page.enable')
193
+ # I, [2019-03-06T22:32:28.433643 #5070] INFO -- : SEND ► {"method":"Page.enable","params":{},"id":1}
194
+ # I, [2019-03-06T22:32:28.440294 #5070] INFO -- : ◀ RECV {"id":1,"result":{}}
195
+ ```
196
+
197
+ ## Development
198
+
199
+ 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 or any of the scripts in the `/examples` directory (e.g. `bundle exec ruby examples/network_dump_and_screenshot.rb`).
200
+
201
+ To install this gem onto your local machine, run `bundle exec rake install`.
202
+
203
+ To release a new version (if you're a maintainer), 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).
204
+
205
+ ## Contributing
206
+
207
+ Bug reports and pull requests are welcome on GitHub at https://github.com/cavalle/chrome_remote.
208
+
209
+ This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to follow the [code of conduct](https://github.com/cavalle/chrome_remote/blob/master/CODE_OF_CONDUCT.md).
210
+
211
+ ## License
212
+
213
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "chrome_remote"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "chrome_remote/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "chrome_remote_better"
8
+ spec.version = ChromeRemote::VERSION
9
+ spec.authors = ["Luismi Cavalle", "Matti Paksula"]
10
+ spec.email = ["luismi@lmcavalle.com", "matti.paksula@iki.fi"]
11
+
12
+ spec.summary = "ChromeRemote is a client implementation of the Chrome DevTools Protocol in Ruby"
13
+ spec.homepage = "https://github.com/matti/chrome_remote_better"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "websocket-driver", "~> 0.6"
22
+
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.0"
25
+ spec.add_development_dependency "em-websocket", "~> 0.5"
26
+ spec.add_development_dependency "byebug"
27
+ spec.add_development_dependency "webmock"
28
+ end
@@ -0,0 +1,21 @@
1
+ require 'chrome_remote'
2
+ require 'base64'
3
+
4
+ chrome = ChromeRemote.client
5
+
6
+ # Enable events
7
+ chrome.send_cmd "Network.enable"
8
+ chrome.send_cmd "Page.enable"
9
+
10
+ # Setup handler to log network requests
11
+ chrome.on "Network.requestWillBeSent" do |params|
12
+ puts params["request"]["url"]
13
+ end
14
+
15
+ # Navigate to github.com and wait for the page to load
16
+ chrome.send_cmd "Page.navigate", url: "https://github.com"
17
+ chrome.wait_for "Page.loadEventFired"
18
+
19
+ # Take page screenshot
20
+ response = chrome.send_cmd "Page.captureScreenshot"
21
+ File.write "screenshot.png", Base64.decode64(response["data"])
@@ -0,0 +1,51 @@
1
+ require "chrome_remote/version"
2
+ require "chrome_remote/client"
3
+ require "json"
4
+ require "net/http"
5
+
6
+ module ChromeRemote
7
+ class ChromeConnectionError < RuntimeError; end
8
+
9
+ class << self
10
+ DEFAULT_OPTIONS = {
11
+ host: "localhost",
12
+ port: 9222
13
+ }
14
+
15
+ def client(options = {})
16
+ options = DEFAULT_OPTIONS.merge(options)
17
+ logger = options.delete(:logger)
18
+
19
+ Client.new(get_ws_url(options), logger)
20
+ end
21
+
22
+ private
23
+
24
+ def get_ws_url(options)
25
+ path = '/json'
26
+ path += '/new?about:blank' if options.key?(:new_tab)
27
+
28
+ response = Net::HTTP.get(options[:host], path, options[:port])
29
+ response = JSON.parse(response)
30
+
31
+ raise ChromeConnectionError unless response.any?
32
+
33
+ return response['webSocketDebuggerUrl'] if options.key?(:new_tab)
34
+
35
+ first_page = response.find {|e| e["type"] == "page"}
36
+
37
+ raise ChromeConnectionError unless first_page
38
+
39
+ first_page["webSocketDebuggerUrl"]
40
+ rescue ChromeConnectionError
41
+ try ||= 0
42
+ try += 1
43
+
44
+ # Wait up to 5 seconds for Chrome to start fully
45
+ if try <= 50
46
+ sleep 0.1
47
+ retry
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,80 @@
1
+ require "chrome_remote/web_socket_client"
2
+ require "logger"
3
+
4
+ module ChromeRemote
5
+ class Client
6
+ attr_reader :ws, :handlers, :logger
7
+
8
+ def initialize(ws_url, logger = nil)
9
+ @ws = WebSocketClient.new(ws_url)
10
+ @handlers = Hash.new { |hash, key| hash[key] = [] }
11
+ @logger = logger || Logger.new(nil)
12
+ @last_id = 0
13
+ end
14
+
15
+ def send_cmd_async(command, params = {})
16
+ msg_id = generate_unique_id
17
+ payload = {method: command, params: params, id: msg_id}.to_json
18
+
19
+ logger.info "SEND ► #{payload}"
20
+ ws.send_msg(payload)
21
+ msg_id
22
+ end
23
+
24
+ def send_cmd(command, params = {})
25
+ msg_id = send_cmd_async command, params
26
+
27
+ msg = read_until { |msg| msg["id"] == msg_id }
28
+ msg["result"]
29
+ end
30
+
31
+ def on(event_name, &block)
32
+ handlers[event_name] << block
33
+ end
34
+
35
+ def listen_until(&block)
36
+ read_until { block.call }
37
+ end
38
+
39
+ def listen
40
+ read_until { false }
41
+ end
42
+
43
+ def wait_for(event_name=nil)
44
+ if event_name
45
+ msg = read_until { |msg| msg["method"] == event_name }
46
+ elsif block_given?
47
+ msg = read_until { |msg| yield(msg["method"], msg["params"]) }
48
+ end
49
+ msg["params"]
50
+ end
51
+
52
+ private
53
+
54
+ def generate_unique_id
55
+ @last_id += 1
56
+ end
57
+
58
+ def read_msg
59
+ msg = ws.read_msg
60
+ logger.info "◀ RECV #{msg}"
61
+ msg = JSON.parse(msg)
62
+
63
+ # Check if it’s an event and invoke any handlers
64
+ if event_name = msg["method"]
65
+ handlers[event_name].each do |handler|
66
+ handler.call(msg["params"])
67
+ end
68
+ end
69
+
70
+ msg
71
+ end
72
+
73
+ def read_until(&block)
74
+ loop do
75
+ msg = read_msg
76
+ return msg if block.call(msg)
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,22 @@
1
+ require "socket"
2
+
3
+ module ChromeRemote
4
+ class Socket
5
+ attr_reader :url, :io
6
+
7
+ def initialize(url)
8
+ uri = URI.parse(url)
9
+
10
+ @url = url
11
+ @io = TCPSocket.new(uri.host, uri.port)
12
+ end
13
+
14
+ def write(data)
15
+ io.print data
16
+ end
17
+
18
+ def read
19
+ io.readpartial(1024)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ module ChromeRemote
2
+ VERSION = "9001.3.0"
3
+ end
@@ -0,0 +1,57 @@
1
+ require "websocket/driver"
2
+ require "chrome_remote/socket"
3
+
4
+ module ChromeRemote
5
+ class WebSocketClient
6
+ attr_reader :socket, :driver, :messages, :status
7
+
8
+ def initialize(url)
9
+ @socket = ChromeRemote::Socket.new(url)
10
+ @driver = ::WebSocket::Driver.client(socket)
11
+
12
+ @messages = []
13
+ @status = :closed
14
+
15
+ setup_driver
16
+ start_driver
17
+ end
18
+
19
+ def send_msg(msg)
20
+ driver.text msg
21
+ end
22
+
23
+ def read_msg
24
+ parse_input until msg = messages.shift
25
+ msg
26
+ end
27
+
28
+ private
29
+
30
+ def setup_driver
31
+ driver.on(:message) do |e|
32
+ messages << e.data
33
+ end
34
+
35
+ driver.on(:error) do |e|
36
+ raise e.message
37
+ end
38
+
39
+ driver.on(:close) do |e|
40
+ @status = :closed
41
+ end
42
+
43
+ driver.on(:open) do |e|
44
+ @status = :open
45
+ end
46
+ end
47
+
48
+ def start_driver
49
+ driver.start
50
+ parse_input until status == :open
51
+ end
52
+
53
+ def parse_input
54
+ @driver.parse(@socket.read)
55
+ end
56
+ end
57
+ end
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chrome_remote_better
3
+ version: !ruby/object:Gem::Version
4
+ version: 9001.3.0
5
+ platform: ruby
6
+ authors:
7
+ - Luismi Cavalle
8
+ - Matti Paksula
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2020-09-30 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: websocket-driver
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '0.6'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '0.6'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '10.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '10.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rspec
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '3.0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '3.0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: em-websocket
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '0.5'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '0.5'
70
+ - !ruby/object:Gem::Dependency
71
+ name: byebug
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: webmock
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ description:
99
+ email:
100
+ - luismi@lmcavalle.com
101
+ - matti.paksula@iki.fi
102
+ executables: []
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - ".gitignore"
107
+ - ".rspec"
108
+ - ".travis.yml"
109
+ - CODE_OF_CONDUCT.md
110
+ - Gemfile
111
+ - LICENSE.txt
112
+ - README.md
113
+ - Rakefile
114
+ - bin/console
115
+ - bin/setup
116
+ - chrome_remote.gemspec
117
+ - examples/network_dump_and_screenshot.rb
118
+ - lib/chrome_remote.rb
119
+ - lib/chrome_remote/client.rb
120
+ - lib/chrome_remote/socket.rb
121
+ - lib/chrome_remote/version.rb
122
+ - lib/chrome_remote/web_socket_client.rb
123
+ homepage: https://github.com/matti/chrome_remote_better
124
+ licenses:
125
+ - MIT
126
+ metadata: {}
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubygems_version: 3.0.6
143
+ signing_key:
144
+ specification_version: 4
145
+ summary: ChromeRemote is a client implementation of the Chrome DevTools Protocol in
146
+ Ruby
147
+ test_files: []