为什么不是';t剥离x-frame选项允许我在此扩展中加载跨站点iframe? 上下文
我正在构建一个chrome扩展,允许用户在第三方网站上从web上的任何位置运行自动脚本。扩展需要能够在用户正在加载第三方站点的任何页面上动态插入iframe 问题 当我尝试从google.com在iframe中加载linkedin.com时,我发现linkedin.com拒绝连接。如果我看一下,我可以看到x帧选项仍然存在于标题中,而我已经确认我已经在标题中删除了它们 我已将以下内容添加到扩展背景脚本中,以允许在任何站点中加载iFrame为什么不是';t剥离x-frame选项允许我在此扩展中加载跨站点iframe? 上下文,iframe,google-chrome-extension,cross-domain,content-security-policy,content-script,Iframe,Google Chrome Extension,Cross Domain,Content Security Policy,Content Script,我正在构建一个chrome扩展,允许用户在第三方网站上从web上的任何位置运行自动脚本。扩展需要能够在用户正在加载第三方站点的任何页面上动态插入iframe 问题 当我尝试从google.com在iframe中加载linkedin.com时,我发现linkedin.com拒绝连接。如果我看一下,我可以看到x帧选项仍然存在于标题中,而我已经确认我已经在标题中删除了它们 我已将以下内容添加到扩展背景脚本中,以允许在任何站点中加载iFrame chrome.webRequest.onHeadersRe
chrome.webRequest.onHeadersReceived.addListener(function (details) {
const headers = details.responseHeaders.filter(header => {
let headerName = header.name.toLowerCase();
return !(headerName === 'content-security-policy' || headerName === 'x-frame-options');
})
if (details.url.includes('linkedin.com')) {
// this console log shows that I've stripped out the necessary headers correctly
console.debug('REMOVED HEADERS: ', headers);
}
return {
responseHeaders: headers
};
}, {
urls: ['<all_urls>']
}, ['blocking', 'responseHeaders']);
在这里,您可以看到控制台日志,其中显示了已修改的标头,其中x-frame和CSP已从iframe请求标头中删除
但是iframe不会加载。它返回200,但什么也没发生
这实际上起到了作用,勇敢的盾牌阻止了iframe在页面中加载。可能是另一个扩展,它可以更改获胜的标题,因为它安装得更早。否则它听起来像个虫子。尝试在addListener的最后一个参数中添加“extraHeaders”。@wOxxOm不起作用:(
(function () {
var iframe = document.createElement('iframe');
iframe.style.position = 'absolute';
iframe.style.zIndex = 100000;
iframe.style.top = 0;
iframe.style.left = 0;
iframe.height = 600;
iframe.width = 900;
iframe.referrerPolicy = 'no-referrer-when-downgrade';
iframe.src = 'https://www.linkedin.com';
document.body.appendChild(iframe);
})();