class Postdoc::ChromeProcess
Spins up a Chrome process.
Attributes
pid[R]
port[R]
Public Class Methods
new(port: Random.rand(65_535 - 1024), **_options)
click to toggle source
# File lib/postdoc/chrome_process.rb, line 8 def initialize(port: Random.rand(65_535 - 1024), **_options) @port = port @pid = Process.spawn "chrome --remote-debugging-port=#{port} --headless", out: File::NULL, err: File::NULL end
Public Instance Methods
alive?()
click to toggle source
# File lib/postdoc/chrome_process.rb, line 14 def alive? @alive ||= test_socket! rescue Errno::ECONNREFUSED false end
client()
click to toggle source
# File lib/postdoc/chrome_process.rb, line 27 def client Client.new port end
kill()
click to toggle source
# File lib/postdoc/chrome_process.rb, line 20 def kill Process.kill 'INT', pid Process.wait pid rescue true end
Private Instance Methods
test_socket!()
click to toggle source
# File lib/postdoc/chrome_process.rb, line 33 def test_socket! TCPSocket.new('localhost', port) end