diff options
author | hackademix | 2019-10-01 22:37:13 +0200 |
---|---|---|
committer | hackademix | 2019-10-01 22:37:28 +0200 |
commit | e3c09d4dc014985bd90bfe6acde1a434bf65ff9b (patch) | |
tree | 0ba7f463148afc4f5b025c07d9587489c38f59fe /src/content/staticNS.js | |
parent | a9a85a5c22b5ccae57498bdb649459f546c433bb (diff) | |
download | noscript-e3c09d4dc014985bd90bfe6acde1a434bf65ff9b.tar.gz noscript-e3c09d4dc014985bd90bfe6acde1a434bf65ff9b.tar.xz noscript-e3c09d4dc014985bd90bfe6acde1a434bf65ff9b.zip |
Handle edge-case policy retrieval for file:// pages loaded by session restore on startup and alike.
Diffstat (limited to 'src/content/staticNS.js')
-rw-r--r-- | src/content/staticNS.js | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/src/content/staticNS.js b/src/content/staticNS.js index bf91972..3102756 100644 --- a/src/content/staticNS.js +++ b/src/content/staticNS.js @@ -34,18 +34,47 @@ }, fetchPolicy() { + debug(`Fetching policy from document %s, readyState %s, content %s`, + document.URL, document.readyState, document.documentElement.outerHTML); + let url = document.URL; + + if (url.startsWith("file:")) { + let cookie = "noscript.startupFileReloaded=true"; + if (!document.cookie.split(/\s*;\s*/).includes(cookie)) { + stop(); + setTimeout(() => { + document.cookie = cookie; + location.reload(); + }, 10) + } + } + let policy = browser.runtime.sendSyncMessage( - {id: "fetchPolicy", url, contextUrl: document.URL}); + {id: "fetchPolicy", url, contextUrl: url}); + + debug("Fetched %o, readyState %s", policy, document.readyState); if (!policy) { - debug(`No answer to fetchPolicy message. This should not be happening.`); + debug("Could not fetch policy!"); + if (url.startsWith("file:") && !sessionStorage.__noScriptFallbackReload__) { + sessionStorage.__noScriptFallbackReload__ = "true"; + location.reload(); + } else { + // let's try asynchronously + (async () => { + this.setup(await Messages.send("fetchPolicy", {url, contextUrl: url})); + })(); + } return false; + } else if (policy.fallback) { + location.reload(); } this.setup(policy); return true; }, setup(policy) { + debug("%s, %s, %o", document.URL, document.readyState, policy); this.policy = policy; if (!policy.permissions || policy.unrestricted) { |