--- title: Cross-Origin-Embedder-Policy slug: Web/HTTP/Headers/Cross-Origin-Embedder-Policy translation_of: Web/HTTP/Headers/Cross-Origin-Embedder-Policy ---
HTTP Cross-Origin-Embedder-Policy
(COEP) 响应标头可防止文档加载未明确授予文档权限(通过 CORP或者 CORS)的任何跨域资源 。
Header type | {{Glossary("Response header")}} |
---|---|
{{Glossary("Forbidden header name")}} | no |
Cross-Origin-Embedder-Policy: unsafe-none | require-corp
unsafe-none
require-corp
crossorigin
属性或 {{HTTPHeader("Cross-Origin-Resource-Policy")}} 头必须使用它来加载资源,而不会被COEP阻止。为了节省时间你可以只接受类似于{{jsxref("SharedArrayBuffer")}} 或者 {{domxref("Performance.now()")}} 对象, 只要你的文档有一个值被设置为require-corp
的 COEP 头部.
Cross-Origin-Embedder-Policy: require-corp Cross-Origin-Opener-Policy: same-origin
你可以看看这个头部 {{HTTPHeader("Cross-Origin-Opener-Policy")}} ,这样你设置起来会做的更好。
检查 cross origin isolation 是否成功,你可以再次测试crossOriginIsolated
这个属性 是否对窗口和工作的上下文有效:
if (crossOriginIsolated) { // Post SharedArrayBuffer } else { // Do something else }
If you enable COEP using require-corp
and have a cross origin resource that needs to be loaded, it needs to support CORS and you need to explicitly mark the resource as loadable from another origin to avoid blockage from COEP. For example, you can use the crossorigin
attribute for this image from a third-party site:
<img src="https://thirdparty.com/img.png" crossorigin>
Specification |
---|
{{SpecName('HTML WHATWG', '#coep', 'Cross-Origin-Embedder-Policy header')}} |
{{Compat("http.headers.Cross-Origin-Embedder-Policy")}}