Fixed race condition causing noscript elements not to be rendered sometimes.

This commit is contained in:
hackademix 2021-02-16 22:43:55 +01:00
parent 54e4671463
commit 7c77a1f913
2 changed files with 4 additions and 5 deletions

View File

@ -115,7 +115,6 @@ let documentOrigin = new URL(document.URL).origin;
window.addEventListener("securitypolicyviolation", e => { window.addEventListener("securitypolicyviolation", e => {
if (!e.isTrusted) return; if (!e.isTrusted) return;
let {violatedDirective, originalPolicy} = e; 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 type = violatedDirective.split("-", 1)[0]; // e.g. script-src 'none' => script
let url = e.blockedURI; let url = e.blockedURI;

View File

@ -4,17 +4,17 @@
function onScriptDisabled() { function onScriptDisabled() {
onScriptDisabled = () => {}; onScriptDisabled = () => {};
let emulateNoScriptElement = () => { let emulateNoscriptElement = () => {
if (ns.allows("noscript")) { if (ns.allows("noscript")) {
NoscriptElements.emulate(true); NoscriptElements.emulate(true);
} }
}; };
debug("onScriptDisabled", document.readyState, new Error().stack);
if (document.readyState === "loading") { if (document.readyState === "loading") {
window.addEventListener("DOMContentLoaded", emulateNoScriptElement, true); window.addEventListener("DOMContentLoaded", emulateNoscriptElement, true);
return; return;
} else { } else {
emulateNoScriptElement(); emulateNoscriptElement();
} }
let eraser = { let eraser = {