Refused to frame: an ancestor violates CSP frame-ancestors

The page you embed sends a Content-Security-Policy with frame-ancestors, and your site is not in the list. Chrome and Edge block the frame and write this message in the console.

  • Chrome
  • Edge
  • Firefox
  • Safari

Updated

Console error · Chrome and Edge, exact text

Framing 'https://example.com/' violates the following Content Security Policy directive: "frame-ancestors 'self'". The request has been blocked.

Chrome, EdgeExact text

The frame shows a gray page: “example.com refused to connect.”

Framing 'https://example.com/' violates the following Content Security Policy directive: "frame-ancestors 'self'". The request has been blocked.

FirefoxExact text

The frame shows “Firefox Can’t Open This Page”.

Content-Security-Policy: The page’s settings blocked the loading of a resource (frame-ancestors) at <unknown> because it violates the following directive: “frame-ancestors 'self'”

SafariExact text

The frame stays blank. There is no message in the page.

Refused to load https://example.com/ because it does not appear in the frame-ancestors directive of the Content Security Policy.

On this page

What it means

The page you embed tells the browser which sites may show it in a frame. Your site is not on that list, so Chrome and Edge do not load it. The server of that page decides this. Your iframe code is fine. Test the URL to see its policy.

Why it happens

The server sends a policy like this one:

Content-Security-Policy: frame-ancestors 'self'
  1. frame-ancestors lists the sites that may put the page in a frame. 'self' is the site itself. 'none' allows no site.

  2. Older Chrome versions write the same block in other words: Refused to frame 'https://example.com/' because an ancestor violates the following Content Security Policy directive: "frame-ancestors 'self'".

  3. The URL in the message is the page you embed. The directive at the end is the policy that blocked it.

  4. When a page sends frame-ancestors, browsers ignore its X-Frame-Options header.

Check the page

See the headers the page sends now

Fix it if you own the site

Add the origin of each site that embeds the page to frame-ancestors. Keep 'self' when the site frames its own pages. Pick your server. The frame-ancestors guide has the full steps.

location / {
  proxy_hide_header X-Frame-Options;
  add_header Content-Security-Policy "frame-ancestors 'self' https://your-site.com" always;
}
nginx.confReplace your-site.com with the site that embeds this page.

Write each site as a full origin, such as https://your-site.com. Do not use * unless any site may embed the page.

If you do not own the site

You cannot change the policy of another site. No iframe attribute removes it. Use one of these.

  1. Use the official embed URL

    YouTube, Google Maps, Calendly, and others give a special embed link that allows frames.

  2. Link out instead

    Open the page in a new tab with a normal link, or show a preview card that links to it.

  3. Ask the owner

    Ask them to add your site to frame-ancestors. Send them this page.

Sources

Know before you embed.

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