browser.webRequest.filterResponseData ondata error
https://github.com/mdn/webextensions-examples/tree/master/http-response code :
function listener(details) {
var filter = browser.webRequest.filterResponseData(details.requestId);
var decoder = new TextDecoder("utf-8");
var encoder = new TextEncoder();
filter.ondata = event => {
var str = decoder.decode(event.data, {stream: true});
console.log( str.length, str);
filter.write(encoder.encode(str));
filter.disconnect();
}
return {};
}
browser.webRequest.onBeforeRequest.addListener(
listener,
{urls: ["<all_urls>"], types: ["xmlhttprequest"]},
["blocking"]
);
console.log( str.length, str);
sometimes, the str is fragmentary .
for example,like this pic:

"alig" it's not the end of response ,but it's end...
the real response is :

The example is pretty lousy. This API is streamed, so filter.ondata is called on chunks of the response, not the full response, but if you call filter.disconnect() you stop the process (only printing the first chunk). This article has a bit better examples: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/webRequest/StreamFilter/ondata.
@dyeray thanks for that link. Coming here from https://stackoverflow.com/questions/46338823, I couldn't figure out why I was only getting the first chunk of data, and if I removed the disconnect(), the response never made it to its original destination.
:heavy_check_mark: added a note to StackOverflow and the top-level MDN docs
No activity within the last three years, closing.