class Ferrum::Browser::Xvfb

Constants

NOT_FOUND

Attributes

display_id[R]
pid[R]
screen_size[R]

Public Class Methods

new(options) click to toggle source
# File lib/ferrum/browser/xvfb.rb, line 19
def initialize(options)
  @path = self.class.xvfb_path
  raise Cliver::Dependency::NotFound.new(NOT_FOUND) unless @path

  @screen_size = options.fetch(:window_size, [1024, 768]).join("x") + "x24"
  @display_id = (Time.now.to_f * 1000).to_i % 100_000_000
end
start(*args) click to toggle source
# File lib/ferrum/browser/xvfb.rb, line 9
def self.start(*args)
  new(*args).tap(&:start)
end
xvfb_path() click to toggle source
# File lib/ferrum/browser/xvfb.rb, line 13
def self.xvfb_path
  Cliver.detect("Xvfb")
end

Public Instance Methods

start() click to toggle source
# File lib/ferrum/browser/xvfb.rb, line 27
def start
  @pid = ::Process.spawn("#{@path} :#{display_id} -screen 0 #{screen_size}")
  ::Process.detach(@pid)
end
to_env() click to toggle source
# File lib/ferrum/browser/xvfb.rb, line 32
def to_env
  { "DISPLAY" => ":#{display_id}" }
end