From 826d85274d34d9bee2b24317f03900805616f17d Mon Sep 17 00:00:00 2001 From: hackademix Date: Wed, 16 Sep 2020 00:53:39 +0200 Subject: [PATCH] Better emulation of SVG events. --- src/content/syncFetchPolicy.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/content/syncFetchPolicy.js b/src/content/syncFetchPolicy.js index 5ee2123..3a8e3fc 100644 --- a/src/content/syncFetchPolicy.js +++ b/src/content/syncFetchPolicy.js @@ -44,7 +44,7 @@ debug("Soft reload", ev); // DEV_ONLY try { let doc = window.wrappedJSObject.document; - removeEventListener("DOMContentLoaded", softReload, true); + if (ev) ev.currentTarget.removeEventListener(ev.type, softReload, true); let isDir = document.querySelector("link[rel=stylesheet][href^='chrome:']") && document.querySelector(`base[href^="${url}"]`); @@ -61,6 +61,19 @@ } catch (e) { debug("Can't use document.write(), XML document?", e); try { + let eventSuppressor = ev => { + if (ev.isTrusted) { + debug("Suppressing natural event", ev); + ev.preventDefault(); + ev.stopImmediatePropagation(); + ev.currentTarget.removeEventListener(ev.type, eventSuppressor, true); + } + }; + let svg = document.documentElement instanceof SVGElement; + if (svg) { + document.addEventListener("SVGLoad", eventSuppressor, true); + } + document.addEventListener("DOMContentLoaded", eventSuppressor, true); DocumentFreezer.unfreeze(); let scripts = [], deferred = []; // push deferred scripts, if any, to the end @@ -94,9 +107,9 @@ debug("Replaced", clone); }); } - debug("ALl scripts done, firing completion events."); + debug("All scripts done, firing completion events."); document.dispatchEvent(new Event("readystatechange")); - if (document.documentElement instanceof SVGElement) { + if (svg) { document.documentElement.dispatchEvent(new Event("SVGLoad")); } document.dispatchEvent(new Event("DOMContentLoaded", {