Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to track DOM change in chrome extension?

I am writing a chrome extension where I want to fetch all the images exist on a page but some of the images load after some time (may be through ajax) which I could not fetch once the DOM is idle. Is there any way to track the DOM change after the page is loaded?

like image 885
codef0rmer Avatar asked Jan 16 '12 15:01

codef0rmer


People also ask

How do I read a DOM extension in Chrome?

Run the extensionLook for the hello world extension icon in Chrome toolbar and click on it. You should be able to see a window popup containing current tab page h1 dom element value.

What is DOM Mutation?

MutationObserver is a built-in object that observes a DOM element and fires a callback when it detects a change. We'll first take a look at the syntax, and then explore a real-world use case, to see where such thing may be useful.


1 Answers

You can use document.addEventListener with the DOMNodeInserted event. Your callback will have to check each node insertion to see if it is the type of node you are looking for. Something like the following should work.

function nodeInsertedCallback(event) {     console.log(event); }; document.addEventListener('DOMNodeInserted', nodeInsertedCallback); 
like image 161
abraham Avatar answered Sep 24 '22 16:09

abraham