The script above does not work properly. I wanted to replace DOMNodeInserted(Line19) to MutationObserver(line21), but when I used MutationObserver, it does not work.
// Line 19 (works well)
document.body.addEventListener('DOMNodeInserted', function (event) {linkifyContainer(event.target);}, false);
// Line 21 (does not work)
var observer=new window.MutationObserver(function(mutations){mutations.forEach(function(mutation){linkifyContainer(mutation.addedNodes)})});observer.observe(document.body,{childList:true,subtree:true});
There should be something wrong in line 21, but I don't know what the problem is and what I should do.
I checked this with chrome28 and firefox23.
It's an extension of chrome, so I don't have to use "WebKitMutationObserver" or "MozMutationObserver".
Please tell me the solusion.
Your mutation observer code works fine. You are trying to pass
linkifyContaineraNodeListargument (namely,mutation.addedNodes), butlinkifyContainerexpects to be passed a single element.Compare the calls:
and
The second case is a
NodeList, not a single DOM node, as indicated by the plural property name addedNodes.Simply use
mutation.addedNodes[0], or a loop overmutation.addedNodes: