javascript Chrome 扩展 webRequest.onBeforeRequest
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29100577/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Chrome extension webRequest.onBeforeRequest
提问by Bonomi
I am trying to create an extension to analyse requests made on the chrome browser but I can't put it work. The alert never fires.
我正在尝试创建一个扩展程序来分析在 chrome 浏览器上发出的请求,但我无法让它工作。警报永远不会触发。
manifest.json
清单文件.json
{
"name": "Test",
"description": "Test",
"version": "1.0",
"manifest_version": 2,
"permissions": ["background", "tabs", "webRequest", "webRequestBlocking", "*://*/*"],
"background": {
"scripts": ["background.js"],
"persistent": true
}
}
background.js
背景.js
var callback = function(details) {
alert("hello");
};
var filter = { "*://*/*" };
var opt_extraInfoSpec = [];
chrome.webRequest.onBeforeRequest.addListener(
callback, filter, opt_extraInfoSpec);
Why is it my alert not firing?
为什么我的警报没有触发?
回答by Dan Smith
Your filter is the wrong format - it's not a valid object at all. Addtionally it needs to contain at least the 'url' property. If you wan't all URL's, use this:
您的过滤器格式错误 - 它根本不是有效对象。此外,它至少需要包含 'url' 属性。如果您不需要所有 URL,请使用以下命令:
var filter = {urls: ["<all_urls>"]};
Check out this for exact details on the format for the filter: https://developer.chrome.com/extensions/webRequest#type-RequestFilter
查看此过滤器格式的确切详细信息:https: //developer.chrome.com/extensions/webRequest#type-RequestFilter