我目前正在尝试找出哪个函数使用MutationObserver
修改了DOM。不幸的是,以下代码段不起作用(堆栈跟踪似乎为空)。
var targetNode = document.body;
var config = { attributes: true, childList: true, subtree: true };
var callback = function(mutationsList, observer) {
for(var mutation of mutationsList) {
// The trace unfortunatelly doesn't contain the function
// "addSomeElement", which I am trying to receive at this point.
console.trace();
}
};
var observer = new MutationObserver(callback);
observer.observe(targetNode, config);
其后是一些DOM突变:
function addSomeElement() {
targetNode.appendChild(document.createElement('span'));
}
addSomeElement();
有什么方法可以输出执行实际突变调用的函数(在这种情况下为appendChild
)?