开发者

Can a Chrome extension monitor XHR events (or other events) from the page it's running against?

开发者 https://www.devze.com 2023-01-27 10:55 出处:网络
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

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
});
0

精彩评论

暂无评论...
验证码 换一张
取 消