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
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
- 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.
-
#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.
-
#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 ⇒ Object
-
#initialize(options = nil) ⇒ Options
constructor
A new instance of Options.
- #to_h ⇒ Object
- #validate_proxy(options) ⇒ Object
Constructor Details
#initialize(options = nil) ⇒ Options
Returns a new instance of Options.
21 22 23 24 25 26 27 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 |
# File 'lib/ferrum/browser/options.rb', line 21 def initialize( = nil) @options = Hash(&.dup) @port = @options.fetch(:port, BROWSER_PORT) @host = @options.fetch(:host, BROWSER_HOST) @timeout = @options.fetch(:timeout, DEFAULT_TIMEOUT) @window_size = @options.fetch(:window_size, WINDOW_SIZE) @js_errors = @options.fetch(:js_errors, false) @headless = @options.fetch(:headless, true) @incognito = @options.fetch(:incognito, true) @flatten = @options.fetch(:flatten, true) @pending_connection_errors = @options.fetch(:pending_connection_errors, true) @process_timeout = @options.fetch(:process_timeout, PROCESS_TIMEOUT) @slowmo = @options[:slowmo].to_f @env = @options[:env] @xvfb = @options[:xvfb] @save_path = @options[:save_path] @browser_name = @options[:browser_name] @browser_path = @options[:browser_path] @ws_max_receive_size = @options[:ws_max_receive_size] @ignore_default_browser_options = @options[:ignore_default_browser_options] @proxy = validate_proxy(@options[:proxy]) @logger = parse_logger(@options[:logger]) @base_url = parse_base_url(@options[:base_url]) if @options[:base_url] @url = @options[:url].to_s if @options[:url] @ws_url = @options[:ws_url].to_s if @options[:ws_url] @options = @options.merge(window_size: @window_size).freeze @browser_options = @options.fetch(:browser_options, {}).freeze end |
Instance Attribute Details
#base_url ⇒ Object
Returns the value of attribute base_url.
14 15 16 |
# File 'lib/ferrum/browser/options.rb', line 14 def base_url @base_url end |
#browser_name ⇒ Object (readonly)
Returns the value of attribute browser_name.
14 15 16 |
# File 'lib/ferrum/browser/options.rb', line 14 def browser_name @browser_name end |
#browser_options ⇒ Object (readonly)
Returns the value of attribute browser_options.
14 15 16 |
# File 'lib/ferrum/browser/options.rb', line 14 def @browser_options end |
#browser_path ⇒ Object (readonly)
Returns the value of attribute browser_path.
14 15 16 |
# File 'lib/ferrum/browser/options.rb', line 14 def browser_path @browser_path end |
#default_user_agent ⇒ Object
Returns the value of attribute default_user_agent.
19 20 21 |
# File 'lib/ferrum/browser/options.rb', line 19 def default_user_agent @default_user_agent end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
14 15 16 |
# File 'lib/ferrum/browser/options.rb', line 14 def env @env end |
#flatten ⇒ Object (readonly)
Returns the value of attribute flatten.
14 15 16 |
# File 'lib/ferrum/browser/options.rb', line 14 def flatten @flatten end |
#headless ⇒ Object (readonly)
Returns the value of attribute headless.
14 15 16 |
# File 'lib/ferrum/browser/options.rb', line 14 def headless @headless end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
14 15 16 |
# File 'lib/ferrum/browser/options.rb', line 14 def host @host end |
#ignore_default_browser_options ⇒ Object (readonly)
Returns the value of attribute ignore_default_browser_options.
14 15 16 |
# File 'lib/ferrum/browser/options.rb', line 14 def @ignore_default_browser_options end |
#incognito ⇒ Object (readonly)
Returns the value of attribute incognito.
14 15 16 |
# File 'lib/ferrum/browser/options.rb', line 14 def incognito @incognito end |
#js_errors ⇒ Object (readonly)
Returns the value of attribute js_errors.
14 15 16 |
# File 'lib/ferrum/browser/options.rb', line 14 def js_errors @js_errors end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
14 15 16 |
# File 'lib/ferrum/browser/options.rb', line 14 def logger @logger end |
#pending_connection_errors ⇒ Object (readonly)
Returns the value of attribute pending_connection_errors.
14 15 16 |
# File 'lib/ferrum/browser/options.rb', line 14 def pending_connection_errors @pending_connection_errors end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
14 15 16 |
# File 'lib/ferrum/browser/options.rb', line 14 def port @port end |
#process_timeout ⇒ Object (readonly)
Returns the value of attribute process_timeout.
14 15 16 |
# File 'lib/ferrum/browser/options.rb', line 14 def process_timeout @process_timeout end |
#proxy ⇒ Object (readonly)
Returns the value of attribute proxy.
14 15 16 |
# File 'lib/ferrum/browser/options.rb', line 14 def proxy @proxy end |
#save_path ⇒ Object (readonly)
Returns the value of attribute save_path.
14 15 16 |
# File 'lib/ferrum/browser/options.rb', line 14 def save_path @save_path end |
#slowmo ⇒ Object (readonly)
Returns the value of attribute slowmo.
14 15 16 |
# File 'lib/ferrum/browser/options.rb', line 14 def slowmo @slowmo end |
#timeout ⇒ Object
Returns the value of attribute timeout.
19 20 21 |
# File 'lib/ferrum/browser/options.rb', line 19 def timeout @timeout end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
14 15 16 |
# File 'lib/ferrum/browser/options.rb', line 14 def url @url end |
#window_size ⇒ Object (readonly)
Returns the value of attribute window_size.
14 15 16 |
# File 'lib/ferrum/browser/options.rb', line 14 def window_size @window_size end |
#ws_max_receive_size ⇒ Object (readonly)
Returns the value of attribute ws_max_receive_size.
14 15 16 |
# File 'lib/ferrum/browser/options.rb', line 14 def ws_max_receive_size @ws_max_receive_size end |
#ws_url ⇒ Object (readonly)
Returns the value of attribute ws_url.
14 15 16 |
# File 'lib/ferrum/browser/options.rb', line 14 def ws_url @ws_url end |
#xvfb ⇒ Object (readonly)
Returns the value of attribute xvfb.
14 15 16 |
# File 'lib/ferrum/browser/options.rb', line 14 def xvfb @xvfb end |
Instance Method Details
#extensions ⇒ Object
58 59 60 61 62 |
# File 'lib/ferrum/browser/options.rb', line 58 def extensions @extensions ||= Array(@options[:extensions]).map do |extension| (extension.is_a?(Hash) && extension[:source]) || File.read(extension) end end |
#to_h ⇒ Object
76 77 78 |
# File 'lib/ferrum/browser/options.rb', line 76 def to_h @options end |
#validate_proxy(options) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/ferrum/browser/options.rb', line 64 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 |