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/client.rb,
lib/ferrum/browser/command.rb,
lib/ferrum/browser/process.rb,
lib/ferrum/browser/subscriber.rb,
lib/ferrum/browser/web_socket.rb,
lib/ferrum/browser/options/base.rb,
lib/ferrum/browser/options/chrome.rb,
lib/ferrum/browser/options/firefox.rb
Defined Under Namespace
Modules: Options Classes: Client, Command, Process, Subscriber, WebSocket, Xvfb
Constant Summary collapse
- DEFAULT_TIMEOUT =
ENV.fetch("FERRUM_DEFAULT_TIMEOUT", 5).to_i
- WINDOW_SIZE =
[1024, 768].freeze
- BASE_URL_SCHEMA =
%w[http https].freeze
Instance Attribute Summary collapse
-
#base_url ⇒ Object
Returns the value of attribute base_url.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#contexts ⇒ Object
readonly
Returns the value of attribute contexts.
-
#js_errors ⇒ Object
readonly
Returns the value of attribute js_errors.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#process ⇒ Object
readonly
Returns the value of attribute process.
-
#slowmo ⇒ Object
readonly
Returns the value of attribute slowmo.
- #timeout ⇒ Object
-
#window_size ⇒ Object
readonly
Returns the value of attribute window_size.
-
#ws_max_receive_size ⇒ Object
readonly
Returns the value of attribute ws_max_receive_size.
Instance Method Summary collapse
- #command(*args) ⇒ Object
- #crash ⇒ Object
- #extensions ⇒ Object
-
#initialize(options = nil) ⇒ Browser
constructor
A new instance of Browser.
- #quit ⇒ Object
- #reset ⇒ Object
- #resize(**options) ⇒ Object
- #restart ⇒ Object
Constructor Details
#initialize(options = nil) ⇒ Browser
Returns a new instance of Browser.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/ferrum/browser.rb', line 36 def initialize( = nil) ||= {} @client = nil @window_size = .fetch(:window_size, WINDOW_SIZE) @original_window_size = @window_size @options = Hash(.merge(window_size: @window_size)) @logger, @timeout, @ws_max_receive_size = @options.values_at(:logger, :timeout, :ws_max_receive_size) @js_errors = @options.fetch(:js_errors, false) @slowmo = @options[:slowmo].to_f if @options.key?(:base_url) self.base_url = @options[:base_url] end if ENV["FERRUM_DEBUG"] && !@logger STDOUT.sync = true @logger = STDOUT @options[:logger] = @logger end @options.freeze start end |
Instance Attribute Details
#base_url ⇒ Object
Returns the value of attribute base_url.
32 33 34 |
# File 'lib/ferrum/browser.rb', line 32 def base_url @base_url end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
32 33 34 |
# File 'lib/ferrum/browser.rb', line 32 def client @client end |
#contexts ⇒ Object (readonly)
Returns the value of attribute contexts.
32 33 34 |
# File 'lib/ferrum/browser.rb', line 32 def contexts @contexts end |
#js_errors ⇒ Object (readonly)
Returns the value of attribute js_errors.
32 33 34 |
# File 'lib/ferrum/browser.rb', line 32 def js_errors @js_errors end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
32 33 34 |
# File 'lib/ferrum/browser.rb', line 32 def logger @logger end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
32 33 34 |
# File 'lib/ferrum/browser.rb', line 32 def @options end |
#process ⇒ Object (readonly)
Returns the value of attribute process.
32 33 34 |
# File 'lib/ferrum/browser.rb', line 32 def process @process end |
#slowmo ⇒ Object (readonly)
Returns the value of attribute slowmo.
32 33 34 |
# File 'lib/ferrum/browser.rb', line 32 def slowmo @slowmo end |
#timeout ⇒ Object
79 80 81 |
# File 'lib/ferrum/browser.rb', line 79 def timeout @timeout || DEFAULT_TIMEOUT end |
#window_size ⇒ Object (readonly)
Returns the value of attribute window_size.
32 33 34 |
# File 'lib/ferrum/browser.rb', line 32 def window_size @window_size end |
#ws_max_receive_size ⇒ Object (readonly)
Returns the value of attribute ws_max_receive_size.
32 33 34 |
# File 'lib/ferrum/browser.rb', line 32 def ws_max_receive_size @ws_max_receive_size end |
Instance Method Details
#command(*args) ⇒ Object
83 84 85 86 87 88 |
# File 'lib/ferrum/browser.rb', line 83 def command(*args) @client.command(*args) rescue DeadBrowserError restart raise end |
#crash ⇒ Object
111 112 113 |
# File 'lib/ferrum/browser.rb', line 111 def crash command("Browser.crash") end |
#extensions ⇒ Object
73 74 75 76 77 |
# File 'lib/ferrum/browser.rb', line 73 def extensions @extensions ||= Array(@options[:extensions]).map do |ext| (ext.is_a?(Hash) && ext[:source]) || File.read(ext) end end |
#quit ⇒ Object
100 101 102 103 104 |
# File 'lib/ferrum/browser.rb', line 100 def quit @client.close @process.stop @client = @process = @contexts = nil end |
#reset ⇒ Object
90 91 92 93 |
# File 'lib/ferrum/browser.rb', line 90 def reset @window_size = @original_window_size contexts.reset end |
#resize(**options) ⇒ Object
106 107 108 109 |
# File 'lib/ferrum/browser.rb', line 106 def resize(**) @window_size = [[:width], [:height]] page.resize(**) end |
#restart ⇒ Object
95 96 97 98 |
# File 'lib/ferrum/browser.rb', line 95 def restart quit start end |