问题
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.
回答1:
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"
.
来源:https://stackoverflow.com/questions/6685503/google-chrome-plugin-development-monitor-network-requests