admin管理员组文章数量:1356265
Using a Google Chrome Extension, I would like to fire some event or somehow detect every HTTP response I receive in my browser.
Pretty much - I want to detect exactly what the "Network" tab of the Chrome developer tools sees using a Google Chrome Extension.
For example, if I open the Network tab and go to Google I see every .js, .css, image, etc. Can I somehow detect that?
Edit:
I have tried the following (which I would expect to get fired after each request pletes):
chrome.webRequest.onCompleted.addListener(function(details) { alert('hey'); });
But that never seems to get fired.
Using a Google Chrome Extension, I would like to fire some event or somehow detect every HTTP response I receive in my browser.
Pretty much - I want to detect exactly what the "Network" tab of the Chrome developer tools sees using a Google Chrome Extension.
For example, if I open the Network tab and go to Google. I see every .js, .css, image, etc. Can I somehow detect that?
Edit:
I have tried the following (which I would expect to get fired after each request pletes):
chrome.webRequest.onCompleted.addListener(function(details) { alert('hey'); });
But that never seems to get fired.
Share Improve this question edited Mar 26, 2012 at 12:53 MattW asked Mar 25, 2012 at 20:47 MattWMattW 13.2k5 gold badges41 silver badges65 bronze badges2 Answers
Reset to default 7You can use the Web Request api for that, be aware that this came in at Chrome version 17 so youll have to set the minimum_chrome_version
to 17.
http://code.google./chrome/extensions/webRequest.html
http://code.google./chrome/extensions/manifest.html#minimum_chrome_version
manifest.json
{
"name": "WebRequest",
"description": "WebRequest - onCompleted",
"version": "0.1",
"permissions": ["<all_urls>", "webRequest"],
"background": {
"scripts": ["background.js"]
},
"manifest_version": 2
}
background.js
chrome.webRequest.onCompleted.addListener(function(details) {
console.debug(details);
}, {
urls: ["<all_urls>"]
});
Go to the background page and look in the console when a page is loading/loaded.
Try this: background.js
chrome.webRequest.onCompleted.addListener
(
TrackRequest,
{urls: ["<all_urls>"]},
["responseHeaders"]
);
function TrackRequest(info)
{
console.log(info);
}
and the manifest.js:
{
"name": "Ext",
"version": "1.0",
"manifest_version": 2,
"description": "Ext template",
"background": {
"scripts": ["background.js"]
},
"content_security_policy": "script-src 'self' chrome-extension-resource://readme.js; object-src 'self'",
"permissions": ["webRequest","*://*/"]
}
You cannot make an "allert" from background script. For debugging, go to extensions and click on "background page". You will see there the console output.
本文标签: javascriptDetect all incoming HTTP files Google Chrome ExtensionStack Overflow
版权声明:本文标题:javascript - Detect all incoming HTTP files Google Chrome Extension - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744033039a2579263.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论