子iframe sameorigin问题

时间:2018-10-18 15:54:53

标签: google-chrome iframe google-chrome-extension same-origin-policy

我有一个网站(localhost:8080)。网站正在显示iframe(我们将其称为frame.com)。 frame.com也有一个来自相同原点的iframe,我们将其称为frame.com/child

frame.comframe.com/child都有x-frame-options:sameorigin。通常,这将阻止localhost显示frame.com。但是我有一个chrome扩展程序,可以执行以下代码

var headerToStrip = 'x-frame-options';

chrome.webRequest.onHeadersReceived.addListener(
  function(details) {
    if (details.initiator !== 'http://localhost:8080') {
      return { responseHeaders: details.responseHeaders }
    }
    return {
      responseHeaders: details.responseHeaders.filter(function(header) {
        return headerToStrip.indexOf(header.name.toLowerCase()) < 0;
      })
    };
  }, {
    urls: ["<all_urls>"]
  }, ["blocking", "responseHeaders"]
);

Okiedoke,现在localhost成功显示frame.com。但是,仍然存在问题。 frame.com未显示frame.com/child

这是我在chrome控制台日志中得到的消息:

Refused to display 'frame.com/child' in a frame because it set 'X-Frame-Options' to 'sameorigin'

为什么会发生此错误,我该如何解决?如果我理解正确,那么frame.comframe.com/child的起源是相同的。

0 个答案:

没有答案