Flash Thunder
Flash Thunder

Reputation: 12036

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....

When I put listener to content page, chrome.WebRequest is undefined, when I put it to background section, totally nothing happens...

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

alert('haha');

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

Any help?

Upvotes: 1

Views: 1444

Answers (1)

Kushal Shukla
Kushal Shukla

Reputation: 110

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"]
 );

Upvotes: 1

Related Questions