module DEBUGGER__::UI_CDP

def send_chrome_response req

def send_chrome_response req
  @repl = false
  case req
  when /^GET\s\/json\/version\sHTTP\/1.1/
    body = {
      Browser: "ruby/v#{RUBY_VERSION}",
      'Protocol-Version': "1.1"
    }
    send_http_res body
    raise UI_ServerBase::RetryConnection
  when /^GET\s\/json\sHTTP\/1.1/
    @uuid = @uuid || SecureRandom.uuid
    addr = @local_addr.inspect_sockaddr
    body = [{
      description: "ruby instance",
      devtoolsFrontendUrl: "devtools://devtools/bundled/inspector.html?experiments=true&v8only=true&ws=#{addr}/#{@uuid}",
      id: @uuid,
      title: $0,
      type: "node",
      url: "file://#{File.absolute_path($0)}",
      webSocketDebuggerUrl: "ws://#{addr}/#{@uuid}"
    }]
    send_http_res body
    raise UI_ServerBase::RetryConnection
  when /^GET\s\/(\w{8}-\w{4}-\w{4}-\w{4}-\w{12})\sHTTP\/1.1/
    raise 'Incorrect uuid' unless $1 == @uuid
    @need_pause_at_first = false
    CONFIG.set_config no_color: true
    @ws_server = WebSocketServer.new(@sock)
    @ws_server.handshake
  end
end