docs: Update webRequest API

This commit is contained in:
Cheng Zhao 2015-12-12 15:45:02 +08:00
parent ab14a4466d
commit 56c1f04a51

View file

@ -294,9 +294,8 @@ The `filter` is an object that has an `urls` property, which is an Array of URL
patterns that will be used to filter out the requests that do not match the URL 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. 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 For certain events the `listener` is passed with a `callback`, which should be
how to handle the request, users can specify the `cancel` property to `true` to called with an `response` object when `listener` has done its work.
cancel the request.
```javascript ```javascript
// Modify the user agent for all requests to the following urls. // Modify the user agent for all requests to the following urls.
@ -304,9 +303,9 @@ var filter = {
urls: ["https://*.github.com/*", "*://electron.github.io"] 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"; details.requestHeaders['User-Agent'] = "MyAgent";
return {cancel: false, requestHeaders: details.requestHeaders}; callback({cancel: false, requestHeaders: details.requestHeaders});
}); });
``` ```
@ -315,8 +314,8 @@ session.defaultSession.webRequest.onBeforeSendHeaders(filter, function(details)
* `filter` Object * `filter` Object
* `listener` Function * `listener` Function
The `listener` will be called with `listener(details)` when a request is about The `listener` will be called with `listener(details, callback)` when a request
to occur. is about to occur.
* `details` Object * `details` Object
* `id` Integer * `id` Integer
@ -325,7 +324,7 @@ to occur.
* `resourceType` String * `resourceType` String
* `timestamp` Double * `timestamp` Double
The `listener` has to return an `response` object: The `callback` has to be called with an `response` object:
* `response` Object * `response` Object
* `cancel` Boolean __optional__ * `cancel` Boolean __optional__
@ -337,9 +336,9 @@ The `listener` has to return an `response` object:
* `filter` Object * `filter` Object
* `listener` Function * `listener` Function
The `listener` will be called with `listener(details)` before sending an HTTP The `listener` will be called with `listener(details, callback)` before sending
request, once the request headers are available. This may occur after a TCP an HTTP request, once the request headers are available. This may occur after a
connection is made to the server, but before any http data is sent. TCP connection is made to the server, but before any http data is sent.
* `details` Object * `details` Object
* `id` Integer * `id` Integer
@ -349,7 +348,7 @@ connection is made to the server, but before any http data is sent.
* `timestamp` Double * `timestamp` Double
* `requestHeaders` Object * `requestHeaders` Object
The `listener` has to return an `response` object: The `callback` has to be called with an `response` object:
* `response` Object * `response` Object
* `cancel` Boolean __optional__ * `cancel` Boolean __optional__
@ -378,8 +377,8 @@ response are visible by the time this listener is fired.
* `filter` Object * `filter` Object
* `listener` Function * `listener` Function
The `listener` will be called with `listener(details)` when HTTP response The `listener` will be called with `listener(details, callback)` when HTTP
headers of a request have been received. response headers of a request have been received.
* `details` Object * `details` Object
* `id` String * `id` String
@ -391,7 +390,7 @@ headers of a request have been received.
* `statusCode` Integer * `statusCode` Integer
* `responseHeaders` Object * `responseHeaders` Object
The `listener` has to return an `response` object: The `callback` has to be called with an `response` object:
* `response` Object * `response` Object
* `cancel` Boolean * `cancel` Boolean