是否可以从Chrome扩展程序的JS中删除X-Frame-Options标头?

时间:2019-04-02 17:49:30

标签: google-chrome-extension

是否可以在Chrome扩展程序中使用JavaScript删除 x-frame-options

目前我有这个

manifest.json

var logSpace = document.getElementById("log");

var log = function(event) {
  console.log(event.type, event);
  var p = document.createElement("p");
  p.innerText = event.type + ":" + event.code;
 // logSpace.appendChild(p);
}

document.body.addEventListener("keydown", log);

Background.js

{
  "manifest_version": 2,
  "name": "background",
  "description": "DE background",
  "version": "1.0",

  "content_scripts": [
    {
      "matches": ["*://*.web.com/*"],
      "js": ["contentscript.js"],
      "all_frames": true
    }
  ],
  "permissions": ["*://*.web.com/*", "webRequest", "webRequestBlocking"]
}

contentscript.js

// This is to remove X-Frame-Options header, if present
chrome.webRequest.onHeadersReceived.addListener(
    function(info) {
      var headers = info.responseHeaders;
      var index = headers.findIndex(x=>x.name.toLowerCase() == "x-frame-options");
      if (index !=-1) {
        headers.splice(index, 1);
      }
      return {responseHeaders: headers};
    },
    {
        urls: ['*://*.web.com/*'], //
        types: ['sub_frame']
    },
    ['blocking', 'responseHeaders']
);

如果代码在background.js中,则可以正常工作,但是可以在contentscript.js中添加该代码(background.js)吗?

我问这个问题,因为我目前在chrome存储中有其他manifest.json和background.js的扩展名,但是我只想编辑contentscript.js以删除x-frame-options,我不想编辑Background.js或manifest.json仅contentscript.js

谢谢

0 个答案:

没有答案