Method: Ferrum::Browser#initialize

Defined in:
lib/ferrum/browser.rb

#initialize(options = nil) ⇒ Browser

Initializes the browser.

Parameters:

  • options (Hash{Symbol => Object}, nil) (defaults to: nil)

    Additional browser options.

Options Hash (options):

  • :headless (Boolean) — default: true

    Set browser as headless or not.

  • :incognito (Boolean) — default: true

    Create an incognito profile for the browser startup window.

  • :xvfb (Boolean) — default: false

    Run browser in a virtual framebuffer.

  • :flatten (Boolean) — default: true

    Use one websocket connection to the browser and all the pages in flatten mode.

  • :window_size ((Integer, Integer)) — default: [1024, 768]

    The dimensions of the browser window in which to test, expressed as a 2-element array, e.g. ‘[1024, 768]`.

  • :extensions (Array<String, Hash>)

    An array of paths to files or JS source code to be preloaded into the browser e.g.: ‘[“/path/to/script.js”, { source: “window.secret = ’top’” }]‘

  • :logger (#puts)

    When present, debug output is written to this object.

  • :slowmo (Integer, Float)

    Set a delay in seconds to wait before sending command. Useful companion of headless option, so that you have time to see changes.

  • :timeout (Numeric) — default: 5

    The number of seconds we’ll wait for a response when communicating with browser.

  • :js_errors (Boolean)

    When true, JavaScript errors get re-raised in Ruby.

  • :pending_connection_errors (Boolean) — default: true

    When main frame is still waiting for slow responses while timeout is reached PendingConnectionsError is raised. It’s better to figure out why you have slow responses and fix or block them rather than turn this setting off.

  • :browser_name (:chrome, :firefox) — default: :chrome

    Sets the browser’s name. Note: only experimental support for ‘:firefox` for now.

  • :browser_path (String)

    Path to Chrome binary, you can also set ENV variable as ‘BROWSER_PATH=some/path/chrome bundle exec rspec`.

  • :browser_options (Hash)

    Additional command line options, [see them all](peter.sh/experiments/chromium-command-line-switches/) e.g. ‘{ “ignore-certificate-errors” => nil }`

  • :ignore_default_browser_options (Boolean)

    Ferrum has a number of default options it passes to the browser, if you set this to ‘true` then only options you put in `:browser_options` will be passed to the browser, except required ones of course.

  • :port (Integer)

    Remote debugging port for headless Chrome.

  • :host (String)

    Remote debugging address for headless Chrome.

  • :url (String)

    URL for a running instance of Chrome. If this is set, a browser process will not be spawned.

  • :process_timeout (Integer)

    How long to wait for the Chrome process to respond on startup.

  • :ws_max_receive_size (Integer)

    How big messages to accept from Chrome over the web socket, in bytes. Defaults to 64MB. Incoming messages larger this will cause a DeadBrowserError.

  • :proxy (Hash)

    Specify proxy settings, [read more](github.com/rubycdp/ferrum#proxy).

  • :save_path (String)

    Path to save attachments with [Content-Disposition](developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition) header.

  • :env (Hash)

    Environment variables you’d like to pass through to the process.



132
133
134
135
136
137
# File 'lib/ferrum/browser.rb', line 132

def initialize(options = nil)
  @options = Options.new(options)
  @client = @process = @contexts = nil

  start
end