webRequest.StreamFilter.write()
Writes some response data to the output stream.
You can only call this function after the
onstart
event has fired.Syntax
filter.write(
data // ArrayBuffer or Uint8Array
)
Parameters
data
Uint8Array
orArrayBuffer
: array of bytes containing the data to pass to the browser's rendering engine.
Return value
None.
Browser compatibility
Report problems with this compatibility data on GitHubwebextensions-desktop | webextensions-mobile | |||||
---|---|---|---|---|---|---|
write | 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 uses write()
, to replace "Example" in the first chunk of the response with "WebExtension Example".
function listener(details) {
let filter = browser.webRequest.filterResponseData(details.requestId);
let decoder = new TextDecoder("utf-8");
let encoder = new TextEncoder();
filter.ondata = event => {
let str = decoder.decode(event.data, {stream: true});
// Just change any instance of Example in the HTTP response
// to WebExtension Example.
str = str.replace(/Example/g, 'WebExtension Example');
filter.write(encoder.encode(str));
filter.disconnect();
}
//return {}; // not needed
}
browser.webRequest.onBeforeRequest.addListener(
listener,
{urls: ["https://example.com/*"], types: ["main_frame"]},
["blocking"]
);