From 7c77a1f9130c5ad0d6186defafea0ec5e809c268 Mon Sep 17 00:00:00 2001 From: hackademix Date: Tue, 16 Feb 2021 22:43:55 +0100 Subject: [PATCH] Fixed race condition causing noscript elements not to be rendered sometimes. --- src/content/content.js | 1 - src/content/onScriptDisabled.js | 8 ++++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/content/content.js b/src/content/content.js index 62a6ada..2f37eeb 100644 --- a/src/content/content.js +++ b/src/content/content.js @@ -115,7 +115,6 @@ let documentOrigin = new URL(document.URL).origin; window.addEventListener("securitypolicyviolation", e => { if (!e.isTrusted) return; let {violatedDirective, originalPolicy} = e; - if (violatedDirective.startsWith(`script-src`) && originalPolicy.includes("script-src 'none'")) onScriptDisabled(); let type = violatedDirective.split("-", 1)[0]; // e.g. script-src 'none' => script let url = e.blockedURI; diff --git a/src/content/onScriptDisabled.js b/src/content/onScriptDisabled.js index 76a5d83..c57188d 100644 --- a/src/content/onScriptDisabled.js +++ b/src/content/onScriptDisabled.js @@ -4,17 +4,17 @@ function onScriptDisabled() { onScriptDisabled = () => {}; - let emulateNoScriptElement = () => { + let emulateNoscriptElement = () => { if (ns.allows("noscript")) { NoscriptElements.emulate(true); } }; - + debug("onScriptDisabled", document.readyState, new Error().stack); if (document.readyState === "loading") { - window.addEventListener("DOMContentLoaded", emulateNoScriptElement, true); + window.addEventListener("DOMContentLoaded", emulateNoscriptElement, true); return; } else { - emulateNoScriptElement(); + emulateNoscriptElement(); } let eraser = {