patterns that will be used to filter out the requests that do not match the URL
patterns. If the `filter` is omitted then all requests will be matched.
-For certain events the `listener` is required to return an object that describes
-how to handle the request, users can specify the `cancel` property to `true` to
-cancel the request.
+For certain events the `listener` is passed with a `callback`, which should be
+called with an `response` object when `listener` has done its work.
```javascript
// Modify the user agent for all requests to the following urls.
urls: ["https://*.github.com/*", "*://electron.github.io"]
};
-session.defaultSession.webRequest.onBeforeSendHeaders(filter, function(details) {
+session.defaultSession.webRequest.onBeforeSendHeaders(filter, function(details, callback) {
details.requestHeaders['User-Agent'] = "MyAgent";
- return {cancel: false, requestHeaders: details.requestHeaders};
+ callback({cancel: false, requestHeaders: details.requestHeaders});
});
```
* `filter` Object
* `listener` Function
-The `listener` will be called with `listener(details)` when a request is about
-to occur.
+The `listener` will be called with `listener(details, callback)` when a request
+is about to occur.
* `details` Object
* `id` Integer
* `resourceType` String
* `timestamp` Double
-The `listener` has to return an `response` object:
+The `callback` has to be called with an `response` object:
* `response` Object
* `cancel` Boolean __optional__
* `filter` Object
* `listener` Function
-The `listener` will be called with `listener(details)` 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.
+The `listener` will be called with `listener(details, callback)` 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.
* `details` Object
* `id` Integer
* `timestamp` Double
* `requestHeaders` Object
-The `listener` has to return an `response` object:
+The `callback` has to be called with an `response` object:
* `response` Object
* `cancel` Boolean __optional__
* `filter` Object
* `listener` Function
-The `listener` will be called with `listener(details)` when HTTP response
-headers of a request have been received.
+The `listener` will be called with `listener(details, callback)` when HTTP
+response headers of a request have been received.
* `details` Object
* `id` String
* `statusCode` Integer
* `responseHeaders` Object
-The `listener` has to return an `response` object:
+The `callback` has to be called with an `response` object:
* `response` Object
* `cancel` Boolean