Class: Ferrum::Browser::Xvfb
- Inherits:
-
Object
- Object
- Ferrum::Browser::Xvfb
- Defined in:
- lib/ferrum/browser/xvfb.rb
Overview
Manages an Xvfb virtual display server, letting a "headful" browser run
in environments without a real display (e.g. CI). Spawned by Process
when the :xvfb option is set, and exposes the DISPLAY environment
variable the browser process needs to attach to it.
Constant Summary collapse
- NOT_FOUND =
"Could not find an executable for the Xvfb. Try to install " \ "it with your package manager"
Instance Attribute Summary collapse
-
#display_id ⇒ Object
readonly
Returns the value of attribute display_id.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
-
#screen_size ⇒ Object
readonly
Returns the value of attribute screen_size.
Class Method Summary collapse
-
.start(*args) ⇒ Xvfb
Builds and starts a new Xvfb instance.
Instance Method Summary collapse
-
#initialize(options) ⇒ Xvfb
constructor
A new instance of Xvfb.
-
#start ⇒ void
Spawns the Xvfb process on the configured display.
-
#to_env ⇒ Hash{String => String}
Environment variables needed to point the browser at this Xvfb display.
Constructor Details
#initialize(options) ⇒ Xvfb
Returns a new instance of Xvfb.
29 30 31 32 33 34 35 |
# File 'lib/ferrum/browser/xvfb.rb', line 29 def initialize() @path = Binary.find("Xvfb") raise BinaryNotFoundError, NOT_FOUND unless @path @screen_size = "#{.window_size.join('x')}x24" @display_id = (Time.now.to_f * 1000).to_i % 100_000_000 end |
Instance Attribute Details
#display_id ⇒ Object (readonly)
Returns the value of attribute display_id.
27 28 29 |
# File 'lib/ferrum/browser/xvfb.rb', line 27 def display_id @display_id end |
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
27 28 29 |
# File 'lib/ferrum/browser/xvfb.rb', line 27 def pid @pid end |
#screen_size ⇒ Object (readonly)
Returns the value of attribute screen_size.
27 28 29 |
# File 'lib/ferrum/browser/xvfb.rb', line 27 def screen_size @screen_size end |
Class Method Details
.start(*args) ⇒ Xvfb
Builds and starts a new Xvfb instance.
23 24 25 |
# File 'lib/ferrum/browser/xvfb.rb', line 23 def self.start(*args) new(*args).tap(&:start) end |
Instance Method Details
#start ⇒ void
This method returns an undefined value.
Spawns the Xvfb process on the configured display.
42 43 44 45 |
# File 'lib/ferrum/browser/xvfb.rb', line 42 def start @pid = ::Process.spawn("#{@path} :#{display_id} -screen 0 #{screen_size}") ::Process.detach(@pid) end |
#to_env ⇒ Hash{String => String}
Environment variables needed to point the browser at this Xvfb display.
52 53 54 |
# File 'lib/ferrum/browser/xvfb.rb', line 52 def to_env { "DISPLAY" => ":#{display_id}" } end |