Garth Humphreys
Garth Humphreys

Reputation: 823

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!

Upvotes: 7

Views: 2934

Answers (1)

serg
serg

Reputation: 111325

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.

Upvotes: 7

Related Questions