在Chrome扩展程序中使用tinyeditor所见即所得编辑器时,沙箱访问冲突

问题描述 投票:1回答:1

尝试在Chrome扩展程序中加载第三方wysiwyg编辑器时出现以下错误。

沙箱访问冲突:在“ chrome-extension:// cmcjindomengjienigbcldekcfnhfped”从访问帧为“ null”。两个框架都是沙盒,缺少“允许相同来源”标志。

我最初遇到类似的错误,并通过添加allow-same-origin标志来解决该错误。这导致另一个错误,需要allow scripts标志。以下是iframe元素的当前状态

<iframe sandbox="allow-same-origin allow-scripts" src="editor.html" width="350" height="350" style="border:none;"></iframe>

所见即所得编辑器动态创建了一个iframe以容纳该编辑器。我假设这可能会触发错误的第二个实例。我尝试在沙盒页面中创建的iframe上设置allow-same-origin标志,但这无济于事。

我可以尝试其他方法,但由于这也是一次学习冒险,所以我很想解决这个问题。

编辑:我尝试用div替换动态创建的iframe,只是为了看看会发生什么。我没有收到上面的错误,但是正如所料,当访问与iframe相关的属性时,代码失败。这不能证明新的iframe是问题,但确实可以。

编辑2FWIW,下面的行是引发错误的地方

this.e = this.i.contentWindow.document;

先前被初始化为的位置

this.i = document.createElement('iframe');
iframe google-chrome-extension sandbox same-origin-policy tinyeditor
1个回答
2
投票

如果您将iframe沙盒化,则无法从外部访问它的内容。然后,您应该使用postMessage在用户代理之间进行通信。

通过在同一域上加载的iframe上同时使用allow-same-origin和allow-scripts,iframe可以删除沙箱属性。

http://www.whatwg.org/specs/web-apps/current-work/multipage/the-iframe-element.html#attr-iframe-sandbox

当嵌入式页面与包含iframe的页面具有相同的来源时,同时设置allow-scripts和allow-same-origin关键字,则嵌入式页面可以简单地删除沙箱属性,然后重新加载自身,从而有效地打破了沙盒。

© www.soinside.com 2019 - 2024. All rights reserved.