user1067742
user1067742

Reputation: 31

Problem when adding new response header with Chrome extension

I'm trying to develop a Chrome extension to add a new response header to responses from a specific web site. My manifest.json file is as follows:

{
  "name": "MVX",
  "version": "0.0.1",
  "manifest_version": 2,
  "background": {
    "scripts": ["background.js"]  
  },
  "permissions": [ "webRequest", "webRequestBlocking", "<all_urls>" ]
}

background.js file is as follows:

chrome.webRequest.onHeadersReceived.addListener(
(x) => {
    x.responseHeaders.push({name:"Some", value: "Data"});
    return {responseHeaders: x.responseHeaders };
},
{ urls: ["https://www.website.com/*"] },
["blocking","responseHeaders"]
);

The problem is suprising. When I make a request myself to this website code does not work, but when web page makes a request itself to get a resource such as image or js file (everthing except the web page) code works. I can see this from Chrome DevTools > Network tab. How can I solve this problem?

Upvotes: 0

Views: 22

Answers (0)

Related Questions