Class: Ferrum::Browser::Options
- Inherits:
-
Object
- Object
- Ferrum::Browser::Options
- Defined in:
- lib/ferrum/browser/options.rb,
lib/ferrum/browser/options/base.rb,
lib/ferrum/browser/options/chrome.rb,
lib/ferrum/browser/options/firefox.rb
Overview
Resolves and normalizes the options hash passed to Browser.new, applying defaults for connection settings (host, port, timeouts), window size, and other launch behavior. Used throughout the browser to look up user-configured settings.
Defined Under Namespace
Classes: Base, Chrome, Firefox
Constant Summary collapse
- BROWSER_PORT =
"0"- BROWSER_HOST =
"127.0.0.1"- WINDOW_SIZE =
[1024, 768].freeze
- BASE_URL_SCHEMA =
%w[http https].freeze
- DEFAULT_TIMEOUT =
ENV.fetch("FERRUM_DEFAULT_TIMEOUT", 5).to_i
- DEFAULT_PROTOCOL_TIMEOUT =
ENV.fetch("FERRUM_PROTOCOL_TIMEOUT", DEFAULT_TIMEOUT).to_i
- PROCESS_TIMEOUT =
ENV.fetch("FERRUM_PROCESS_TIMEOUT", 10).to_i
- DEBUG_MODE =
!ENV.fetch("FERRUM_DEBUG", nil).nil?
Instance Attribute Summary collapse
-
#base_url ⇒ Object
Returns the value of attribute base_url.
-
#browser_name ⇒ Object
readonly
Returns the value of attribute browser_name.
-
#browser_options ⇒ Object
readonly
Returns the value of attribute browser_options.
-
#browser_path ⇒ Object
readonly
Returns the value of attribute browser_path.
-
#default_user_agent ⇒ Object
Returns the value of attribute default_user_agent.
-
#dockerize ⇒ Object
readonly
Returns the value of attribute dockerize.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#flatten ⇒ Object
readonly
Returns the value of attribute flatten.
-
#headless ⇒ Object
readonly
Returns the value of attribute headless.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#ignore_default_browser_options ⇒ Object
readonly
Returns the value of attribute ignore_default_browser_options.
-
#incognito ⇒ Object
readonly
Returns the value of attribute incognito.
-
#js_errors ⇒ Object
readonly
Returns the value of attribute js_errors.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#pending_connection_errors ⇒ Object
readonly
Returns the value of attribute pending_connection_errors.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#process_timeout ⇒ Object
readonly
Returns the value of attribute process_timeout.
-
#protocol_timeout ⇒ Object
Returns the value of attribute protocol_timeout.
-
#proxy ⇒ Object
readonly
Returns the value of attribute proxy.
-
#save_path ⇒ Object
readonly
Returns the value of attribute save_path.
-
#slowmo ⇒ Object
readonly
Returns the value of attribute slowmo.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
-
#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.
-
#ws_url ⇒ Object
readonly
Returns the value of attribute ws_url.
-
#xvfb ⇒ Object
readonly
Returns the value of attribute xvfb.
Instance Method Summary collapse
-
#extensions ⇒ Array<String>
JS source to preload into the browser, read from
:extensionsoption. -
#initialize(options = nil) ⇒ Options
constructor
A new instance of Options.
-
#to_h ⇒ Hash{Symbol => Object}
Raw options hash used to initialize the browser.
-
#validate_proxy(options) ⇒ Hash?
Validates the
:proxyoption, if given.
Constructor Details
#initialize(options = nil) ⇒ Options
28 29 30 31 32 33 34 35 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 |
# File 'lib/ferrum/browser/options.rb', line 28 def initialize( = nil) = Hash(&.dup) @port = .fetch(:port, BROWSER_PORT) @host = .fetch(:host, BROWSER_HOST) @timeout = .fetch(:timeout, DEFAULT_TIMEOUT) @protocol_timeout = .fetch(:protocol_timeout, DEFAULT_PROTOCOL_TIMEOUT) @window_size = .fetch(:window_size, WINDOW_SIZE) @js_errors = .fetch(:js_errors, false) @headless = .fetch(:headless, true) @incognito = .fetch(:incognito, true) @dockerize = .fetch(:dockerize, false) @flatten = .fetch(:flatten, true) @pending_connection_errors = .fetch(:pending_connection_errors, false) @process_timeout = .fetch(:process_timeout, PROCESS_TIMEOUT) @slowmo = [:slowmo].to_f @env = [:env] @xvfb = [:xvfb] @save_path = [:save_path] @browser_name = [:browser_name] @browser_path = [:browser_path] @ws_max_receive_size = [:ws_max_receive_size] = [:ignore_default_browser_options] @proxy = validate_proxy([:proxy]) @logger = parse_logger([:logger]) @base_url = parse_base_url([:base_url]) if [:base_url] @url = [:url].to_s if [:url] @ws_url = [:ws_url].to_s if [:ws_url] = .merge(window_size: @window_size).freeze = .fetch(:browser_options, {}).freeze end |
Instance Attribute Details
#base_url ⇒ Object
Returns the value of attribute base_url.
21 22 23 |
# File 'lib/ferrum/browser/options.rb', line 21 def base_url @base_url end |
#browser_name ⇒ Object (readonly)
Returns the value of attribute browser_name.
21 22 23 |
# File 'lib/ferrum/browser/options.rb', line 21 def browser_name @browser_name end |
#browser_options ⇒ Object (readonly)
Returns the value of attribute browser_options.
21 22 23 |
# File 'lib/ferrum/browser/options.rb', line 21 def end |
#browser_path ⇒ Object (readonly)
Returns the value of attribute browser_path.
21 22 23 |
# File 'lib/ferrum/browser/options.rb', line 21 def browser_path @browser_path end |
#default_user_agent ⇒ Object
Returns the value of attribute default_user_agent.
26 27 28 |
# File 'lib/ferrum/browser/options.rb', line 26 def default_user_agent @default_user_agent end |
#dockerize ⇒ Object (readonly)
Returns the value of attribute dockerize.
21 22 23 |
# File 'lib/ferrum/browser/options.rb', line 21 def dockerize @dockerize end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
21 22 23 |
# File 'lib/ferrum/browser/options.rb', line 21 def env @env end |
#flatten ⇒ Object (readonly)
Returns the value of attribute flatten.
21 22 23 |
# File 'lib/ferrum/browser/options.rb', line 21 def flatten @flatten end |
#headless ⇒ Object (readonly)
Returns the value of attribute headless.
21 22 23 |
# File 'lib/ferrum/browser/options.rb', line 21 def headless @headless end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
21 22 23 |
# File 'lib/ferrum/browser/options.rb', line 21 def host @host end |
#ignore_default_browser_options ⇒ Object (readonly)
Returns the value of attribute ignore_default_browser_options.
21 22 23 |
# File 'lib/ferrum/browser/options.rb', line 21 def end |
#incognito ⇒ Object (readonly)
Returns the value of attribute incognito.
21 22 23 |
# File 'lib/ferrum/browser/options.rb', line 21 def incognito @incognito end |
#js_errors ⇒ Object (readonly)
Returns the value of attribute js_errors.
21 22 23 |
# File 'lib/ferrum/browser/options.rb', line 21 def js_errors @js_errors end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
21 22 23 |
# File 'lib/ferrum/browser/options.rb', line 21 def logger @logger end |
#pending_connection_errors ⇒ Object (readonly)
Returns the value of attribute pending_connection_errors.
21 22 23 |
# File 'lib/ferrum/browser/options.rb', line 21 def pending_connection_errors @pending_connection_errors end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
21 22 23 |
# File 'lib/ferrum/browser/options.rb', line 21 def port @port end |
#process_timeout ⇒ Object (readonly)
Returns the value of attribute process_timeout.
21 22 23 |
# File 'lib/ferrum/browser/options.rb', line 21 def process_timeout @process_timeout end |
#protocol_timeout ⇒ Object
Returns the value of attribute protocol_timeout.
26 27 28 |
# File 'lib/ferrum/browser/options.rb', line 26 def protocol_timeout @protocol_timeout end |
#proxy ⇒ Object (readonly)
Returns the value of attribute proxy.
21 22 23 |
# File 'lib/ferrum/browser/options.rb', line 21 def proxy @proxy end |
#save_path ⇒ Object (readonly)
Returns the value of attribute save_path.
21 22 23 |
# File 'lib/ferrum/browser/options.rb', line 21 def save_path @save_path end |
#slowmo ⇒ Object (readonly)
Returns the value of attribute slowmo.
21 22 23 |
# File 'lib/ferrum/browser/options.rb', line 21 def slowmo @slowmo end |
#timeout ⇒ Object
Returns the value of attribute timeout.
26 27 28 |
# File 'lib/ferrum/browser/options.rb', line 26 def timeout @timeout end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
21 22 23 |
# File 'lib/ferrum/browser/options.rb', line 21 def url @url end |
#window_size ⇒ Object (readonly)
Returns the value of attribute window_size.
21 22 23 |
# File 'lib/ferrum/browser/options.rb', line 21 def window_size @window_size end |
#ws_max_receive_size ⇒ Object (readonly)
Returns the value of attribute ws_max_receive_size.
21 22 23 |
# File 'lib/ferrum/browser/options.rb', line 21 def ws_max_receive_size @ws_max_receive_size end |
#ws_url ⇒ Object (readonly)
Returns the value of attribute ws_url.
21 22 23 |
# File 'lib/ferrum/browser/options.rb', line 21 def ws_url @ws_url end |
#xvfb ⇒ Object (readonly)
Returns the value of attribute xvfb.
21 22 23 |
# File 'lib/ferrum/browser/options.rb', line 21 def xvfb @xvfb end |
Instance Method Details
#extensions ⇒ Array<String>
JS source to preload into the browser, read from :extensions option.
81 82 83 84 85 |
# File 'lib/ferrum/browser/options.rb', line 81 def extensions @extensions ||= Array([:extensions]).map do |extension| (extension.is_a?(Hash) && extension[:source]) || File.read(extension) end end |
#to_h ⇒ Hash{Symbol => Object}
Raw options hash used to initialize the browser.
116 117 118 |
# File 'lib/ferrum/browser/options.rb', line 116 def to_h end |
#validate_proxy(options) ⇒ Hash?
Validates the :proxy option, if given.
99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/ferrum/browser/options.rb', line 99 def validate_proxy() return unless raise ArgumentError, "proxy options must be a Hash" unless .is_a?(Hash) if [:host].nil? && [:port].nil? raise ArgumentError, "proxy options must be a Hash with at least :host | :port" end end |