Class: Ferrum::Browser::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/ferrum/browser/command.rb

Direct Known Subclasses

Chrome, Firefox

Constant Summary collapse

BROWSER_HOST =
"127.0.0.1"
BROWSER_PORT =
"0"
NOT_FOUND =
"Could not find an executable for the browser. Try to make " \
"it available on the PATH or set environment varible for " \
"example BROWSER_PATH=\"/usr/bin/chrome\"".freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options, user_data_dir) ⇒ Command

Returns a new instance of Command.

Raises:

  • (Cliver::Dependency::NotFound)


27
28
29
30
31
32
33
34
# File 'lib/ferrum/browser/command.rb', line 27

def initialize(options, user_data_dir)
  @flags = {}
  @options, @user_data_dir = options, user_data_dir
  @path = options[:browser_path] || ENV["BROWSER_PATH"] || detect_path
  raise Cliver::Dependency::NotFound.new(NOT_FOUND) unless @path

  combine_flags
end

Instance Attribute Details

#flagsObject (readonly)

Returns the value of attribute flags.



25
26
27
# File 'lib/ferrum/browser/command.rb', line 25

def flags
  @flags
end

#optionsObject (readonly)

Returns the value of attribute options.



25
26
27
# File 'lib/ferrum/browser/command.rb', line 25

def options
  @options
end

#pathObject (readonly)

Returns the value of attribute path.



25
26
27
# File 'lib/ferrum/browser/command.rb', line 25

def path
  @path
end

Class Method Details

.build(options, user_data_dir) ⇒ Object

Currently only these browsers support CDP: github.com/cyrus-and/chrome-remote-interface#implementations



14
15
16
17
18
19
20
21
22
23
# File 'lib/ferrum/browser/command.rb', line 14

def self.build(options, user_data_dir)
  case options[:browser_name]
  when :firefox
    Firefox
  when :chrome, :opera, :edge, nil
    Chrome
  else
    raise NotImplementedError, "not supported browser"
  end.new(options, user_data_dir)
end

Instance Method Details

#to_aObject



36
37
38
# File 'lib/ferrum/browser/command.rb', line 36

def to_a
  [path] + flags.map { |k, v| v.nil? ? "--#{k}" : "--#{k}=#{v}" }
end