*Use COOP and COEP to set up a cross-origin isolated environment and enable
powerful features like `SharedArrayBuffer`,
`performance.measureUserAgentSpecificMemory()` and high resolution timer with
better precision.*


![Eiji Kitamura](https://web.dev/images/authors/agektmr.jpg) Eiji Kitamura [X](https://twitter.com/agektmr) [GitHub](https://github.com/agektmr) [Mastodon](https://infosec.exchange/@agektmr) [Bluesky](https://bsky.app/profile/agektmr.com)

<br />


Published: April 13, 2020, Last updated: June 21, 2022

<br />

> [!CAUTION]
> **Caution:** `SharedArrayBuffer` on Chrome desktop requires cross-origin isolation starting from Chrome 92. Learn more at [SharedArrayBuffer updates](https://developer.chrome.com/blog/enabling-shared-array-buffer).

This document shows how to use these COOP and COEP. You can read more about why
this matters in [Make your website "cross-origin isolated" using COOP and COEP](https://web.dev/articles/why-coop-coep.md.txt).

[Video](https://www.youtube.com/watch?v=XLNJYhjA-0c)

Some web APIs increase the risk of side-channel attacks like Spectre. To
mitigate that risk, browsers offer an opt-in-based isolated environment called
cross-origin isolated. With a cross-origin isolated state, the webpage will be
able to use privileged features including:

| API | Description |
|---|---|
| [`SharedArrayBuffer`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer) | Required for WebAssembly threads. This is available from Android Chrome 88. Desktop version is enabled by default with the help of [Site Isolation](https://www.chromium.org/Home/chromium-security/site-isolation), but will require the cross-origin isolated state and [will be disabled by default in Chrome 92](https://developer.chrome.com/blog/enabling-shared-array-buffer). |
| [`performance.measureUserAgentSpecificMemory()`](https://web.dev/articles/monitor-total-page-memory-usage.md.txt) | Available from Chrome 89. |
| [`performance.now()`, `performance.timeOrigin`](https://crbug.com/1180178) | Available in many browsers, with resolution limited to 100 microseconds or higher. With cross-origin isolation, the resolution can be 5 microseconds or higher. |
[Features that will be available behind cross-origin isolated
state.]

The cross-origin isolated state also prevents modifications of
`document.domain`. (Being able to alter `document.domain` allows communication
between same-site documents and has been considered a loophole in the
same-origin policy.)

To opt in to a cross-origin isolated state, you need to send the following
HTTP headers on the main document:

```console
Cross-Origin-Embedder-Policy: require-corp
Cross-Origin-Opener-Policy: same-origin
```

These headers instruct the browser to block loading of resources or iframes
which haven't opted into being loaded by cross-origin documents, and prevent
cross-origin windows from directly interacting with your document. This also
means those resources being loaded cross-origin require opt-ins.

You can determine whether a web page is in a cross-origin isolated state by
examining
[`self.crossOriginIsolated`](https://developer.mozilla.org/docs/Web/API/WindowOrWorkerGlobalScope/crossOriginIsolated).

> [!NOTE]
> **Note:** This document is aimed at those who would like to get their websites ready for using `SharedArrayBuffer`, WebAssembly threads, `performance.measureUserAgentSpecificMemory()` or high resolution timer with better precision in a more robust manner across browser platforms.

## Glossary

This document uses many similarly named and abbreviated terminology. To clarify,
we've curated a mini glossary:

- [COEP: Cross Origin Embedder Policy](https://wicg.github.io/cross-origin-embedder-policy/)
- [COOP: Cross Origin Opener Policy](https://github.com/whatwg/html/pull/5334/files)
- [CORP: Cross Origin Resource Policy](https://developer.mozilla.org/docs/Web/HTTP/Cross-Origin_Resource_Policy_(CORP))
- [CORS: Cross Origin Resource Sharing](https://developer.mozilla.org/docs/Web/HTTP/CORS)
- [CORB: Cross Origin Read Blocking](https://www.chromium.org/Home/chromium-security/corb-for-developers)

## Make your website cross-origin isolated

> [!TIP]
> **Tip:** Learn practical steps to [enable cross-origin isolation](https://web.dev/articles/cross-origin-isolation-guide.md.txt).

### 1. Set `Cross-Origin-Opener-Policy: same-origin` on the top-level document

By enabling `COOP: same-origin` on a top-level document, windows with the same
origin and windows opened from the document have a separate browsing
context group, unless they are in the same origin with the same COOP setting.
Thus, isolation is enforced for opened windows and mutual communication between
both windows is disabled.

A browsing context group is a set of windows that can reference each other. For
example, a top-level document and its child documents embedded with `<iframe>`.
If a website (`https://a.example`) opens a dialog window (`https://b.example`),
the opener window and the dialog window share the same browsing context,
therefore they have access to each other with DOM APIs such as `window.opener`.

![Illustration representing Browsing Content Group with user interacting with page elements.](https://web.dev/static/articles/coop-coep/image/browsing-context-group.png)

You can check if the window opener and its openee are in separate browsing
context groups [from DevTools](https://web.dev/articles/coop-coep.md.txt#debug_issues).

### 2. Enable CORP or CORS on resources

Make sure that all resources in the page are loaded with CORP or CORS HTTP
headers. This step is required for [step four, enabling COEP](https://web.dev/articles/coop-coep.md.txt#enable-coep).

Here's what you need to do, depending on the nature of the resource:

- If the resource is expected to be loaded **only from the same origin** , set the `Cross-Origin-Resource-Policy: same-origin` header.
- If the resource is expected to be loaded **only from the same site but cross
  origin** , set the `Cross-Origin-Resource-Policy: same-site` header.
- If the resource is **loaded from cross origin(s) under your control** , set the `Cross-Origin-Resource-Policy: cross-origin` header if possible.
- For cross origin resources that you have no control over:
  - Use the `crossorigin` attribute in the loading HTML tag if the resource is served with CORS. (For example, `<img src="***" crossorigin>`.)
  - Ask the owner of the resource to support either CORS or CORP.
- For iframes, follow the same principles and set the `Cross-Origin-Resource-Policy: cross-origin` (or `same-site`, `same-origin` depending on the context).
- Scripts loaded with a `WebWorker` must be served from same-origin, so you don't need a CORP or CORS headers.
- For a document or a worker served with `COEP: require-corp`, cross-origin subresources loaded without CORS must set the `Cross-Origin-Resource-Policy:
  cross-origin` header to opt into being embedded. For example, this applies to `<script>`, `importScripts`, `<link>`, `<video>`, `<iframe>`, etc.

> [!IMPORTANT]
> **Key Term:** *Same-site* are websites that have the same scheme and the same eTLD+1. *Same-origin* are websites that have the same combination of scheme, hostname, and port. Read more about the [difference between same-site and same-origin](https://web.dev/articles/same-site-same-origin.md.txt).

#### Isolation in iframes

You can enable cross-origin isolation on a document embedded within an
iframe by applying `allow="cross-origin-isolated"` permissions policy to the
`<iframe>` tag and meeting these conditions. The entire chain of the documents,
including parent frames and child frames, must be cross-origin isolated, too.

### 3. Use the COEP Report-Only HTTP header to assess embedded resources

Before fully enabling COEP, you can do a dry run by using the
`Cross-Origin-Embedder-Policy-Report-Only` header to examine whether the policy
actually works. You will receive reports without blocking embedded content.

Recursively apply this to **all** documents including the top-level document,
iframes and worker scripts. For information on the Report-Only HTTP header, see
[Observe issues using the Reporting API](https://web.dev/articles/coop-coep.md.txt#observe_issues_using_the_reporting_api).

### 4. Enable COEP

This step can only be done once you've
[ensured resources have CORP or CORS enabled](https://web.dev/articles/coop-coep.md.txt#ensure-resources).

Once you've confirmed that everything works and that all resources can be
successfully loaded, switch the `Cross-Origin-Embedder-Policy-Report-Only`
header to the `Cross-Origin-Embedder-Policy` header with the same value to all
documents including those that are embedded with iframes and worker scripts.

> [!NOTE]
> **Note:** [Squoosh](https://squoosh.app), an image optimization PWA, [uses COOP / COEP](https://github.com/GoogleChromeLabs/squoosh/pull/829/files#diff-316f969413f2d9a065fcc08c7a5589c088dd1e21deebadccfc5a4372ac5e0cbbR22-R23) to gain access to Wasm Threads (and Shared Array Buffer) and on Android Chrome.

> [!CAUTION]
> **Caution:** We're exploring how to deploy `Cross-Origin-Resource-Policy` at scale, as cross-origin isolation requires all subresources to explicitly opt-in. One option is [COEP credentialless mode](https://developer.mozilla.org/docs/Web/API/Window/credentialless) that allows loading resources without the CORP header, by stripping all their credentials. Credentialless mode is available from Chrome 96 and in Edge, but is not yet supported by other browsers.

### Determine if isolation succeeded

The `self.crossOriginIsolated` property returns `true` when the web page is in a
cross-origin isolated state and all resources and windows are isolated within
the same browsing context group. You can use this API to determine whether you
have successfully isolated the browsing context group and gained access to
features like `performance.measureUserAgentSpecificMemory()`.

## Debug issues

You may encounter issues with COOP and COEP. You can use browser developer tools
or the reporting API to debug.

### Debug with Chrome DevTools

[Video](https://www.youtube.com/watch?v=D5DLVo_TlEA)

For resources that are rendered on the screen such as images, it's fairly easy
to detect COEP issues, because the request is blocked and the page should
indicate a missing image. However, for resources that don't
necessarily have a visual impact, such as scripts or styles, COEP issues might
go unnoticed. For those, use the DevTools Network panel.

If there's an issue with COEP, you should see
`(blocked:NotSameOriginAfterDefaultedToSameOriginByCoep)` in the **Status**
column.

![COEP issues in the Status column of the Network panel.](https://web.dev/static/articles/coop-coep/image/coep-issues-the-status-c-9f8040461053.jpg)

You can then click the entry to see more details.

![Details of the COEP issue are shown in the Headers tab after clicking a network resource in the Network panel.](https://web.dev/static/articles/coop-coep/image/details-the-coep-issue-a-7483b46211d45.jpg)

You can also determine the status of iframes and dialog windows through the
**Application** panel. Go to the "Frames" section on the left hand side and
expand "top" to see the breakdown of the resource structure.

You can check the iframe's status such as availability of `SharedArrayBuffer`, etc.

![Chrome DevTools iframe inspector.](https://web.dev/static/articles/coop-coep/image/chrome-devtools-iframe-in-7b22ff613fbeb.png)

You can also check the dialog windows's status such as whether it's cross-origin isolated.

![Chrome DevTools dialog window inspector](https://web.dev/static/articles/coop-coep/image/chrome-devtools-popup-win-191023386b4a8.png)

### Observe issues using the Reporting API

The [Reporting API](https://web.dev/articles/reporting-api) is another mechanism through which you can
detect various issues. You can configure the Reporting API to instruct your
users' browser to send a report whenever COEP blocks the loading of a resource
or COOP isolates a dialog window. Chrome has supported the Reporting API since
version 69 for a variety of uses including COEP and COOP.

> [!NOTE]
> **Note:** Are you already using the Reporting API with the `Report-To` header? Chrome is transitioning to a new version of the Reporting API, which replaces `Report-To` with `Reporting-Endpoints`; consider migrating to the new version. Check out [Migrate to Reporting API v1](https://web.dev/reporting-api-migration) for details.

Learn how to [configure the Reporting API](https://web.dev/articles/reporting-api#using-the-reporting-api) and set up a server to receive
reports.

#### Example COEP report

An example [COEP report](https://html.spec.whatwg.org/multipage/origin.html#coep-report-type)
payload when cross-origin resource is blocked looks like this:

```json
[{
  "age": 25101,
  "body": {
    "blocked-url": "https://third-party-test.example.org/check.svg?",
    "blockedURL": "https://third-party-test.example.org/check.svg?",
    "destination": "image",
    "disposition": "enforce",
    "type": "corp"
  },
  "type": "coep",
  "url": "https://cross-origin-isolation.example.com/?coep=require-corp&coop=same-origin&",
  "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4249.0 Safari/537.36"
}]
```

> [!CAUTION]
> **Caution:** `blocked-url` exists for backward compatibility only and [will be removed](https://github.com/whatwg/html/pull/5848).

#### Example COOP report

An example [COOP report](https://html.spec.whatwg.org/multipage/origin.html#reporting)
payload when a dialog is opened isolated looks like this:

```json
[{
  "age": 7,
  "body": {
    "disposition": "enforce",
    "effectivePolicy": "same-origin",
    "nextResponseURL": "https://third-party-test.example.org/popup?report-only&coop=same-origin&",
    "type": "navigation-from-response"
  },
  "type": "coop",
  "url": "https://cross-origin-isolation.example.com/coop?coop=same-origin&",
  "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4246.0 Safari/537.36"
}]
```

When different browsing context groups try to access each other (only on
"report-only" mode), COOP also sends a report. For example, a report when
`postMessage()` is attempted would look like this:

```json
[{
  "age": 51785,
  "body": {
    "columnNumber": 18,
    "disposition": "reporting",
    "effectivePolicy": "same-origin",
    "lineNumber": 83,
    "property": "postMessage",
    "sourceFile": "https://cross-origin-isolation.example.com/popup.js",
    "type": "access-from-coop-page-to-openee"
  },
  "type": "coop",
  "url": "https://cross-origin-isolation.example.com/coop?report-only&coop=same-origin&",
  "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4246.0 Safari/537.36"
},
{
  "age": 51785,
  "body": {
    "disposition": "reporting",
    "effectivePolicy": "same-origin",
    "property": "postMessage",
    "type": "access-to-coop-page-from-openee"
  },
  "type": "coop",
  "url": "https://cross-origin-isolation.example.com/coop?report-only&coop=same-origin&",
  "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4246.0 Safari/537.36"
}]
```

## Takeaways

Use a combination of COOP and COEP HTTP headers to opt a web page into a special
cross-origin isolated state. You can examine `self.crossOriginIsolated` to
determine whether a web page is in a cross-origin isolated state.

We'll [keep this post updated](https://web.dev/articles/coop-coep.md.txt#document_updates) as new features are made
available to this cross-origin isolated state, and further improvements are made
to DevTools around COOP and COEP.

### Resources

- [Why you need "cross-origin isolated" for powerful features](https://web.dev/articles/why-coop-coep.md.txt)
- [A guide to enable cross-origin isolation](https://web.dev/articles/cross-origin-isolation-guide.md.txt)
- [Monitor your web page's total memory usage with
  `measureUserAgentSpecificMemory()`](https://web.dev/monitor-total-page-memory-usage)

## Document updates

- **June 21, 2022**: Worker scripts also need care when cross-origin isolation is enabled. Added some explanations.
- **Aug 5, 2021** : JS Self-Profiling API has been mentioned as one of APIs that require cross-origin isolation, but reflecting [recent change of the
  direction](https://github.com/shhnjk/shhnjk.github.io/tree/main/investigations/js-self-profiling#conclusion), it's removed.
- **May 6, 2021** : Based on feedback and issues reported we've decided to adjust the timeline for `SharedArrayBuffer` usage in none cross-origin isolated sites to be restricted in Chrome M92.
- **April 16, 2021** : Added notes about [COEP credentialless
  mode](https://github.com/mikewest/credentiallessness/) and [COOP
  same-origin-allow-popups to be a relaxed
  condition](https://github.com/whatwg/html/issues/6364) for cross-origin isolation.
- **March 5, 2021** : Removed limitations for `SharedArrayBuffer`, `performance.measureUserAgentSpecificMemory()`, and debugging functionalities, which are now fully enabled in Chrome 89. Added upcoming capabilities, `performance.now()` and `performance.timeOrigin`, that will have higher precision.
- **February 19, 2021** : Added a note about feature policy `allow="cross-origin-isolated"` and debugging functionality on DevTools.
- **October 15, 2020** : `self.crossOriginIsolated` is available from Chrome 87. Reflecting that, `document.domain` is immutable when `self.crossOriginIsolated` returns `true`. `performance.measureUserAgentSpecificMemory()` is ending its origin trial and is enabled by default in Chrome 89. Shared Array Buffer on Android Chrome will be available from Chrome 88.