def start
    return self if running?

    unless @pid = ::Process.spawn(*@cli)
      # The launch failed.
      stop
      return nil
    end

    (@timeout * 20).times do
      # Check if the browser exited.
      begin
        break if ::Process.wait(@pid, ::Process::WNOHANG)
      rescue SystemCallError  # no children
        break
      end

      # Check if the browser finished starting up.
      begin
        browser = WebkitRemote::Browser.new process: self
        @running = true
        return browser
      rescue SystemCallError  # most likely ECONNREFUSED
        Kernel.sleep 0.05
      end
    end
    # The browser failed, or was too slow to start.
    stop
    nil
  end
def start
    return self if running?

    unless @pid = ::Process.spawn(*@cli)
      # The launch failed.
      stop
      return nil
    end

    (@timeout * 20).times do
      # Check if the browser exited.
      begin
        break if ::Process.wait(@pid, ::Process::WNOHANG)
      rescue SystemCallError  # no children
        break
      end

      # Check if the browser finished starting up.
      begin
        browser = WebkitRemote::Browser.new process: self
        @running = true
        return browser
      rescue SystemCallError  # most likely ECONNREFUSED
        Kernel.sleep 0.05
      end
    end
    # The browser failed, or was too slow to start.
    stop
    nil
  end
Tracker for a yet-unlaunched process.

 @param [Hash] opts tweak the options below
 @option opts [Integer] port the port used by the remote debugging server;
     the default port is 9292
 @option opts [Number] timeout number of seconds to wait for the browser
     to start; the default timeout is 10 seconds
 @option opts [Hash<Symbol, Number>] window set the :left, :top, :width and
     :height of the browser window; by default, the browser window is
     256x256 starting at 0,0.
 @option opts [Boolean] allow_popups when true, the popup blocker is
     disabled; this is sometimes necessary when driving a Web UI via
     JavaScript
 @option opts [Boolean] headless if true, Chrome runs without any dependency
     on a display server
 @option opts [String] chrome_binary path to the Chrome binary to be used;
     by default, the path is automatically detected
 Starts the browser process.

 @return [WebkitRemote::Browser] master session to the started Browser
     process; the session's auto_close is set to false so that it can be
     safely discarded; nil if the launch fails