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 ex开发者_StackOverflow社区tension 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?
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
});
精彩评论