Class: Ferrum::Browser
- Inherits:
-
Object
- Object
- Ferrum::Browser
- Extended by:
- Forwardable
- Defined in:
- lib/ferrum/browser.rb,
lib/ferrum/browser/xvfb.rb,
lib/ferrum/browser/binary.rb,
lib/ferrum/browser/command.rb,
lib/ferrum/browser/options.rb,
lib/ferrum/browser/process.rb,
lib/ferrum/browser/options/base.rb,
lib/ferrum/browser/version_info.rb,
lib/ferrum/browser/options/chrome.rb,
lib/ferrum/browser/options/firefox.rb
Defined Under Namespace
Modules: Binary Classes: Command, Options, Process, VersionInfo, Xvfb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#contexts ⇒ Object
readonly
Returns the value of attribute contexts.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#process ⇒ Object
readonly
Returns the value of attribute process.
Instance Method Summary collapse
- #crash ⇒ Object
-
#create_page(new_context: false, proxy: nil) ⇒ Ferrum::Page
Creates a new page.
-
#evaluate_on_new_document(expression) ⇒ Object
Evaluate JavaScript to modify things before a page load.
- #headless_new? ⇒ Boolean
-
#initialize(options = nil) ⇒ Browser
constructor
Initializes the browser.
- #quit ⇒ Object
-
#reset ⇒ Object
Closes browser tabs opened by the ‘Browser` instance.
- #restart ⇒ Object
-
#version ⇒ VersionInfo
Gets the version information from the browser.
Constructor Details
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
33 34 35 |
# File 'lib/ferrum/browser.rb', line 33 def client @client end |
#contexts ⇒ Object (readonly)
Returns the value of attribute contexts.
33 34 35 |
# File 'lib/ferrum/browser.rb', line 33 def contexts @contexts end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
33 34 35 |
# File 'lib/ferrum/browser.rb', line 33 def @options end |
#process ⇒ Object (readonly)
Returns the value of attribute process.
33 34 35 |
# File 'lib/ferrum/browser.rb', line 33 def process @process end |
Instance Method Details
#crash ⇒ Object
221 222 223 |
# File 'lib/ferrum/browser.rb', line 221 def crash command("Browser.crash") end |
#create_page(new_context: false, proxy: nil) ⇒ Ferrum::Page
Creates a new page.
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/ferrum/browser.rb', line 147 def create_page(new_context: false, proxy: nil) page = if new_context || proxy params = {} if proxy .validate_proxy(proxy) params.merge!(proxyServer: "#{proxy[:host]}:#{proxy[:port]}") params.merge!(proxyBypassList: proxy[:bypass]) if proxy[:bypass] end context = contexts.create(**params) context.create_page(proxy: proxy) else default_context.create_page end block_given? ? yield(page) : page ensure if block_given? page&.close context.dispose if new_context end end |
#evaluate_on_new_document(expression) ⇒ Object
Evaluate JavaScript to modify things before a page load.
184 185 186 |
# File 'lib/ferrum/browser.rb', line 184 def evaluate_on_new_document(expression) extensions << expression end |
#headless_new? ⇒ Boolean
236 237 238 |
# File 'lib/ferrum/browser.rb', line 236 def headless_new? process&.command&.headless_new? end |
#quit ⇒ Object
211 212 213 214 215 216 217 218 219 |
# File 'lib/ferrum/browser.rb', line 211 def quit return unless @client contexts.close_connections @client.close @process.stop @client = @process = @contexts = nil end |
#reset ⇒ Object
Closes browser tabs opened by the ‘Browser` instance.
202 203 204 |
# File 'lib/ferrum/browser.rb', line 202 def reset contexts.reset end |
#restart ⇒ Object
206 207 208 209 |
# File 'lib/ferrum/browser.rb', line 206 def restart quit start end |
#version ⇒ VersionInfo
Gets the version information from the browser.
232 233 234 |
# File 'lib/ferrum/browser.rb', line 232 def version VersionInfo.new(command("Browser.getVersion")) end |