Chrome扩展程序访问webrequest标头

时间:2014-10-29 07:10:06

标签: google-chrome google-chrome-extension

我正在尝试编写一个可以处理请求标头的简单扩展。

documentation中有chrome.WebRequest的内容,但我不知道如何让它发挥作用......

当我将监听器放到内容页面时,chrome.WebRequest未定义,当我把它放到背景部分时,完全没有任何反应......

清单

{
    "manifest_version": 2,
    "name": "RequestSpy",
    "version": "0.1",
    "description": "HTTP/S Request Analizer",
    "background": [
    {
      "scripts": ["scripts.js"]
    }
    ],
    "icons":{
        "128":"spy.png"
    },
    "permissions": [
          "*://*/*","webRequest"
    ]
}

的script.js

alert('haha');

chrome.webRequest.onHeadersReceived.addListener(function(details){
        console.log(details);
        alert('huhu');
});

任何帮助?

1 个答案:

答案 0 :(得分:1)

的manifest.json

{
   "name": "OnRequest",
   "version": "1.0",
   "description": "I can't has cheezburger!",
   "permissions": ["webRequest",
   "webRequestBlocking",
   "http://*/*",
   "https://*/*"],
   "background": {
                    "scripts": ["background.js"]
                 },
   "manifest_version": 2
}

background.js

chrome.webRequest.onHeadersReceived.addListener(function(e){
  alert("onHeadersReceived");},{urls: ["http://*/*", "https://*/*"]}, ["blocking"]
 );