diff options
author | hackademix | 2019-10-31 23:52:54 +0100 |
---|---|---|
committer | hackademix | 2019-10-31 23:52:54 +0100 |
commit | 08a41b3a62c8621904e79ed4edf2039fffb45a64 (patch) | |
tree | 48d96157c7f2df9146637e14f23ef9f01868db6a | |
parent | 25fd1727b64635b23207446b671baa59ccfa55dc (diff) | |
download | noscript-08a41b3a62c8621904e79ed4edf2039fffb45a64.tar.gz noscript-08a41b3a62c8621904e79ed4edf2039fffb45a64.tar.xz noscript-08a41b3a62c8621904e79ed4edf2039fffb45a64.zip |
Fixed bug in policy fetching.
-rw-r--r-- | src/bg/main.js | 3 | ||||
-rw-r--r-- | src/content/staticNS.js | 21 |
2 files changed, 19 insertions, 5 deletions
diff --git a/src/bg/main.js b/src/bg/main.js index 7df5b2f..165260c 100644 --- a/src/bg/main.js +++ b/src/bg/main.js @@ -142,7 +142,8 @@ async fetchChildPolicy({url, contextUrl}, sender) { await ns.initializing; - return (this.fetchChildPolicy = this.fetchChildPolicySync)(...arguments); + return (messageHandler.fetchChildPolicy = + messageHandler.fetchChildPolicySync)(...arguments); }, fetchChildPolicySync({url, contextUrl}, sender) { let {tab, frameId} = sender; diff --git a/src/content/staticNS.js b/src/content/staticNS.js index 8f447e7..1d00ecf 100644 --- a/src/content/staticNS.js +++ b/src/content/staticNS.js @@ -35,14 +35,27 @@ fetchPolicy() { let url = document.URL; - if (url.startsWith("http")) { + debug(`Fetching policy from document %s, readyState %s, content %s`, + url, document.readyState, document.documentElement.outerHTML); + + if (!/^(?:file|ftp|https?):/i.test(url)) { (async () => { - this.setup(await Messages.send("fetchChildPolicy", {url, contextUrl: url})); + let policy; + try { + policy = await Messages.send("fetchChildPolicy", {url, contextUrl: url}); + } catch (e) { + console.error("Error while fetching policy", e); + } + if (policy === undefined) { + log("Policy was undefined, retrying in 1/2 sec..."); + setTimeout(() => this.fetchPolicy(), 500); + return; + } + this.setup(policy); })(); return; } - debug(`Fetching policy from document %s, readyState %s, content %s`, - url, document.readyState, document.documentElement.outerHTML); + let originalState = document.readyState; let blockedScripts = []; |