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!
Asked
Active
Viewed 2,807 times
7
-
Did you ever have any luck with this? I'm trying to address the same issue for different reasons. I'd really like to catch the content of any responses the browser recieves. There must be a way to do this, because the Developer Toolbar in chrome does it, and I believe it's implemented in javascript. – Omn Dec 20 '13 at 02:13
-
I think answer can help you : http://stackoverflow.com/a/11811558/453767 – Amit Kumar Gupta Jan 27 '16 at 04:09
1 Answers
7
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.

serg
- 109,619
- 77
- 317
- 330
-
Thanks @serg I tired doing that already and it works, but like you said it was constantly firing events :( I guess this can't be done, which sucks because I'll either have to make a button for my users to reload the extension or have them just click the browser reload button. Thanks anyway! – Garth Humphreys Aug 01 '11 at 20:12
-
@Garth Can you describe in more details what your extension does, what kind of ajax request are your looking for (something particular or any?) and why your extension should be reloaded? Would `DOMSubtreeModified` with the delay work? – serg Aug 01 '11 at 20:29
-
-
@Setheron You can attach listener to non-existent element via `.live`, but you can't catch when this element was added to the page that way. – serg Sep 06 '11 at 18:12
-
yea I'm pretty stumped. I've even tried binding to the global 'ajaxComplete' events and I can't seem to get a way in my content scripts to get when the event occurs so I can re-inject my content script – Setheron Sep 06 '11 at 20:02
-
-
Old question but as it came up in google .. here is a page that provides a more up-to-date overview of this . https://www.moesif.com/blog/technical/apirequest/How-We-Captured-AJAX-Requests-with-a-Chrome-Extension/# – ScottC Apr 09 '19 at 17:28