diff options
author | hackademix <giorgio@maone.net> | 2018-09-01 08:31:51 +0200 |
---|---|---|
committer | hackademix <giorgio@maone.net> | 2018-09-01 08:31:51 +0200 |
commit | f6bf59a4ed44ec7323a76b11317f715c929a69b4 (patch) | |
tree | adc49b2f1cd64d2a187d9b964bf29015ca8d6729 /bg | |
parent | b724b4154b248b65fa93180b24d59e6c80b96d3b (diff) |
Moved external licenses check into response pre-processing, in order to avoid filterResponse() as much as possible (fixing issue #11)
Diffstat (limited to 'bg')
-rw-r--r-- | bg/ResponseProcessor.js | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/bg/ResponseProcessor.js b/bg/ResponseProcessor.js index 7c264a4..e3d6c45 100644 --- a/bg/ResponseProcessor.js +++ b/bg/ResponseProcessor.js @@ -33,8 +33,8 @@ class ResponseProcessor { static install(handler, types = ["main_frame", "sub_frame", "script"]) { if (listeners.has(handler)) return false; - let listener = - request => new ResponseTextFilter(request).process(handler); + let listener = + async request => await new ResponseTextFilter(request).process(handler); listeners.set(handler, listener); webRequestEvent.addListener( listener, @@ -70,12 +70,12 @@ class ResponseTextFilter { (type === "script" || /\bhtml\b/i.test(md.contentType)); } - process(handler) { + async process(handler) { if (!this.canProcess) return ResponseProcessor.ACCEPT; let {metaData, request} = this; let response = {request, metaData}; // we keep it around allowing callbacks to store state if (typeof handler.pre === "function") { - let res = handler.pre(response); + let res = await handler.pre(response); if (res) return res; if (handler.post) handler = handler.post; if (typeof handler !== "function") ResponseProcessor.ACCEPT; @@ -101,7 +101,7 @@ class ResponseTextFilter { } catch(e) { console.error(e); } - if (metaData.forcedUTF8 || + if (metaData.forcedUTF8 && request.type !== "script" || editedText !== null && response.text !== editedText) { // if we changed the charset, the text or both, let's re-encode filter.write(new TextEncoder().encode(editedText)); |