Class: Google::Chrome::Client
- Inherits:
-
Object
- Object
- Google::Chrome::Client
- Defined in:
- lib/google/chrome/client.rb
Instance Method Summary collapse
- #extension(id) ⇒ Object
-
#initialize(host, port) ⇒ Client
constructor
Create a Client object and establish the debugger connection.
-
#read_all_response ⇒ Object
Read all responses from the server.
-
#read_response ⇒ Object
Read one response from the server.
-
#request(header, body) ⇒ Object
Send a request.
- #server_version ⇒ Object
- #tabs ⇒ Object
Constructor Details
#initialize(host, port) ⇒ Client
Create a Client object and establish the debugger connection.
19 20 21 22 |
# File 'lib/google/chrome/client.rb', line 19 def initialize(host, port) @socket = TCPSocket.open(host, port) handshake end |
Instance Method Details
#extension(id) ⇒ Object
80 81 82 |
# File 'lib/google/chrome/client.rb', line 80 def extension(id) ExtensionPorts.new(self, id) end |
#read_all_response ⇒ Object
Read all responses from the server.
27 28 29 30 31 32 33 34 35 |
# File 'lib/google/chrome/client.rb', line 27 def read_all_response result = [] while IO.select([ @socket ], [], [], 0.1) result << read_response end result end |
#read_response ⇒ Object
Read one response from the server.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/google/chrome/client.rb', line 40 def read_response header = {} while ln = @socket.gets case ln when "\r\n" break when /^([A-Za-z-]+):(.*)$/ header[$1] = $2.chomp else raise end end body = JSON.parse(@socket.read(header['Content-Length'].to_i)) return header, body end |
#request(header, body) ⇒ Object
Send a request.
61 62 63 64 |
# File 'lib/google/chrome/client.rb', line 61 def request(header, body) write_request(header, body) return read_response end |
#server_version ⇒ Object
66 67 68 69 70 |
# File 'lib/google/chrome/client.rb', line 66 def server_version header, resp = request({ 'Tool' => 'DevToolsService' }, { 'command' => 'version' }) resp['data'] end |