From 1d583e17f462bb39f5934a519ce43f4a2a4cc804 Mon Sep 17 00:00:00 2001 From: hackademix Date: Tue, 1 Sep 2020 00:56:17 +0200 Subject: [PATCH] Skip soft reload if not needed. --- src/content/syncFetchPolicy.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/content/syncFetchPolicy.js b/src/content/syncFetchPolicy.js index e98462d..c8d5435 100644 --- a/src/content/syncFetchPolicy.js +++ b/src/content/syncFetchPolicy.js @@ -19,6 +19,7 @@ // Mozilla has already parsed the element, we must take extra steps... let softReloading = true; + let suppressedScripts = 0; debug("Early parsing: preemptively suppressing events and script execution."); try { @@ -57,7 +58,7 @@ } let {readyState} = document; - debug("Readystate: %s, canScript: ", readyState, ns.canScript); + debug("Readystate: %s, %suppressedScripts %s, canScript = %s", readyState, suppressedScripts, ns.canScript); if (!ns.canScript) { for (let node of document.querySelectorAll("*")) { let evAttrs = [...node.attributes].filter(a => a.name.toLowerCase().startsWith("on")); @@ -71,6 +72,13 @@ return; } + if (suppressedScripts === 0 && readyState === "loading") { + // we don't care reloading, if no script has been suppressed + // and no readyState change has been fired yet + softReloading = false; + return; + } + let softReload = ev => { let html = document.documentElement.outerHTML; try { @@ -143,7 +151,8 @@ debug(e.type, e.target, softReloading); // DEV_ONLY if (softReloading) { e.preventDefault(); - debug("Blocked early script", e.target); + ++suppressedScripts; + debug(`Suppressed early script #${suppressedScripts}`, e.target); } else { removeEventListener(e.type, scriptSuppressor); }