Skip to content

Commit 570cf04

Browse files
committed
Prevent multiple canScript content messages during the same page load.
1 parent 9382bbd commit 570cf04

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

src/content/content.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,24 @@ let notifyPage = () => {
7272
return false;
7373
}
7474

75-
75+
var queryingCanScript = false;
7676
async function init() {
77+
if (queryingCanScript) return;
78+
queryingCanScript = true;
79+
debug(`NoScript init() called in document %s, scripting=%s, content type %s readyState %s`,
80+
document.URL, canScript, document.contentType, document.readyState);
81+
7782
try {
7883
canScript = await browser.runtime.sendMessage({type: "canScript"});
7984
init = () => {};
8085
debug("canScript:", canScript);
8186
} catch (e) {
87+
debug("Error querying canScript", e);
8288
// background script not initialized yet?
8389
setTimeout(() => init(), 100);
8490
return;
91+
} finally {
92+
queryingCanScript = false;
8593
}
8694

8795
if (!canScript) onScriptDisabled();

0 commit comments

Comments
 (0)