Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Attach listener to AJAX event via chrome extension

I want to attach a listener to a AJAX update, so that I can reload my chrome extension. Right now if a user clicks and goes to another section of the site that is loaded via AJAX the extension doesn't show up. This site is not my site, so I don't control the AJAX updating. Thanks!

like image 877
Garth Humphreys Avatar asked Aug 01 '11 19:08

Garth Humphreys


1 Answers

You can't listen to ajax requests (without using experimental api), but you can listen to DOMSubtreeModified event that fires whenever DOM is modified:

document.addEventListener("DOMSubtreeModified", function(event){
        //something on the page has changed
});

Just need to be careful as there might be hundreds of such events firing in seconds when big chunk of page is modified. Might need to implement some delay.

like image 143
serg Avatar answered Sep 28 '22 08:09

serg