module Selenium::WebDriver::DriverExtensions::HasAuthentication
def auth_handlers
def auth_handlers @auth_handlers ||= [] end
def authenticate(request_id, url)
def authenticate(request_id, url) credentials = auth_handlers.find do |handler| url.match?(handler[:uri]) end if credentials devtools.fetch.continue_with_auth( request_id: request_id, auth_challenge_response: { response: 'ProvideCredentials', username: credentials[:username], password: credentials[:password] } ) else devtools.fetch.continue_with_auth( request_id: request_id, auth_challenge_response: { response: 'CancelAuth' } ) end end
def register(username:, password:, uri: //)
def register(username:, password:, uri: //) auth_handlers << {username: username, password: password, uri: uri} devtools.network.set_cache_disabled(cache_disabled: true) devtools.fetch.on(:auth_required) do |params| authenticate(params['requestId'], params.dig('request', 'url')) end devtools.fetch.on(:request_paused) do |params| devtools.fetch.continue_request(request_id: params['requestId']) end devtools.fetch.enable(handle_auth_requests: true) end