webRequest.StreamFilter.close()
Closes the request. After this is called, no further response data will be passed to the browser's rendering engine and no more filter events will be given to the extension.
Note the difference between this function and disconnect()
. With disconnect()
, the browser will continue to process any further response data, but it won't be accessible through the filter. With close()
, the browser will ignore any response data that hasn't already been passed through to the rendering engine.
You should always call close()
or disconnect()
once you don't need to interact with the response any further.
You can't call this function until after the onstart
event has fired.
Syntax
filter.close()
Parameters
None.
Return value
None.
Browser compatibility
Report problems with this compatibility data on GitHubwebextensions-desktop | webextensions-mobile | |||||
---|---|---|---|---|---|---|
close | ChromeNo supportNo | EdgeNo supportNo | FirefoxFull support57 | OperaNo supportNo | SafariNo supportNo | Firefox for AndroidFull support57 |
Legend
- Full support
- Full support
- No support
- No support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Examples
This example will replace the page content with "replacement text":
function listener(details) {
let filter = browser.webRequest.filterResponseData(details.requestId);
filter.onstart = event => {
console.log("started");
let encoder = new TextEncoder();
filter.write(encoder.encode("replacement content"));
filter.close();
}
}
browser.webRequest.onBeforeRequest.addListener(
listener,
{urls: ["https://example.org/"], types: ["main_frame"]},
["blocking"]
);