aboutsummaryrefslogtreecommitdiff
path: root/bg/ResponseProcessor.js
diff options
context:
space:
mode:
Diffstat (limited to 'bg/ResponseProcessor.js')
-rw-r--r--bg/ResponseProcessor.js20
1 files changed, 9 insertions, 11 deletions
diff --git a/bg/ResponseProcessor.js b/bg/ResponseProcessor.js
index 4443d90..d10d46d 100644
--- a/bg/ResponseProcessor.js
+++ b/bg/ResponseProcessor.js
@@ -90,8 +90,6 @@ class ResponseTextFilter {
};
filter.onstop = async event => {
-
- let params = {stream: true};
// concatenate chunks
let size = buffer.reduce((sum, chunk, n) => sum + chunk.byteLength, 0)
let allBytes = new Uint8Array(size);
@@ -119,19 +117,19 @@ class ResponseTextFilter {
} catch(e) {
console.error(e);
}
- if (editedText !== null &&
- (metaData.forcedUTF8 && request.type !== "script" ||
- response.text !== editedText)) {
- // if we changed the charset, the text or both, let's re-encode
- filter.write(new TextEncoder().encode(editedText));
- } else {
- // ... otherwise pass all the raw bytes through
- filter.write(allBytes);
+ if (editedText !== null) {
+ // we changed the content, let's re-encode
+ let encoded = new TextEncoder().encode(editedText);
+ // pre-pending the UTF-8 BOM will force the charset per HTML 5 specs
+ allBytes = new Uint8Array(encoded.byteLength + 3);
+ allBytes.set(new Uint8Array([0xEF, 0xBB, 0xBF]), 0); // UTF-8 BOM
+ allBytes.set(encoded, 3);
}
+ filter.write(allBytes);
filter.close();
}
- return metaData.forceUTF8() ? {responseHeaders} : ResponseProcessor.ACCEPT;;
+ return ResponseProcessor.ACCEPT;
}
}