Red*_*ohn 6 javascript google-chrome mutation-observers
我有一个内容脚本,它监听在某些网站上插入文本节点.它在Facebook上工作得很好.脚本未检测到插入的某些文本节点.
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 });
Run Code Online (Sandbox Code Playgroud)
如果我允许记录所有节点类型,我可以在我的日志中看到这些文本节点的父节点.
谢谢.
小智 0
即使调试器在网站上打开,Facebook 也有一种检测方法。我猜他们也有办法检测突变观察者。他们可能只是阻止您的内容脚本。此外,我不会真正使用整个文档作为我的对象。只需尝试使用 document.querySelector 来监视您想要的内容。