简体   繁体   English

Chrome扩展程序访问Webrequest标头

[英]Chrome extension access webrequest headers

I'm trying to write simple extension that would act on request headers. 我正在尝试编写将对请求标头起作用的简单扩展。

In documentation there is something about chrome.WebRequest , but I have no idea how to make it work.... 文档中有一些关于chrome.WebRequest ,但是我不知道如何使它工作。

When I put listener to content page, chrome.WebRequest is undefined, when I put it to background section, totally nothing happens... 当我将侦听器放置到内容页面时, chrome.WebRequest是未定义的,当我将其放置到背景部分时,完全没有任何反应...

manifest 表现

{
    "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 script.js

alert('haha');

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

Any help? 有什么帮助吗?

manifest.json 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 background.js

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM