5

I'm building a Chrome extension that manipulates the content of the page, but the content I'm interested in only shows up when the user has clicked a button and the data has then been loaded from an Ajax call.

At the moment the extension monitors the page with a SetTimeout but it's clumsy.

Can an extension know when an Ajax call has been initiated, and when it ended? or can the extension somehow receive events from the page?

Bambax
  • 2,920
  • 6
  • 34
  • 43

1 Answers1

4

I don't know an easy way to monitor XHR requests, but you can monitor any changes being made to a page structure by listening to DOMSubtreeModified event. So when ajax call is done and elements are added/removed/changed on a page - you will be notified.

document.addEventListener("DOMSubtreeModified", function(event){
        //something has changed
});
serg
  • 109,619
  • 77
  • 317
  • 330
  • 1
    It's not really the answer I was hoping for, but it's still a very valuable piece of information, that I didn't know about, so I accept it! – Bambax Feb 17 '11 at 09:24
  • @Bambax I have a nearly identical scenario, how has the DOMBSubtreeModified worked for you? – Devin Rhode Sep 12 '11 at 07:21