忽略 firefox webextension 中的 X-Frame-Options

Ignoring X-Frame-Options in firefox webextension

我正在尝试将我的扩展程序从 Chrome 移植到 Firefox,但是我遇到了问题 与 X 框架选项。我的扩展非常简单,它所做的只是创建一些 iframe,等待它们加载,然后从加载的页面中提取一些数据。

这一切都很好Chrome,但是在 Firefox 中我的页面有问题 不会在 iframe 中加载(可能是由于 X-Frame-Options: ALLOW-FROM XXX)。

在Chrome有

"permissions": {
    "https://example.com/"
}

足以使浏览器忽略 X-Frame-Options,但在 Firefox 中 还是不行。

那么,我怎样才能强制 Firefox 忽略我的扩展程序的这个 X-Frame-Options(以及 它的页面)?

编辑:我只想补充一点,因为无论如何我都在使用注入的内容脚本(从框架中获取数据),我 不需要 它是在 iframe 中。我所需要的只是在用户不可见的情况下呈现页面(所以新标签等是不行的:/)。

EDIT2:这 2 个文件扩展名在 chrome 中有效,但在 firefox 中无效:

manifest.json

{
  "manifest_version": 2,
  "name": "Iframe test",
  "description": "foobar",
  "version": "0.9.3",
  "browser_action": {
    "default_popup": "popup.html"
  },
  "permissions": [
    "activeTab",
    "https://jisho.org/"
  ]
}

popup.html

<html>
    <head>
        <meta charset="UTF-8" />
    </head>
    <body>
        <iframe src="https://jisho.org"></iframe>
    </body>
</html>

在Chrome中看起来像"just works"因为Chromedoesn't support"ALLOW FROM".

Firefox 在这里做了正确的事情,但您可以像使用 webRequest API, specifically webRequest.onHeadersReceived 一样拦截此 header。像这样的东西(未经测试)应该可以工作:

browser.webRequest.onHeadersReceived.addListener((details) => {
        let newHeaders = details.responseHeaders.filter(
            header => !header.name.toLowerCase().endsWith('frame-options')
        );
        return {responseHeaders: newHeaders};
    },
    {
        urls: [ 'https://jisho.org/*' ],
        types: [ 'sub_frame' ]
    },
    ['blocking', 'responseHeaders']
);

您还需要 webRequestwebRequestBlocking 权限。