WorkerGlobalScope:crossOriginIsolated 属性

io error: No such file or directory (os error 2) (/home/runner/work/yari/yari/mdn/translated-content/files/zh-cn/web/api/workerglobalscope/index.md)

WorkerGlobalScope 接口的 crossOriginIsolated 只读属性返回一个指示网站是否处于跨源隔离状态的布尔值。该状态降低了旁路攻击的风险并解锁了一些功能:

当响应标头 Cross-Origin-Opener-Policy 的值为 same-originCross-Origin-Embedder-Policy 标头的值为 require-corpcredentialless 时,网站处于跨源隔离状态。

一个布尔值。

示例

js
const myWorker = new Worker("worker.js");

if (window.crossOriginIsolated) {
  const buffer = new SharedArrayBuffer(16);
  myWorker.postMessage(buffer);
} else {
  const buffer = new ArrayBuffer(16);
  myWorker.postMessage(buffer);
}

规范

Specification
HTML Standard
# dom-crossoriginisolated-dev

浏览器兼容性

BCD tables only load in the browser