Sha256: 30c27a122183edf9a604c9b967872709afd6480796979fdee5666735bca665cf
Contents?: true
Size: 673 Bytes
Versions: 3
Compression:
Stored size: 673 Bytes
Contents
# frozen_string_literal: true module Postdoc # Spins up a Chrome process. class ChromeProcess attr_reader :pid, :port def initialize(port: Random.rand(1025..65535), **_options) @port = port @pid = Process.spawn "chrome --remote-debugging-port=#{port} --headless", out: File::NULL, err: File::NULL end def alive? @alive ||= test_socket! rescue Errno::ECONNREFUSED false end def kill Process.kill 'INT', pid Process.wait pid rescue true end def client Client.new port end private def test_socket! TCPSocket.new('localhost', port) end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
postdoc-0.4.5 | lib/postdoc/chrome_process.rb |
postdoc-0.4.4 | lib/postdoc/chrome_process.rb |
postdoc-0.4.3 | lib/postdoc/chrome_process.rb |