Class: WebkitRemote::Rpc
- Inherits:
-
Object
- Object
- WebkitRemote::Rpc
- Defined in:
- lib/webkit_remote/rpc.rb
Overview
RPC client for the Webkit remote debugging protocol.
Instance Attribute Summary collapse
-
#closed ⇒ Boolean
(also: #closed?)
readonly
If true, the connection to the remote debugging server has been closed, and this instance is mostly useless.
-
#debug_url ⇒ String
readonly
Points to this client’s Webkit remote debugging server.
Instance Method Summary collapse
-
#call(method, params = nil) ⇒ Hash<String, Object>
Remote debugging RPC call.
-
#close ⇒ WebkitRemote::Rpc
Closes the connection to the remote debugging server.
-
#each_event {|event| ... } ⇒ WebkitRemote::Rpc
Continuously reports events sent by the remote debugging server.
-
#initialize(opts = {}) ⇒ Rpc
constructor
Connects to the remote debugging server in a Webkit tab.
Constructor Details
#initialize(opts = {}) ⇒ Rpc
Connects to the remote debugging server in a Webkit tab.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/webkit_remote/rpc.rb', line 13 def initialize(opts = {}) unless tab = opts[:tab] raise ArgumentError, 'Target tab not specified' end @closed = false @next_id = 2 @events = [] @debug_url = tab.debug_url @web_socket = WsSyncClient.new @debug_url end |
Instance Attribute Details
#closed ⇒ Boolean (readonly) Also known as: closed?
Returns if true, the connection to the remote debugging server has been closed, and this instance is mostly useless.
85 86 87 |
# File 'lib/webkit_remote/rpc.rb', line 85 def closed @closed end |
#debug_url ⇒ String (readonly)
Returns points to this client’s Webkit remote debugging server.
89 90 91 |
# File 'lib/webkit_remote/rpc.rb', line 89 def debug_url @debug_url end |
Instance Method Details
#call(method, params = nil) ⇒ Hash<String, Object>
Remote debugging RPC call.
See the following URL for implemented calls.
https://developers.google.com/chrome-developer-tools/docs/protocol/1.1/index
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/webkit_remote/rpc.rb', line 34 def call(method, params = nil) request_id = @next_id @next_id += 1 request = { jsonrpc: '2.0', id: request_id, method: method, } request[:params] = params if params request_json = JSON.dump request @web_socket.send_frame request_json loop do result = request_id return result if result end end |
#close ⇒ WebkitRemote::Rpc
Closes the connection to the remote debugging server.
Call this method to avoid leaking resources.
75 76 77 78 79 80 81 |
# File 'lib/webkit_remote/rpc.rb', line 75 def close return if @closed @closed = true @web_socket.close @web_socket = nil self end |
#each_event {|event| ... } ⇒ WebkitRemote::Rpc
Continuously reports events sent by the remote debugging server.
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/webkit_remote/rpc.rb', line 59 def each_event loop do if @events.empty? nil else yield @events.shift end end self end |