diff options
author | hackademix | 2018-07-25 11:08:43 +0200 |
---|---|---|
committer | hackademix | 2018-07-25 11:08:43 +0200 |
commit | d88a0cf6d76408be4455d8e6a1ba5cb55bd6b8b7 (patch) | |
tree | 1f6c82409b6fd43cd92ddcdffda2fea6125bbb47 /src/content | |
parent | 391c8b402a2a1a103db8f232ecde65410f82c9ef (diff) | |
download | noscript-d88a0cf6d76408be4455d8e6a1ba5cb55bd6b8b7.tar.gz noscript-d88a0cf6d76408be4455d8e6a1ba5cb55bd6b8b7.tar.xz noscript-d88a0cf6d76408be4455d8e6a1ba5cb55bd6b8b7.zip |
Fixed infinite reload loops on scripting permissions mismatches.
Diffstat (limited to 'src/content')
-rw-r--r-- | src/content/content.js | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/content/content.js b/src/content/content.js index a2bb4d9..dd847f0 100644 --- a/src/content/content.js +++ b/src/content/content.js @@ -87,11 +87,15 @@ let notifyPage = () => { } var queryingCanScript = false; -var caps = {}; + +function reload(noCache = false) { + init = () => {}; + location.reload(noCache); +} async function init(oldPage = false) { if (queryingCanScript) return; - if (document.URL === "about:blank") { + if (!document.URL.startsWith("http")) { return; } queryingCanScript = true; @@ -105,12 +109,13 @@ async function init(oldPage = false) { if (canScript) { if (oldPage) { probe(); - setTimeout(() => init(), 100); + setTimeout(() => init(), 200); return; } if (!shouldScript) { // Something wrong: scripts can run, permissions say they shouldn't. // Was webRequest bypassed by caching/session restore/service workers? + window.stop(); let noCache = !!navigator.serviceWorker.controller; if (noCache) { for (let r of await navigator.serviceWorker.getRegistrations()) { @@ -118,7 +123,7 @@ async function init(oldPage = false) { } } debug("Reloading %s (%s)", document.URL, noCache ? "no cache" : "cached"); - location.reload(noCache); + reload(noCache); return; } } @@ -129,7 +134,8 @@ async function init(oldPage = false) { if (!oldPage && /Receiving end does not exist/.test(e.message)) { // probably startup and bg page not ready yet, hence no CSP: reload! - location.reload(false); + debug("Reloading", document.URL); + reload(); } else { setTimeout(() => init(oldPage), 100); } @@ -162,4 +168,4 @@ async function init(oldPage = false) { // document.write("<plaintext>"); } notifyPage() || addEventListener("pageshow", notifyPage); -}; +} |