From e9d5477d970b44d26b5bccdad2400e81c3435d84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Wr=C3=B3blewski?= Date: Thu, 22 Feb 2024 19:57:27 +0100 Subject: [PATCH] Run observeDOMChanges after DOMContentLoaded --- src/scriptlets/href-sanitizer.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/scriptlets/href-sanitizer.ts b/src/scriptlets/href-sanitizer.ts index 13057e09d..cc9fc3765 100644 --- a/src/scriptlets/href-sanitizer.ts +++ b/src/scriptlets/href-sanitizer.ts @@ -216,14 +216,16 @@ export function hrefSanitizer( hit(source); }; + const run = () => { + sanitize(selector); + observeDOMChanges(() => sanitize(selector), true); + }; + if (document.readyState === 'loading') { - window.addEventListener('DOMContentLoaded', () => { - sanitize(selector); - }, { once: true }); + window.addEventListener('DOMContentLoaded', run, { once: true }); } else { - sanitize(selector); + run(); } - observeDOMChanges(() => sanitize(selector), true); } hrefSanitizer.names = [