From 1ead91d2aa0e9029327c3e0817d51f03777b31ae Mon Sep 17 00:00:00 2001 From: hackademix Date: Fri, 18 Oct 2019 22:43:08 +0200 Subject: Support for safe asynchronous page loading without fallback reloads. --- src/content/staticNS.js | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) (limited to 'src/content') diff --git a/src/content/staticNS.js b/src/content/staticNS.js index e5aaf3c..a175220 100644 --- a/src/content/staticNS.js +++ b/src/content/staticNS.js @@ -55,36 +55,25 @@ let url = document.URL; let isFileUrl = url.startsWith("file:"); if (isFileUrl) { - let cookie = "noscript.startupFileReloaded=true"; - if (!document.cookie.split(/\s*;\s*/).includes(cookie)) { - stopAndReload(() => document.cookie = cookie); - } + addEventListener("beforescriptexecute", e => { + if (!this.canScript) e.preventDefault(); + }, true); } let policy = browser.runtime.sendSyncMessage( {id: "fetchPolicy", url, contextUrl: url}); debug("Fetched %o, readyState %s", policy, document.readyState); - if (!policy) { - debug("Could not fetch policy!"); - if (isFileUrl && !sessionStorage.__noScriptFallbackReload__) { - sessionStorage.__noScriptFallbackReload__ = "true"; - stopAndReload(); - } - // let's try asynchronously - (async () => { - this.setup(await Messages.send("fetchPolicy", {url, contextUrl: url})); - })(); - return false; - } else if (policy.fallback) { - stopAndReload(); - } this.setup(policy); + return true; }, setup(policy) { debug("%s, %s, %o", document.URL, document.readyState, policy); + if (!policy) { + policy = {permissions: {capabilities: []}, localFallback: true}; + } this.policy = policy; if (!policy.permissions || policy.unrestricted) { -- cgit v1.2.3