Method: Ferrum::Browser::Process#start

Defined in:
lib/ferrum/browser/process.rb

#startObject



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/ferrum/browser/process.rb', line 138

def start
  # Don't do anything as browser is already running as external process.
  return if ws_url

  begin
    read_io, write_io = IO.pipe
    process_options = { in: File::NULL }
    process_options[:pgroup] = true unless Ferrum.windows?
    process_options[:out] = process_options[:err] = write_io

    raise Cliver::Dependency::NotFound.new(NOT_FOUND) unless @path

    @cmd = [@path] + @options.map { |k, v| v.nil? ? "--#{k}" : "--#{k}=#{v}" }
    @pid = ::Process.spawn(*@cmd, process_options)
    ObjectSpace.define_finalizer(self, self.class.process_killer(@pid))

    parse_ws_url(read_io, @process_timeout)
  ensure
    close_io(read_io, write_io)
  end
end