From 50d4b4ba0207b7fd7ece2f1797ff87795e5bc064 Mon Sep 17 00:00:00 2001 From: hackademix Date: Wed, 13 Mar 2019 01:06:18 +0100 Subject: Sniffing of charset in tags and BOM. --- bg/ResponseProcessor.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'bg/ResponseProcessor.js') diff --git a/bg/ResponseProcessor.js b/bg/ResponseProcessor.js index d10d46d..1aa89de 100644 --- a/bg/ResponseProcessor.js +++ b/bg/ResponseProcessor.js @@ -106,10 +106,10 @@ class ResponseTextFilter { response.text = await (await fetch(request.url, {cache: "reload", credentials: "include"})).text(); } else { console.debug("It's a %s, trying to decode it as UTF-16.", request.type); - response.text = new TextDecoder("utf-16be").decode(allBytes); + response.text = new TextDecoder("utf-16be").decode(allBytes, {stream: true}); } } else { - response.text = metaData.createDecoder().decode(allBytes, {stream: true}); + response.text = metaData.decode(allBytes); } let editedText = null; try { @@ -122,7 +122,7 @@ class ResponseTextFilter { 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(ResponseMetaData.UTF8BOM, 0); // UTF-8 BOM allBytes.set(encoded, 3); } filter.write(allBytes); -- cgit v1.2.3