Prevent multiple canScript content messages during the same page load.

This commit is contained in:
hackademix 2018-07-20 23:30:14 +02:00
parent 9382bbd911
commit 570cf0456c
1 changed files with 9 additions and 1 deletions

View File

@ -72,16 +72,24 @@ let notifyPage = () => {
return false;
}
var queryingCanScript = false;
async function init() {
if (queryingCanScript) return;
queryingCanScript = true;
debug(`NoScript init() called in document %s, scripting=%s, content type %s readyState %s`,
document.URL, canScript, document.contentType, document.readyState);
try {
canScript = await browser.runtime.sendMessage({type: "canScript"});
init = () => {};
debug("canScript:", canScript);
} catch (e) {
debug("Error querying canScript", e);
// background script not initialized yet?
setTimeout(() => init(), 100);
return;
} finally {
queryingCanScript = false;
}
if (!canScript) onScriptDisabled();