Skip to content

Commit

Permalink
Run observeDOMChanges after DOMContentLoaded
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamWr committed Feb 22, 2024
1 parent 303f529 commit e9d5477
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/scriptlets/href-sanitizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down

0 comments on commit e9d5477

Please sign in to comment.