class Selenium::WebDriver::Network

def add_authentication_handler(username, password)

def add_authentication_handler(username, password)
  intercept = @network.add_intercept(phases: [BiDi::Network::PHASES[:auth_required]])
  auth_id = @network.on(:auth_required) do |event|
    request_id = event['requestId']
    @network.continue_with_auth(request_id, username, password)
  end
  @auth_callbacks[auth_id] = intercept
  auth_id
end

def clear_authentication_handlers

def clear_authentication_handlers
  @auth_callbacks.each_key { |id| remove_authentication_handler(id) }
end

def initialize(bridge)

def initialize(bridge)
  @network = BiDi::Network.new(bridge.bidi)
  @auth_callbacks = {}
end

def remove_authentication_handler(id)

def remove_authentication_handler(id)
  intercept = @auth_callbacks[id]
  @network.remove_intercept(intercept['intercept'])
  @auth_callbacks.delete(id)
end