是否可以在普通页面中嵌入 cross-origin-isolated iframe?

Is it possible to embed a cross-origin-isolated iframe inside a normal page?

换句话说,如果我不能在我的主站点中使用sharedArrayBuffer,我可以打开一个iframe并在iframe中使用sharedArrayBuffer吗?

has been asked in March 2021, and the accepted answer was "No" at the time. However, a more recent google blogpost好像另有所指,所以我想再问一下。

所以我想在我的站点中使用一些带有 sharedArrayBuffer 的 wasm,但是这样做是不切实际的 cross-origin-isolated,所以我创建了另一个站点 https://my-wasm-function.app cross-origin-isolated。我希望将其用作 iframe,并通过 postMessage.

与我的主站点通信

但是,我发现一旦它作为 iframe 嵌入,它就失去了隔离状态。

博文有一些关于如何隔离 iframe 的模糊说明,其中之一是添加 header Cross-Origin-Resource-Policy: cross-origin(在 COOPCOEP 之上,我想想),我试过了,没用。另一种是这样打开iframe:<iframe allow="cross-origin-isolated">,我也试过了,也没用。

所以,答案是否定的。得到该博文作者的确认。

不太清楚<iframe allow="cross-origin-isolated">实现了什么,如果parent被隔离并且iframe的header不在你的控制范围内,也许它可以在不设置headers的情况下隔离iframe,但它肯定会如果 parent 不是,则不要隔离 iframe。博文作者说他会添加一些说明。

In other words, if I can't use sharedArrayBuffer in my main site, can I open an iframe and use sharedArrayBuffer inside the iframe?

没有。父级无法向 iframe 传达一个功能是不具备的。


cross-origin-isolated是一种能力。它启用了多项功能,例如:

  • 在两个 worker 之间共享一个 SharedArrayBuffer。
  • 高清定时器。
  • 等等

截至 2022 年 3 月: 当 top-level 文档使用 COOP:same-originCOEP:require-corpCOOP:credentialless 时,您将获得该功能。对于 iframe,父级还必须使用“allow='cross-origin-isolated'”向下“传达”能力。