Class: Capybara::Lightpanda::Process

Inherits:
Object
  • Object
show all
Defined in:
lib/capybara/lightpanda/process.rb

Constant Summary collapse

READY_PATTERN =
/server running.*address=(\d+\.\d+\.\d+\.\d+:\d+)/
ADDRESS_IN_USE_PATTERN =
/err=AddressInUse/
MINIMUM_NIGHTLY_BUILD =

First nightly with Page.addScriptToEvaluateOnNewDocument (PR #1993, merged 2026-03-30). The gem relies on this for XPath polyfill auto-injection.

5267

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Process

Returns a new instance of Process.



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/capybara/lightpanda/process.rb', line 15

def initialize(options)
  @options = options
  @pid = nil
  @ws_url = nil
  @version = nil
  @nightly_build = nil
  @stdout_r = nil
  @stdout_w = nil
  @stderr_r = nil
  @stderr_w = nil
end

Instance Attribute Details

#nightly_buildObject (readonly)

Returns the value of attribute nightly_build.



13
14
15
# File 'lib/capybara/lightpanda/process.rb', line 13

def nightly_build
  @nightly_build
end

#pidObject (readonly)

Returns the value of attribute pid.



13
14
15
# File 'lib/capybara/lightpanda/process.rb', line 13

def pid
  @pid
end

#versionObject (readonly)

Returns the value of attribute version.



13
14
15
# File 'lib/capybara/lightpanda/process.rb', line 13

def version
  @version
end

#ws_urlObject (readonly)

Returns the value of attribute ws_url.



13
14
15
# File 'lib/capybara/lightpanda/process.rb', line 13

def ws_url
  @ws_url
end

Instance Method Details

#alive?Boolean

Returns:

  • (Boolean)


65
66
67
68
69
70
71
72
# File 'lib/capybara/lightpanda/process.rb', line 65

def alive?
  return false unless @pid

  ::Process.kill(0, @pid)
  true
rescue Errno::ESRCH, Errno::EPERM
  false
end

#startObject



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/capybara/lightpanda/process.rb', line 27

def start
  binary_path = @options.browser_path || Binary.find_or_download

  raise BinaryNotFoundError, "Lightpanda binary not found" unless binary_path

  check_minimum_version(binary_path)
  attempt_start(binary_path)
rescue ProcessTimeoutError => e
  raise unless e.message.include?("already in use")

  kill_process_on_port(@options.port)
  attempt_start(binary_path)
end

#stopObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/capybara/lightpanda/process.rb', line 41

def stop
  return unless @pid

  begin
    ::Process.kill("TERM", -@pid) # Kill process group
  rescue Errno::ESRCH, Errno::EPERM
    # Process group already dead, try direct
    begin
      ::Process.kill("TERM", @pid)
    rescue Errno::ESRCH
      # Process already dead
    end
  end

  begin
    ::Process.wait(@pid)
  rescue Errno::ECHILD
    # Already reaped
  end

  cleanup_pipes
  @pid = nil
end