Class: WebkitRemote::Client
- Inherits:
-
Object
- Object
- WebkitRemote::Client
- Defined in:
- lib/webkit_remote/client.rb,
lib/webkit_remote/client/dom.rb,
lib/webkit_remote/client/page.rb,
lib/webkit_remote/client/input.rb,
lib/webkit_remote/client/console.rb,
lib/webkit_remote/client/network.rb,
lib/webkit_remote/client/runtime.rb,
lib/webkit_remote/client/dom_runtime.rb,
lib/webkit_remote/client/network_events.rb
Overview
Client for the Webkit remote debugging protocol
A client manages a single tab.
Defined Under Namespace
Modules: Console, Dom, Input, Network, Page, Runtime Classes: ConsoleMessage, DomNode, JsObject, JsObjectGroup, JsProperty, NetworkCacheEntry, NetworkRequest, NetworkRequestInitiator, NetworkResource, NetworkResourceTiming, NetworkResponse, StackTrace, UndefinedClass
Constant Summary collapse
- Undefined =
class WebkitRemote::Client::UndefinedClass
UndefinedClass.new
Instance Attribute Summary collapse
-
#browser ⇒ WebkitRemote::Browser
readonly
Master session to the browser that owns the tab debugged by this client.
-
#close_browser ⇒ Boolean
(also: #close_browser?)
If true, the master debugging connection to the browser associated with the client’s tab will be automatically closed when this RPC client’s connection is closed; in turn, this might stop the browser process.
-
#closed ⇒ Boolean
(also: #closed?)
readonly
If true, the connection to the remote debugging server has been closed, and this instance is mostly useless.
-
#rpc ⇒ WebkitRemote::Rpc
readonly
The WebSocket RPC client; useful for making raw RPC calls to unsupported methods.
Attributes included from Network
#disable_cache, #http_headers, #network_events, #network_resources, #user_agent
Attributes included from Console
#console_events, #console_messages
Attributes included from Page
Class Method Summary collapse
-
.clearer(name) ⇒ Object
Registers a module clearer.
-
.initializer(name) ⇒ Object
Registers a module initializer.
Instance Method Summary collapse
-
#clear_all ⇒ Object
Removes all the remote debugging data cached by this client.
-
#close ⇒ WebkitRemote::Rpc
Closes the remote debugging connection.
-
#each_event {|event| ... } ⇒ WebkitRemote::Client
Continuously reports events sent by the remote debugging server.
-
#initialize(opts = {}) ⇒ Client
constructor
Connects to the remote debugging server in a Webkit tab.
-
#inspect ⇒ Object
Debugging output.
-
#wait_for(conditions) ⇒ Array<WebkitRemote::Event>
Waits for the remote debugging server to send a specific event.
Methods included from Runtime
#clear_runtime, #initialize_runtime, #object_group, #object_group_auto_name, #object_group_remove, #remote_eval
Methods included from Network
#can_clear_cookies?, #can_clear_network_cache?, #clear_cookies, #clear_network, #clear_network_cache, #initialize_network, #network_resource
Methods included from Console
#clear_console, #console_add_message, #initialize_console
Methods included from Input
Methods included from Page
#initialize_page, #navigate_to, #reload
Methods included from Dom
#clear_dom, #dom_node, #dom_root, #dom_root!, #dom_update_node, #initialize_dom
Constructor Details
#initialize(opts = {}) ⇒ Client
Connects to the remote debugging server in a Webkit tab.
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/webkit_remote/client.rb', line 15 def initialize(opts = {}) unless tab = opts[:tab] raise ArgumentError, 'Target tab not specified' end @rpc = WebkitRemote::Rpc.new opts @debug_url = @rpc.debug_url @browser = tab.browser @close_browser = opts.fetch :close_browser, false @closed = false initialize_modules end |
Instance Attribute Details
#browser ⇒ WebkitRemote::Browser (readonly)
Returns master session to the browser that owns the tab debugged by this client.
108 109 110 |
# File 'lib/webkit_remote/client.rb', line 108 def browser @browser end |
#close_browser ⇒ Boolean Also known as: close_browser?
Returns if true, the master debugging connection to the browser associated with the client’s tab will be automatically closed when this RPC client’s connection is closed; in turn, this might stop the browser process.
50 51 52 |
# File 'lib/webkit_remote/client.rb', line 50 def close_browser @close_browser end |
#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.
43 44 45 |
# File 'lib/webkit_remote/client.rb', line 43 def closed @closed end |
#rpc ⇒ WebkitRemote::Rpc (readonly)
Returns the WebSocket RPC client; useful for making raw RPC calls to unsupported methods.
104 105 106 |
# File 'lib/webkit_remote/client.rb', line 104 def rpc @rpc end |
Class Method Details
.clearer(name) ⇒ Object
Registers a module clearer.
126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/webkit_remote/client.rb', line 126 def self.clearer(name) before_name = :"clear_modules_before_#{name}" alias_method before_name, :clear_modules private before_name remove_method :clear_modules eval <<END_METHOD def clear_modules #{name} #{before_name.to_s} end END_METHOD private :clear_modules end |
.initializer(name) ⇒ Object
Registers a module initializer.
111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/webkit_remote/client.rb', line 111 def self.initializer(name) before_name = :"initialize_modules_before_#{name}" alias_method before_name, :initialize_modules private before_name remove_method :initialize_modules eval <<END_METHOD def initialize_modules #{name} #{before_name.to_s} end END_METHOD private :initialize_modules end |
Instance Method Details
#clear_all ⇒ Object
Removes all the remote debugging data cached by this client.
Some modules accumulate data throughout the debigging process. For example, WebkitRemote::Client::Remote#remote_eval and WebkitRemote::Events#ConsoleMessage build Ruby equivalents of the returned JavaScript objects, and prevent Chrome from garbage-collecting the returned JavaScript objects.
Although modules have individual methods for releasing this data, such as WebkitRemote::Client::RemoteGroup#release, keeping track of individual data items is very inconvenient. Therefore, if you need to run a WebkitRemote client for an extended period of time, you might find it easier to periodically call this method.
98 99 100 |
# File 'lib/webkit_remote/client.rb', line 98 def clear_all clear_modules end |
#close ⇒ WebkitRemote::Rpc
Closes the remote debugging connection.
Call this method to avoid leaking resources.
32 33 34 35 36 37 38 39 |
# File 'lib/webkit_remote/client.rb', line 32 def close return if @closed @closed = true @rpc.close @rpc = nil @browser.close if @close_browser self end |
#each_event {|event| ... } ⇒ WebkitRemote::Client
Continuously reports events sent by the remote debugging server.
60 61 62 63 64 65 |
# File 'lib/webkit_remote/client.rb', line 60 def each_event @rpc.each_event do |rpc_event| yield WebkitRemote::Event.for(rpc_event, self) end self end |
#inspect ⇒ Object
Debugging output.
157 158 159 160 161 162 |
# File 'lib/webkit_remote/client.rb', line 157 def inspect result = self.to_s result[-1, 0] = " server=#{@debug_url.inspect} closed=#{@closed.inspect}" result end |
#wait_for(conditions) ⇒ Array<WebkitRemote::Event>
Waits for the remote debugging server to send a specific event.
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/webkit_remote/client.rb', line 72 def wait_for(conditions) unless WebkitRemote::Event.can_receive? self, conditions raise ArgumentError, "Cannot receive event with #{conditions.inspect}" end events = [] each_event do |event| events << event break if event.matches?(conditions) end events end |