Class: WebkitRemote::Browser
- Inherits:
-
Object
- Object
- WebkitRemote::Browser
- Defined in:
- lib/webkit_remote/browser.rb
Overview
The master connection to the remote debugging server in a Webkit process.
Defined Under Namespace
Classes: Tab
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.
-
#host ⇒ String
readonly
Hostname or IP of the Webkit remote debugging server.
-
#port ⇒ Integer
readonly
Port that the Webkit remote debugging server listens on.
-
#process ⇒ WebkitRemote::Process?
readonly
Process instance passed to this connection’s constructor.
-
#stop_process ⇒ Boolean
(also: #stop_process?)
If true, a WebkitRemote::Process will be stopped when this browser connection is closed.
Instance Method Summary collapse
-
#close ⇒ WebkitRemote::Browser
Closes the connection the browser.
-
#finalize ⇒ Object
Clean up when garbage collected.
-
#initialize(opts = {}) ⇒ Browser
constructor
Sets up a debugging connection to a Webkit process.
-
#tabs ⇒ Array<WebkitRemote::Browser::Tab>
Retrieves the tabs that are currently open in the browser.
Constructor Details
#initialize(opts = {}) ⇒ Browser
Sets up a debugging connection to a Webkit process.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# 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 |
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.
113 114 115 |
# File 'lib/webkit_remote/browser.rb', line 113 def closed @closed end |
#host ⇒ String (readonly)
Returns hostname or IP of the Webkit remote debugging server.
106 107 108 |
# File 'lib/webkit_remote/browser.rb', line 106 def host @host end |
#port ⇒ Integer (readonly)
Returns port that the Webkit remote debugging server listens on.
109 110 111 |
# File 'lib/webkit_remote/browser.rb', line 109 def port @port end |
#process ⇒ WebkitRemote::Process? (readonly)
Returns Process instance passed to this connection’s constructor.
103 104 105 |
# File 'lib/webkit_remote/browser.rb', line 103 def process @process end |
#stop_process ⇒ Boolean Also known as: stop_process?
Returns if true, a WebkitRemote::Process will be stopped when this browser connection is closed.
77 78 79 |
# File 'lib/webkit_remote/browser.rb', line 77 def stop_process @stop_process end |
Instance Method Details
#close ⇒ WebkitRemote::Browser
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.
47 48 49 50 51 52 53 54 |
# 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 |
#finalize ⇒ Object
Clean up when garbage collected.
117 118 119 |
# File 'lib/webkit_remote/browser.rb', line 117 def finalize close unless @closed end |
#tabs ⇒ Array<WebkitRemote::Browser::Tab>
Retrieves the tabs that are currently open in the browser.
These tabs can be used to start debugging.
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# 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 |