Class: Capybara::Lightpanda::Process

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

Constant Summary collapse

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

Floor for the cookie/navigation/redirect/modal/keyboard/css/forms/dispatch/ xpath/history/iframe-context/dialog fixes the gem now relies on: PR #2255 (Network.clearBrowserCookies empty params + Network.getAllCookies), PR #2257 (window.location.pathname/.search assignment triggers navigation), PR #2265 (URL fragment inherited across fragment-less redirect), PR #2261 (LP.handleJavaScriptDialog pre-arm), PR #2283 (Referer on cross-page nav), PR #2292 (KeyboardEvent.keyCode/charCode), PR #2294 (UA stylesheet display:none for HEAD/SCRIPT/STYLE/NOSCRIPT/TEMPLATE/ TITLE/), PR #2308 (textarea LF→CRLF), PR #2312 (<input type=image> click submits form), PR #2315 (:disabled honors fieldset/ optgroup ancestors), PR #2322 (LP dialog defaultText fallback when promptText is null), PR #2324 (<label> click runs activation behavior on labeled control), PR #2286 (HTML constraint validation API: el.validity, validationMessage, checkValidity, reportValidity), PR #2342 (<summary> click toggles parent <details>.open), PR #2352 (HTMLInputElement.pattern + patternMismatch via V8 RegExp), PR #2368 (events: report listener exceptions instead of halting dispatch — load-bearing for the gem’s JS bundle dispatch assumptions), PR #2289 (Page.getNavigationHistory + Page.navigateToHistoryEntry —lets us drop the history.back()/history.forward() JS workaround in Browser#back / #forward), PR #2305 (XPath 1.0: Document.evaluate, XPathResult, XPathEvaluator, XPathExpression — lets us drop the ~700 LOC XPath polyfill in javascripts/index.js), PR #2431 (cdp: remove duplicate Page.frameNavigated emission + reuse child frame’s V8 context — fixes issue #2400 iframe contextId churn, lets us drop Browser#find_in_frame’s refresh_frame_stack! rescue), PR #2445 (cdp: reset browser context arena on Target.disposeBrowserContext — restores per-spec state hygiene during Driver#reset!, cures the batch-mode pollution that PR #2431 alone exposed), PR #2435 (dom: implement HTMLDialogElement.showModal, close natively — load-bearing for the gem’s HTMLDialogElement assumptions after polyfills.js was deleted), PR #2450 (forms: add enctype + 5 submitter form-* IDL accessors + text/plain submission — lets us delete polyfills.js entirely; reads of form.enctype / submitter.formTarget now return spec-typed values natively), PR #2478 (css: evaluate @media and matchMedia against viewport —inline <style> @media blocks now apply declarations against the hardcoded 1920×1080 viewport, and window.matchMedia(q).matches returns spec-correct booleans. Lets _lightpanda.isVisible detect inline-@media-gated hides via el.checkVisibility() without any gem-side workaround. External <link rel=“stylesheet”> fetch stays out of scope by design — see .claude/rules/lightpanda-io.md limitation #6). Build 6269 = first nightly carrying PR #2478 (merge commit ab63cfbf, 2026-05-16); the 2026-05-16 nightly cut at 03:36 UTC was hours before the merge at 13:42 UTC.

Gem::Version.new("6269")

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Process

Returns a new instance of Process.



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

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
  @finalizer_registered = false
end

Instance Attribute Details

#nightly_buildObject (readonly)

Returns the value of attribute nightly_build.



60
61
62
# File 'lib/capybara/lightpanda/process.rb', line 60

def nightly_build
  @nightly_build
end

#pidObject (readonly)

Returns the value of attribute pid.



60
61
62
# File 'lib/capybara/lightpanda/process.rb', line 60

def pid
  @pid
end

#versionObject (readonly)

Returns the value of attribute version.



60
61
62
# File 'lib/capybara/lightpanda/process.rb', line 60

def version
  @version
end

#ws_urlObject (readonly)

Returns the value of attribute ws_url.



60
61
62
# File 'lib/capybara/lightpanda/process.rb', line 60

def ws_url
  @ws_url
end

Instance Method Details

#alive?Boolean

Returns:

  • (Boolean)


113
114
115
116
117
118
119
120
# File 'lib/capybara/lightpanda/process.rb', line 113

def alive?
  return false unless @pid

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

#startObject



75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/capybara/lightpanda/process.rb', line 75

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

  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



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/capybara/lightpanda/process.rb', line 89

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