MutationObservers - some added nodes were not detected

I have a content script that listens for the insertion of text nodes into some websites. It works great except on Facebook. Some of the inserted text nodes are not recognized by the script.

script.js

var observer = new MutationObserver(function(mutations) { mutations.forEach(function(mutation) { if (mutation.type === "characterData") { console.log(mutation.target); } else { for (var x = 0; x < mutation.addedNodes.length; x++) { var node = mutation.addedNodes[x]; if (node.nodeType === Node.TEXT_NODE) { console.log(node); } } } }); }); observer.observe(document, { childList: true, subtree: true, characterData: true }); 

If I enable logging of all node types, I can see the parent nodes of these text nodes in my log.

Thanks.

+6
source share
1 answer

Facebook has a detection method even when the debugger opens on a website. I guess they have a way to detect mutation observers. They can simply block your content scripts. In addition, I would not use the entire document as an object. Just try to keep track of what you want using document.querySelector.

0
source

Source: https://habr.com/ru/post/957200/


All Articles