Chrome扩展程序是否可以监视它正在运行的页面中的XHR事件(或其他事件)? [英] Can a Chrome extension monitor XHR events (or other events) from the page it's running against?

查看:948
本文介绍了Chrome扩展程序是否可以监视它正在运行的页面中的XHR事件(或其他事件)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个处理页面内容的Chrome扩展程序,但我感兴趣的内容仅在用户点击按钮并且数据已从Ajax调用加载时才会显示。

p>

目前扩展程序使用SetTimeout监视页面,但它笨拙。

扩展程序可以知道何时使用Ajax呼叫已启动,何时结束?或扩展不知何故从页面接收事件?

解决方案

我不知道一个简单的方法来监控XHR请求,但您可以通过监听 DOMSubtreeModified 事件来监视对页面结构所做的任何更改。因此,当完成ajax调用并在页面上添加/删除/更改元素时,系统会通知您。

  document.addEventListener (DOMSubtreeModified,函数(事件){
//有东西已经改变
});


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?

解决方案

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

这篇关于Chrome扩展程序是否可以监视它正在运行的页面中的XHR事件(或其他事件)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆