From 0790ad885e82914a68dd6e2f4732515ae6c4602f Mon Sep 17 00:00:00 2001 From: hackademix Date: Tue, 12 Nov 2024 22:26:40 +0100 Subject: [PATCH] Optimized fall-back reporting for non-HTTP documents and included script type. --- src/content/content.js | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/content/content.js b/src/content/content.js index 8bf0491..39a86b4 100644 --- a/src/content/content.js +++ b/src/content/content.js @@ -169,12 +169,13 @@ if (!/^https:/.test(location.protocol)) { // let's emulate them using mutation observers const checked = new Set(); const checkSrc = async (node) => { - if (!('src' in node && node.parentNode)) { + if (!(node.src && node.parentNode)) { return; } const type = node instanceof HTMLMediaElement ? "media" : node instanceof HTMLIFrameElement ? "sub_frame" : node instanceof HTMLObjectElement || node instanceof HTMLEmbedElement ? "object" + : node instanceof HTMLScriptElement ? "script" : ""; if (!type) { return; @@ -199,12 +200,20 @@ if (!/^https:/.test(location.protocol)) { } } }; - const observer = new MutationObserver(mutationsCallback); - observer.observe(document.documentElement, { - childList: true, - subtree: true, - attributeFilter: ["src"], - }); + const watch = () => { + [...document.querySelectorAll("media, video, audio, iframe, frame, object, embed, script")].forEach(checkSrc); + const observer = new MutationObserver(mutationsCallback); + observer.observe(document.documentElement, { + childList: true, + subtree: true, + attributeFilter: ["src"], + }); + } + if (document.readyState === "complete") { + watch(); + } else { + addEventListener("DOMContentLoaded", watch, true); + } } ns.on("capabilities", () => {