diff options
Diffstat (limited to 'bg/ResponseProcessor.js')
-rw-r--r-- | bg/ResponseProcessor.js | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/bg/ResponseProcessor.js b/bg/ResponseProcessor.js index 2c613c9..078f38a 100644 --- a/bg/ResponseProcessor.js +++ b/bg/ResponseProcessor.js @@ -24,7 +24,7 @@ only the "interesting" HTML and script requests and leaving the other alone */ -let {ResponseMetaData} = require("./ResponseMetaData"); +let { ResponseMetaData } = require("./ResponseMetaData"); let listeners = new WeakMap(); let webRequestEvent = browser.webRequest.onHeadersReceived; @@ -34,13 +34,13 @@ class ResponseProcessor { static install(handler, types = ["main_frame", "sub_frame", "script"]) { if (listeners.has(handler)) return false; let listener = - async request => await new ResponseTextFilter(request).process(handler); + async request => await new ResponseTextFilter(request).process(handler); listeners.set(handler, listener); webRequestEvent.addListener( - listener, - {urls: ["<all_urls>"], types}, - ["blocking", "responseHeaders"] - ); + listener, + { urls: ["<all_urls>"], types }, + ["blocking", "responseHeaders"] + ); return true; } @@ -54,15 +54,15 @@ class ResponseProcessor { Object.assign(ResponseProcessor, { // control flow values to be returned by handler.pre() callbacks - ACCEPT: {}, - REJECT: {cancel: true}, - CONTINUE: null + ACCEPT: {}, + REJECT: { cancel: true }, + CONTINUE: null }); class ResponseTextFilter { constructor(request) { this.request = request; - let {type, statusCode} = request; + let { type, statusCode } = request; let md = this.metaData = new ResponseMetaData(request); this.canProcess = // we want to process html documents and scripts only (statusCode < 300 || statusCode >= 400) && // skip redirections @@ -72,8 +72,8 @@ class ResponseTextFilter { 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 + let { metaData, request } = this; + let response = { request, metaData }; // we keep it around allowing callbacks to store state if (typeof handler.pre === "function") { let res = await handler.pre(response); if (res) return res; @@ -81,7 +81,7 @@ class ResponseTextFilter { if (typeof handler !== "function") return ResponseProcessor.ACCEPT; } - let {requestId, responseHeaders} = request; + let { requestId, responseHeaders } = request; let filter = browser.webRequest.filterResponseData(requestId); let buffer = []; @@ -103,10 +103,10 @@ class ResponseTextFilter { console.debug("Warning: zeroes in bytestream, probable cached encoding mismatch.", request); if (request.type === "script") { console.debug("It's a script, trying to refetch it."); - response.text = await (await fetch(request.url, {cache: "reload", credentials: "include"})).text(); + 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, {stream: true}); + response.text = new TextDecoder("utf-16be").decode(allBytes, { stream: true }); } } else { response.text = metaData.decode(allBytes); @@ -114,7 +114,7 @@ class ResponseTextFilter { let editedText = null; try { editedText = await handler(response); - } catch(e) { + } catch (e) { console.error(e); } if (editedText !== null) { |