Fixed infinite reload loops on scripting permissions mismatches.
This commit is contained in:
parent
391c8b402a
commit
d88a0cf6d7
|
@ -269,7 +269,7 @@ var RequestGuard = (() => {
|
||||||
let records = TabStatus.map.get(tabId);
|
let records = TabStatus.map.get(tabId);
|
||||||
let noscriptFrames = records && records.noscriptFrames;
|
let noscriptFrames = records && records.noscriptFrames;
|
||||||
let canScript = !(noscriptFrames && noscriptFrames[sender.frameId]);
|
let canScript = !(noscriptFrames && noscriptFrames[sender.frameId]);
|
||||||
let shouldScript = ns.isEnforced(tabId) && ns.policy.can(url, "script");
|
let shouldScript = !ns.isEnforced(tabId) || ns.policy.can(url, "script");
|
||||||
debug("Frame %s %s of %o, canScript: %s, shouldScript: %s", frameId, url, noscriptFrames, canScript, shouldScript);
|
debug("Frame %s %s of %o, canScript: %s, shouldScript: %s", frameId, url, noscriptFrames, canScript, shouldScript);
|
||||||
return {canScript, shouldScript};
|
return {canScript, shouldScript};
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,11 +87,15 @@ let notifyPage = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
var queryingCanScript = false;
|
var queryingCanScript = false;
|
||||||
var caps = {};
|
|
||||||
|
function reload(noCache = false) {
|
||||||
|
init = () => {};
|
||||||
|
location.reload(noCache);
|
||||||
|
}
|
||||||
|
|
||||||
async function init(oldPage = false) {
|
async function init(oldPage = false) {
|
||||||
if (queryingCanScript) return;
|
if (queryingCanScript) return;
|
||||||
if (document.URL === "about:blank") {
|
if (!document.URL.startsWith("http")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
queryingCanScript = true;
|
queryingCanScript = true;
|
||||||
|
@ -105,12 +109,13 @@ async function init(oldPage = false) {
|
||||||
if (canScript) {
|
if (canScript) {
|
||||||
if (oldPage) {
|
if (oldPage) {
|
||||||
probe();
|
probe();
|
||||||
setTimeout(() => init(), 100);
|
setTimeout(() => init(), 200);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!shouldScript) {
|
if (!shouldScript) {
|
||||||
// Something wrong: scripts can run, permissions say they shouldn't.
|
// Something wrong: scripts can run, permissions say they shouldn't.
|
||||||
// Was webRequest bypassed by caching/session restore/service workers?
|
// Was webRequest bypassed by caching/session restore/service workers?
|
||||||
|
window.stop();
|
||||||
let noCache = !!navigator.serviceWorker.controller;
|
let noCache = !!navigator.serviceWorker.controller;
|
||||||
if (noCache) {
|
if (noCache) {
|
||||||
for (let r of await navigator.serviceWorker.getRegistrations()) {
|
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");
|
debug("Reloading %s (%s)", document.URL, noCache ? "no cache" : "cached");
|
||||||
location.reload(noCache);
|
reload(noCache);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -129,7 +134,8 @@ async function init(oldPage = false) {
|
||||||
if (!oldPage &&
|
if (!oldPage &&
|
||||||
/Receiving end does not exist/.test(e.message)) {
|
/Receiving end does not exist/.test(e.message)) {
|
||||||
// probably startup and bg page not ready yet, hence no CSP: reload!
|
// probably startup and bg page not ready yet, hence no CSP: reload!
|
||||||
location.reload(false);
|
debug("Reloading", document.URL);
|
||||||
|
reload();
|
||||||
} else {
|
} else {
|
||||||
setTimeout(() => init(oldPage), 100);
|
setTimeout(() => init(oldPage), 100);
|
||||||
}
|
}
|
||||||
|
@ -162,4 +168,4 @@ async function init(oldPage = false) {
|
||||||
// document.write("<plaintext>");
|
// document.write("<plaintext>");
|
||||||
}
|
}
|
||||||
notifyPage() || addEventListener("pageshow", notifyPage);
|
notifyPage() || addEventListener("pageshow", notifyPage);
|
||||||
};
|
}
|
||||||
|
|
Loading…
Reference in New Issue