Chrome 中的 iframe 错误:无法从“窗口"读取“localStorage":此文档的访问被拒绝 [英] Iframe in Chrome error: Failed to read 'localStorage' from 'Window': Access denied for this document

查看:137
本文介绍了Chrome 中的 iframe 错误:无法从“窗口"读取“localStorage":此文档的访问被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 localStorage 的网络应用程序.现在我们想通过 iframe 将此 Web 应用程序嵌入到其他(第三方)站点上.我们希望提供一个类似于 youtube 的 iframe 嵌入,以便其他网站可以将我们的网络应用程序嵌入到 iframe 中.从功能上讲,它就好像它不会被嵌入一样.但它不起作用.Chrome 打印错误消息:

I have a web app which uses localStorage. Now we want to embed this web app on other (third-party) sites via iframe. We want to provide an iframe embed similar to youtube so that other websites can embed our web app in an iframe. Functionally it is the same as if it wouldn't be embedded. But it does not work. Chrome prints the error message:

Uncaught SecurityError: Failed to read the 'localStorage' property from 'Window': Access is denied for this document.

我只是做了以下检查(在 iframe 中):

I just do the following check (in the iframe):

if (typeof window.localStorage !== 'undefined') {
    // SETUP SESSION, AUHT, LOCALE, SETTINGS ETC
} else {
    // PROVIDE FEEDBACK TO THE USER
}

我在 Chrome 中检查了我的安全设置,如 另一个 Stackoverflow 线程 但它不起作用.在不需要调整大多数现代浏览器的(默认)安全设置的情况下,是否有任何更改可以使嵌入成为可能?

I checked my security settings in Chrome like described in another Stackoverflow Thread but it doesn't work. Is there any change to make embedding possible without the need of adjusting (default) security settings of most modern browsers?

为了提供更多信息,我们将 Ember-CLI 用于我们的网络应用程序并开启了CSP(有关 Ember-CLI CSP 的更多信息).CSP 会导致我们的网络应用引发安全错误吗?

To give more information, we use Ember-CLI for our web app and turned on CSP (more info about the Ember-CLI CSP). Could CSP cause our web app to throw security errors?

推荐答案

在 Chrome 的设置 > 隐私 > 内容设置下,您将 cookie 设置设置为阻止网站设置任何数据"

Under Chrome's Settings > Privacy > Content settings, you have the cookie setting set to to "Block sites from setting any data"

此复选框是导致异常的原因.

This checkbox is what is causing the exception.

这篇关于Chrome 中的 iframe 错误:无法从“窗口"读取“localStorage":此文档的访问被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆