Can the Chrome XHR monitor track events (or other events) from the page it’s working with?

I am creating a Chrome extension that controls the content of the page, but the content that interests me only appears when the user clicked the button and then the data was loaded from an Ajax call.

Currently, the extension controls the page with SetTimeout, but it is awkward.

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

+4
source share
1 answer

I don’t know an easy way to track XHR requests, but you can track any changes made to the page structure by listening to the DOMSubtreeModified event. Therefore, when an ajax call is made, and the elements are added / removed / changed on the page, you will be notified.

 document.addEventListener("DOMSubtreeModified", function(event){ //something has changed }); 
+3
source

All Articles