Permission denied to access property on cross-origin object

Firefox throws this error when your script reads a property of a frame from another origin, such as `document`. The same-origin policy blocks it. Use postMessage to pass data between the two pages.

  • Chrome
  • Edge
  • Firefox

Updated

Console error · Firefox, exact text

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

FirefoxExact text

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

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

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.

On this page

What it means

Your script tried to read inside a page from another origin. Firefox stops the script with this error. The frame itself is fine, and it still shows the page.

Why it happens

Your script reads a property of a window on another origin:

iframe.contentWindow.document
  1. The name in quotes is the property your script read: document, location.href, or a global of the other page.

  2. Firefox throws the error as a DOMException with the name SecurityError.

  3. The same block exists in each browser. Only the words differ.

Check the page

See the headers the page sends now

Fix it if you own the site

If you own both pages, send the data with postMessage and check event.origin when it comes in. The postMessage guide has the full pattern.

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

// In your page (https://your-site.com)
window.addEventListener("message", (event) => {
  if (event.origin !== "https://example.com") return;
  iframe.style.height = `${event.data.height}px`;
});

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.