DOMException: Blocked a frame with origin from accessing a cross-origin frame
Error message
Blocked a frame with origin "X" from accessing a cross-origin frame
Quick summary
You tried to access an iframe, window, or document from a different origin — the Same-Origin Policy blocks this for security.
Why this happens
Tried to access an iframe's content from a different domain
Attempted to read properties of a window opened to another origin
Made a fetch request to a server without proper CORS headers
Minimal example
const iframe = document.getElementById("frame");
const data = iframe.contentWindow.document.body.innerHTML;// Use postMessage for cross-origin communication
iframe.contentWindow.postMessage("get-data", "https://other-origin.com");
window.addEventListener("message", (e) => {
if (e.origin === "https://other-origin.com") console.log(e.data);
});Direct DOM access across origins is blocked. Use postMessage for safe cross-origin communication.
How to diagnose
Check if the target is on a different domain, protocol, or port
Verify CORS headers are set on the server for fetch requests
Look for iframe or window access across origins
How to fix
Configure CORS headers on the server to allow the origin
Use postMessage for cross-origin iframe communication
Proxy the request through your own server to avoid cross-origin issues
How to prevent
Set proper CORS headers on APIs
Use postMessage instead of direct DOM access for cross-origin iframes
Keep resources on the same origin when possible