From 4e140b4b51208ebfa50557f388779ce641b7ca49 Mon Sep 17 00:00:00 2001 From: hackademix Date: Wed, 28 Apr 2021 18:37:20 +0200 Subject: [PATCH] Avoid document rewriting for noscript meta refresh emulation in most cases. --- src/content/onScriptDisabled.js | 24 +++++++++++------------- src/nscl | 2 +- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/content/onScriptDisabled.js b/src/content/onScriptDisabled.js index 282dce6..bdade91 100644 --- a/src/content/onScriptDisabled.js +++ b/src/content/onScriptDisabled.js @@ -2,12 +2,12 @@ "use strict"; function onScriptDisabled() { - onScriptDisabled = () => {}; - - let emulateNoscriptElement = () => { - if (ns.allows("noscript")) { - NoscriptElements.emulate(true); - } else { + onScriptDisabled = () => {}; // call me just once + debug("onScriptDisabled state", document.readyState); + if (ns.allows("noscript")) { + NoscriptElements.emulate(true); + } else { + let reportNoscriptElements = () => { if (document.querySelector("noscript")) { let request = { id: "noscript-noscript", @@ -18,14 +18,12 @@ function onScriptDisabled() { }; seen.record({policyType: "noscript", request, allowed: false}); } + }; + if (document.readyState === "loading") { + window.addEventListener("DOMContentLoaded", reportNoscriptElements, true); + } else { + reportNoscriptElements(); } - }; - debug("onScriptDisabled", document.readyState, new Error().stack); // DEV ONLY - if (document.readyState === "loading") { - window.addEventListener("DOMContentLoaded", emulateNoscriptElement, true); - return; - } else { - emulateNoscriptElement(); } let eraser = { diff --git a/src/nscl b/src/nscl index 1570208..4fb995d 160000 --- a/src/nscl +++ b/src/nscl @@ -1 +1 @@ -Subproject commit 1570208f7a04915063ce7776f61ad3bdca543c17 +Subproject commit 4fb995d4d4683902906bafec460e505565e71c3b