class WebkitRemote::Browser
The master connection to the remote debugging server in a Webkit process.
Attributes
@return [Boolean] if true, the connection to the remote debugging server
has been closed, and this instance is mostly useless
@return [Boolean] if true, the connection to the remote debugging server
has been closed, and this instance is mostly useless
@return [String] hostname or IP of the Webkit remote debugging server
@return [Integer] port that the Webkit remote debugging server listens on
@return [WebkitRemote::Process, nil] Process
instance passed to this
connection's constructor
@return [Boolean] if true, a WebkitRemote::Process
will be stopped when
this browser connection is closed
@return [Boolean] if true, a WebkitRemote::Process
will be stopped when
this browser connection is closed
Public Class Methods
Sets up a debugging connection to a Webkit process.
@param [Hash] opts info on the browser to connect to @option opts [String] host the hostname / IP address of the Webkit remote
debugging server
@option opts [Integer] port the port that the Webkit remote debugging
server listens to
@option opts [WebkitRemote::Process] process a process on the local machine
to connect to; the process will automatically be stopped when the debugging connection is closed; the host and port will be configured automatically
@option opts [Boolean] stop_process
if true, the WebkitRemote::Process
passed to the constructor will be automatically stopped
@raise [SystemCallError] if the connection could not be established; this
most likely means that there is no remote debugging server at the given host / port
# File lib/webkit_remote/browser.rb, line 24 def initialize(opts = {}) if opts[:process] @process = opts[:process] @stop_process = opts.fetch :stop_process, false @host = 'localhost' @port = process.port else @process = nil @stop_process = false @host = opts[:host] || 'localhost' @port = opts[:port] || 9292 end @closed = false @http = Net::HTTP.start @host, @port end
Public Instance Methods
Closes the connection the browser.
If the Browser
instance was given a WebkitRemote::Process
, the process will also be stopped. This instance becomes useless after closing.
@return [WebkitRemote::Browser] self
# File lib/webkit_remote/browser.rb, line 47 def close return self if @closed @closed = true @http.finish @http = nil @process.stop if @stop_process self end
Clean up when garbage collected.
# File lib/webkit_remote/browser.rb, line 117 def finalize close unless @closed end
Changes the automated WebkitRemote::Process
stopping behavior.
This should only be set to true if this Browser
instance was given a WebkitRemote::Process
at creation time.
@param [Boolean] new_stop_process if true, the WebkitRemote::Process
passed to this instance's constructor will be stopped when this connection is closed
@return [Boolean] new_stop_process
# File lib/webkit_remote/browser.rb, line 89 def stop_process=(new_stop_process) if new_stop_process unless @process raise ArgumentError, "Browser instance not backed by a Webkit process" end @stop_process = true else @stop_process = false end new_stop_process end
Retrieves the tabs that are currently open in the browser.
These tabs can be used to start debugging.
@return [Array<WebkitRemote::Browser::Tab>] the open tabs
# File lib/webkit_remote/browser.rb, line 61 def tabs http_response = @http.request Net::HTTP::Get.new('/json') tabs = JSON.parse(http_response.body).map do |json_tab| title = json_tab['title'] url = json_tab['url'] debug_url = json_tab['webSocketDebuggerUrl'] Tab.new self, debug_url, title: title, url: url end # HACK(pwnall): work around the nasty Google Hangouts integration tabs.select do |tab| tab.url != 'chrome-extension://nkeimhogjdpnpccoofpliimaahmaaome/background.html' end end