Fired when the server sends a 401
or 407
status code (that is, when the server is asking the client to provide authentication credentials, such as a username and password).
The listener can respond in one of four different ways:
- Take no action
-
The listener can do nothing, just observing the request. If this happens, it will have no effect on the handling of the request, and the browser will probably just ask the user to log in.
- Cancel the request
-
The listener can cancel the request. If they do this, then authentication will fail, and the user will not be asked to log in. Extensions can cancel requests as follows:
- in addListener, pass
"blocking"
in theextraInfoSpec
parameter - in the listener itself, return an object with a
cancel
property set totrue
- in addListener, pass
- Provide credentials synchronously
-
If credentials are available synchronously, the extension can supply them synchronously. If the extension does this, then the browser will attempt to log in with the given credentials. The listener can provide credentials synchronously as follows:
- in addListener, pass
"blocking"
in theextraInfoSpec
parameter - in the listener, return an object with an
authCredentials
property set to the credentials to supply
- in addListener, pass
- Provide credentials asynchronously
-
The extension might need to fetch credentials asynchronously. For example, the extension might need to fetch credentials from storage, or ask the user. In this case, the listener can supply credentials asynchronously as follows:
- in addListener, pass
"blocking"
in theextraInfoSpec
parameter - in the listener, return a
Promise
that is resolved with an object containing anauthCredentials
property, set to the credentials to supply
- in addListener, pass
See Examples.
If you use "blocking"
you must have the "webRequestBlocking" API permission in your manifest.json
.
If your extension provides bad credentials, then the listener will be called again. For this reason, take care not to enter an infinite loop by repeatedly providing bad credentials.