module ChromeRemote

Constants

DEFAULT_OPTIONS
VERSION

Public Class Methods

client(options = {}) click to toggle source
# File lib/chrome_remote.rb, line 15
def client(options = {})
  options = DEFAULT_OPTIONS.merge(options)
  logger = options.delete(:logger)

  Client.new(get_ws_url(options), logger)
end

Private Class Methods

get_ws_url(options) click to toggle source
# File lib/chrome_remote.rb, line 24
def get_ws_url(options)
  path = '/json'
  path += '/new?about:blank'  if options.key?(:new_tab)

  response = Net::HTTP.get(options[:host], path, options[:port])
  response = JSON.parse(response)

  raise ChromeConnectionError unless response.any?

  return response['webSocketDebuggerUrl'] if options.key?(:new_tab)

  first_page = response.find {|e| e["type"] == "page"}

  raise ChromeConnectionError unless first_page

  first_page["webSocketDebuggerUrl"]
rescue ChromeConnectionError
  try ||= 0
  try += 1

  # Wait up to 5 seconds for Chrome to start fully
  if try <= 50
    sleep 0.1
    retry
  end
end