ChromeWebRequest class
class ChromeWebRequest extends ChromeApi { static final JsObject _webRequest = chrome['webRequest']; ChromeWebRequest._(); bool get available => _webRequest != null; /** * The maximum number of times that `handlerBehaviorChanged` can be called per * 10 minute sustained interval. `handlerBehaviorChanged` is an expensive * function call that shouldn't be called often. */ int get MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES => _webRequest['MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES']; /** * Needs to be called when the behavior of the webRequest handlers has changed * to prevent incorrect handling due to caching. This function call is * expensive. Don't call it often. */ Future handlerBehaviorChanged() { if (_webRequest == null) _throwNotAvailable(); var completer = new ChromeCompleter.noArgs(); _webRequest.callMethod('handlerBehaviorChanged', [completer.callback]); return completer.future; } /** * Fired when a request is about to occur. */ Stream<Map> get onBeforeRequest => _onBeforeRequest.stream; final ChromeStreamController<Map> _onBeforeRequest = new ChromeStreamController<Map>.oneArg(_webRequest, 'onBeforeRequest', mapify); /** * Fired before sending an HTTP request, once the request headers are * available. This may occur after a TCP connection is made to the server, but * before any HTTP data is sent. */ Stream<Map> get onBeforeSendHeaders => _onBeforeSendHeaders.stream; final ChromeStreamController<Map> _onBeforeSendHeaders = new ChromeStreamController<Map>.oneArg(_webRequest, 'onBeforeSendHeaders', mapify); /** * Fired just before a request is going to be sent to the server * (modifications of previous onBeforeSendHeaders callbacks are visible by the * time onSendHeaders is fired). */ Stream<Map> get onSendHeaders => _onSendHeaders.stream; final ChromeStreamController<Map> _onSendHeaders = new ChromeStreamController<Map>.oneArg(_webRequest, 'onSendHeaders', mapify); /** * Fired when HTTP response headers of a request have been received. */ Stream<Map> get onHeadersReceived => _onHeadersReceived.stream; final ChromeStreamController<Map> _onHeadersReceived = new ChromeStreamController<Map>.oneArg(_webRequest, 'onHeadersReceived', mapify); /** * Fired when an authentication failure is received. The listener has three * options: it can provide authentication credentials, it can cancel the * request and display the error page, or it can take no action on the * challenge. If bad user credentials are provided, this may be called * multiple times for the same request. */ Stream<OnAuthRequiredEvent> get onAuthRequired => _onAuthRequired.stream; final ChromeStreamController<OnAuthRequiredEvent> _onAuthRequired = new ChromeStreamController<OnAuthRequiredEvent>.twoArgs(_webRequest, 'onAuthRequired', _createOnAuthRequiredEvent); /** * Fired when the first byte of the response body is received. For HTTP * requests, this means that the status line and response headers are * available. */ Stream<Map> get onResponseStarted => _onResponseStarted.stream; final ChromeStreamController<Map> _onResponseStarted = new ChromeStreamController<Map>.oneArg(_webRequest, 'onResponseStarted', mapify); /** * Fired when a server-initiated redirect is about to occur. */ Stream<Map> get onBeforeRedirect => _onBeforeRedirect.stream; final ChromeStreamController<Map> _onBeforeRedirect = new ChromeStreamController<Map>.oneArg(_webRequest, 'onBeforeRedirect', mapify); /** * Fired when a request is completed. */ Stream<Map> get onCompleted => _onCompleted.stream; final ChromeStreamController<Map> _onCompleted = new ChromeStreamController<Map>.oneArg(_webRequest, 'onCompleted', mapify); /** * Fired when an error occurs. */ Stream<Map> get onErrorOccurred => _onErrorOccurred.stream; final ChromeStreamController<Map> _onErrorOccurred = new ChromeStreamController<Map>.oneArg(_webRequest, 'onErrorOccurred', mapify); void _throwNotAvailable() { throw new UnsupportedError("'chrome.webRequest' is not available"); } }
Extends
ChromeApi > ChromeWebRequest
Properties
final bool available #
Returns true if the API is available. The common causes of an API not being avilable are:
- a permission is missing in the application's manifest.json file
- the API is defined on a newer version of Chrome then the current runtime
bool get available => _webRequest != null;
final int MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES #
The maximum number of times that handlerBehaviorChanged
can be called per
10 minute sustained interval. handlerBehaviorChanged
is an expensive
function call that shouldn't be called often.
int get MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES => _webRequest['MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES'];
final Stream<OnAuthRequiredEvent> onAuthRequired #
Fired when an authentication failure is received. The listener has three options: it can provide authentication credentials, it can cancel the request and display the error page, or it can take no action on the challenge. If bad user credentials are provided, this may be called multiple times for the same request.
Stream<OnAuthRequiredEvent> get onAuthRequired => _onAuthRequired.stream;
final Stream<Map> onBeforeRedirect #
Fired when a server-initiated redirect is about to occur.
Stream<Map> get onBeforeRedirect => _onBeforeRedirect.stream;
final Stream<Map> onBeforeRequest #
Fired when a request is about to occur.
Stream<Map> get onBeforeRequest => _onBeforeRequest.stream;
final Stream<Map> onBeforeSendHeaders #
Fired before sending an HTTP request, once the request headers are available. This may occur after a TCP connection is made to the server, but before any HTTP data is sent.
Stream<Map> get onBeforeSendHeaders => _onBeforeSendHeaders.stream;
final Stream<Map> onCompleted #
Fired when a request is completed.
Stream<Map> get onCompleted => _onCompleted.stream;
final Stream<Map> onErrorOccurred #
Fired when an error occurs.
Stream<Map> get onErrorOccurred => _onErrorOccurred.stream;
final Stream<Map> onHeadersReceived #
Fired when HTTP response headers of a request have been received.
Stream<Map> get onHeadersReceived => _onHeadersReceived.stream;
final Stream<Map> onResponseStarted #
Fired when the first byte of the response body is received. For HTTP requests, this means that the status line and response headers are available.
Stream<Map> get onResponseStarted => _onResponseStarted.stream;
final Stream<Map> onSendHeaders #
Fired just before a request is going to be sent to the server (modifications of previous onBeforeSendHeaders callbacks are visible by the time onSendHeaders is fired).
Stream<Map> get onSendHeaders => _onSendHeaders.stream;
Methods
Future handlerBehaviorChanged() #
Needs to be called when the behavior of the webRequest handlers has changed to prevent incorrect handling due to caching. This function call is expensive. Don't call it often.
Future handlerBehaviorChanged() { if (_webRequest == null) _throwNotAvailable(); var completer = new ChromeCompleter.noArgs(); _webRequest.callMethod('handlerBehaviorChanged', [completer.callback]); return completer.future; }