From 570cf0456ce912aa4e331b103c5b1b4a3b5e7dc2 Mon Sep 17 00:00:00 2001 From: hackademix Date: Fri, 20 Jul 2018 23:30:14 +0200 Subject: Prevent multiple canScript content messages during the same page load. --- src/content/content.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/content') diff --git a/src/content/content.js b/src/content/content.js index a74aa0c..fa87ba8 100644 --- a/src/content/content.js +++ b/src/content/content.js @@ -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(); -- cgit v1.2.3