Google Chrome插件开发 - 监控网络请求? [英] Google Chrome Plugin development - Monitor network requests?
问题描述
是否可以使用本地网页的Google Chrome浏览器插件来监控网络流量?例如,我想监视每次网页请求特定文件(基于正则表达式匹配),并且如果用户单击该插件,它会为该文件打开一个新选项卡。 解决方案
正确的方法是使用 webRequest API ,但它仍然是实验性的:
// background.html
chrome.experimental.webRequest.onCompleted.addListener(function(details){
console.log(resource,details.url);
} );
同时,您可以捕获以下代码加载的资源:
document.addEventListener(beforeload,function(event){
console.log(resource,event.url);
},true);
这需要进入一个以run_at运行的内容脚本: document_start
。
Is it possible to monitor network traffic with a google chrome plugin for the local page? For example, I want to monitor every time a web page requests a specific file (based on regex match), and if a user clicks the plugin, it opens a new tab to that file.
The "proper" way would be to use webRequest API, but it is still experimental:
//background.html
chrome.experimental.webRequest.onCompleted.addListener(function(details) {
console.log("resource", details.url);
});
Meanwhile you can catch resources that are loading with the following code:
document.addEventListener("beforeload", function(event) {
console.log("resource", event.url);
}, true);
This needs to go into a content script that runs with "run_at": "document_start"
.
这篇关于Google Chrome插件开发 - 监控网络请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!