summaryrefslogtreecommitdiff
path: root/src/content
diff options
context:
space:
mode:
authorhackademix2019-10-25 23:11:07 +0100
committerhackademix2019-10-25 23:19:48 +0100
commitafe71bb7a47cbdc281f6f1efc4aa4cba42eab99a (patch)
tree70fd309d74435092e429e69162d4e29e3462a147 /src/content
parentd84ff782c249da15352a88923371e714b6bfb0e6 (diff)
downloadnoscript-afe71bb7a47cbdc281f6f1efc4aa4cba42eab99a.tar.gz
noscript-afe71bb7a47cbdc281f6f1efc4aa4cba42eab99a.tar.xz
noscript-afe71bb7a47cbdc281f6f1efc4aa4cba42eab99a.zip
More precise and verbose fallbacks for policy retrieval timing issues.
Diffstat (limited to 'src/content')
-rw-r--r--src/content/staticNS.js21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/content/staticNS.js b/src/content/staticNS.js
index 828663f..eea16de 100644
--- a/src/content/staticNS.js
+++ b/src/content/staticNS.js
@@ -36,10 +36,16 @@
fetchPolicy() {
debug(`Fetching policy from document %s, readyState %s, content %s`,
document.URL, document.readyState, document.documentElement.outerHTML);
+ let originalState = document.readyState;
+ let scriptsBlocked = false;
let url = document.URL;
addEventListener("beforescriptexecute", e => {
// safety net for syncrhonous load on Firefox
- if (!this.canScript) e.preventDefault();
+ if (!this.canScript) {
+ e.preventDefault();
+ scriptsBlocked = true;
+ log("Some script managed to be inserted in the DOM while fetching policy, blocking it.\n", e.target.textContent);
+ }
}, true);
let policy = null;
@@ -50,13 +56,24 @@
break;
} catch (e) {
if (!Messages.isMissingEndpoint(e)) {
+ error(e);
break;
}
- error("Background page ready yet, retrying to fetch policy...")
+ error("Background page not ready yet, retrying to fetch policy...")
}
}
debug("Fetched %o, readyState %s", policy, document.readyState); // DEV_ONLY
this.setup(policy);
+ if (this.canScript && scriptsBlocked &&
+ originalState === "loading" && document.readyState !== originalState) {
+ log("Blocked some scripts on %s even though they are actually permitted by policy.", url)
+ // something went wrong, e.g. with session restore.
+ if (!url.startsWith("http")) {
+ log("Not a HTTP page, reloading %s.", url);
+ window.stop();
+ location.reload(false);
+ }
+ }
return true;
},