Cross-domain isolation requires setting two response headers at the same time, why third-party images and scripts suddenly do not load
What's the matter with the third-party images and scripts not loading after setting them? This problem usually occurs after developers add cross-origin isolation policies to the site. Cross-origin isolation requires setting two response headers simultaneously - Cross-Origin-Embedder-Policy controls which cross-origin resources the document on this site is allowed to load, and Cross-Origin-Opener-Policy controls the reference relationship between windows - both of which need to be set together to mark the document as an isolated environment.Once the isolation strategy takes effect, third-party images and scripts without cross-domain permission tags on the page will be blocked from loading by the browser.
What do the two response headers manage separately
Cross-Origin-Embedder-Policy (abbreviated COEP) determines whether the current document can refer to cross-origin resources. If not set, the browser treats it as unsafe-none and imposes no restrictions on cross-origin resources. Once set to require-corp, cross-origin resources must be explicitly declared in some way to allow them to be referenced by this site, otherwise the request will be intercepted.
Cross-Origin-Opener-Policy (abbreviated COOP) determines the reference relationship between the current document and the newly opened window. When set to same-origin, the newly opened cross-origin window no longer holds a reference to the window.opener of the original document, and the original document cannot access the other in reverse. This strategy cuts off the cross-domain channel between windows.
COEP instruction value comparison
| directive | behavior |
|---|---|
| unsafe-none | Default value, does not impose cross-origin resource restrictions |
| require-corp | Cross-origin resources must carry the crossorigin attribute or the Cross-Origin-Resource-Policy header to be allowed to load |
| credentialless | Cross-origin requests without credentials are allowed, but the response must not include cookies |
require-corp is the most commonly used isolation mode. Under this rule, when a page references images or scripts from external domains, the response of the resource must include the Cross-Origin-Resource-Policy pass mark, and the reference tag also needs to be added with the crossorigin attribute. If either side is missing the mark, the browser treats the resource as unauthorized and blocks loading.
Why must the two headers be set in pairs
The specification requires cross-domain isolation status to meet two conditions: COEP set to require-corp or credentialless, and COOP set to same-origin.If any of them are missing, the document will not be marked as isolated environment. SharedArrayBuffer and precise timers depend on the isolated state to be used, which is a common motivation for developers to set response headers.If only COEP was set without COOP, although isolation was not fully achieved, the resource limit was triggered prematurely - the sudden failure of third-party resources often originates from this.
Troubleshooting思路 for third-party resource loading failures
First confirm the actual scope of the isolation strategy. Open the developer tool Console to check if there are any error messages from resources being blocked by COEP, the error will provide the domain name of the intercepted resource and the required tag.Check if the intercepted third-party resource itself sent a Cross-Origin-Resource-Policy header;If the resource is hosted by an external service provider, contact the party to add this header in the response. Also, check if the page reference tag has added crossorigin=“anonymous”;Even if the resource carries the CORP release mark, the tag side will still be intercepted if the property is missing. For third-party components that cannot be modified, they can be placed in an independent iframe, and COEP should not be set on the document of the iframe, thereby bypassing the isolation strategy of this site.
Common questions
Q: Why can't third-party images be loaded when only COEP is set and COOP is not?
A: The resource restrictions of COEP take effect independently of the isolation state. As long as the response header contains require-corp, cross-origin resources must meet the marker requirements, regardless of whether COOP is set. The failure to achieve complete isolation does not mean that the restrictions have not been triggered.
Q: Where should the cross-origin permission marker be added?
A: Both sides must be met simultaneously. Add the crossorigin attribute on the referencing tag side and the Cross-Origin-Resource-Policy header on the resource service side. Any missing side may cause the load to fail.
Q: Can credentialless replace require-corp?
A: credentialless allows sending cross-origin requests without credentials, suitable for loading third-party images that cannot be modified. However, it must be set to same-origin by COOP in order to enable cross-origin isolation, and not all browsers fully support this command; compatibility with the target browser must be confirmed before deployment.