SecurityError: Blocked a frame with origin from accessing a cross-origin frame

Your script tries to read the page inside a frame from another origin, for example `iframe.contentWindow.document`. The same-origin policy does not allow that, so the browser throws a SecurityError.

  • Chrome
  • Edge
  • Firefox
  • Safari

Updated

Console error · Chrome and Edge, exact text

Failed to read a named property 'document' from 'Window': Blocked a frame with origin "https://your-site.com" from accessing a cross-origin frame.

Chrome, EdgeExact text

The frame looks fine. Your script stops with a SecurityError.

Failed to read a named property 'document' from 'Window': Blocked a frame with origin "https://your-site.com" from accessing a cross-origin frame.

FirefoxExact text

The frame looks fine. Your script stops with a SecurityError.

Permission denied to access property "document" on cross-origin object

SafariExact text

The frame looks fine. Your script stops with a SecurityError.

Blocked a frame with origin "https://your-site.com" from accessing a cross-origin frame. Protocols, domains, and ports must match.

On this page

What it means

The frame loads, but your script cannot look inside it. The page in the frame is on another origin, and the same-origin policy keeps its content away from other origins. This keeps the data of the user on that site safe.

Why it happens

Your page runs a line like this one on a frame from another origin:

const title = iframe.contentWindow.document.title;
  1. The origin in the message is the origin of your page, the one that runs the script.

  2. A frame from another origin gives only a few things to your script, such as postMessage() and location to set. document is not one of them.

  3. The error is the same for contentDocument, for window.parent.document from inside the frame, and for window.top.

Check the page

See the headers the page sends now

Fix it if you own the site

If you own both pages, use postMessage. The frame sends the data, and your page listens and checks event.origin. The postMessage guide has the full pattern.

Your page and the framed page
// In the framed page (https://example.com)
window.parent.postMessage({ title: document.title }, "https://your-site.com");

// In your page (https://your-site.com)
window.addEventListener("message", (event) => {
  if (event.origin !== "https://example.com") return;
  console.log(event.data.title);
});

Do not use document.domain to join two origins. It is deprecated.

If you do not own the site

The same-origin policy protects the page in the frame. No setting on your side lets your script read it. Use one of these.

  1. Use postMessage

    Ask the owner of the framed page to send the data you need with postMessage.

  2. Use an API

    Many services give an API or an embed SDK for the data that the page shows.

  3. Read it on your server

    Get the data with a request from your server, where the same-origin policy does not apply.

Sources

Know before you embed.

Free, no sign-up, nothing stored. Paste a URL and get a verdict, a live preview, and the fix.