diff options
author | hackademix | 2019-04-08 13:08:17 +0200 |
---|---|---|
committer | hackademix | 2019-04-08 13:08:17 +0200 |
commit | a489c192d6ab3bc70cf6af90f4a60c04a2a76a9d (patch) | |
tree | 5dff76fa5c306296688b0fd694e8a3a60bd10564 /src/bg/RequestGuard.js | |
parent | 5ffd53ee89767e1ca08d41516e968aab06cf42d3 (diff) | |
download | noscript-a489c192d6ab3bc70cf6af90f4a60c04a2a76a9d.tar.gz noscript-a489c192d6ab3bc70cf6af90f4a60c04a2a76a9d.tar.xz noscript-a489c192d6ab3bc70cf6af90f4a60c04a2a76a9d.zip |
Make RequestGuard's header processing synchronous on non-supporting browsers.
Diffstat (limited to 'src/bg/RequestGuard.js')
-rw-r--r-- | src/bg/RequestGuard.js | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/bg/RequestGuard.js b/src/bg/RequestGuard.js index c1771aa..bdf2ea2 100644 --- a/src/bg/RequestGuard.js +++ b/src/bg/RequestGuard.js @@ -296,7 +296,9 @@ var RequestGuard = (() => { } return ALLOW; }, - async onHeadersReceived(request) { + onHeadersReceived(request) { + let result = ALLOW; + let promises = []; // called for main_frame, sub_frame and object // check for duplicate calls let headersModified = false; @@ -324,7 +326,7 @@ var RequestGuard = (() => { if (isMainFrame) { if (policy.autoAllowTop && perms === policy.DEFAULT) { policy.set(Sites.optimalKey(url), perms = policy.TRUSTED.tempTwin); - await ChildPolicies.update(policy); + promises.push(ChildPolicies.update(policy)); } capabilities = perms.capabilities; } else { @@ -360,12 +362,16 @@ var RequestGuard = (() => { headersModified = true; } if (headersModified) { - return {responseHeaders}; + result = {responseHeaders}; } } catch (e) { error(e, "Error in onHeadersReceived", request); } - return ALLOW; + promises = promises.filter(p => p instanceof Promise); + if (promises.length > 0) { + return Promise.all(promises).then(() => result); + } + return result; }, onResponseStarted(request) { debug("onResponseStarted", request); |