How to track DOM change in chrome extension?

Updated for 2020:

The recommended way nowadays is to use the Mutation Observer API.

 let observer = new MutationObserver(mutations => {
    for(let mutation of mutations) {
         for(let addedNode of mutation.addedNodes) {
             if (addedNode.nodeName === "IMG") {
                 console.log("Inserted image", addedNode);
              }
          }
     }
 });
 observer.observe(document, { childList: true, subtree: true });

Leave a Comment