Unable to Embed Experience Cloud Site in iframe?

I have an OmniScript hosted on an Experience Cloud site. Within this OmniScript, I want to display another Experience Cloud site using an LWC component that contains an iframe. However, when I attempt to load the second Experience Cloud site inside the iframe, I encounter the error:
Refused to frame 'https://adb-dev-ed.my.site.com/' because an ancestor violates the following Content Security Policy directive: "frame-ancestors 'none'".
Additionally, the browser console shows that the site refuses to connect. I expected that if the user accessing the iframe was not already logged in to the second Experience Cloud site, they would be redirected to the login page of that site. However, this behavior is not occurring. These are the security settings of the target Experience Cloud site:
CRS Info Solutions offers industry-leading Salesforce Course for Beginners with real-time projects, certification guidance, interview coaching, and a practical approach to make you job-ready.
Answer:
The issue arises because of the Content Security Policy (CSP) settings on the target Experience Cloud site. The error message clearly indicates that the CSP directive "frame-ancestors 'none'"
is blocking the target site from being embedded within an iframe. This directive explicitly disallows the site from being framed in any other page, ensuring security but causing your use case to fail.
Here are some solutions and alternatives to resolve this issue:
1.Modify the Content Security Policy on the Target Site
Navigate to the Security & Privacy settings of the target Experience Cloud site. Under the Content Security Policy (CSP) section, update the policy to allow framing by specific trusted sites. Change the frame-ancestors
directive to include the URL of the site hosting the iframe. For example, if your primary site URL is https://example1.my.site.com
, you need to explicitly allow this URL to frame the target site. This can be done as follows:
- In Salesforce Setup, go to Sites.
- Select your Experience Cloud site.
- Edit the CSP Settings and update the allowed hosts to include your primary site.
2.Update the Clickjack Protection Settings
In the Clickjack Protection settings of the target Experience Cloud site, ensure it is set to “Allow framing by any page” or “Allow framing by trusted sites only.” This setting allows the second site to be framed by the specified URL of the OmniScript’s host site.
3.Redirect the User to a Separate Tab Instead of Using an iframe
If the CSP and clickjack protection settings cannot be adjusted due to organizational security policies, consider redirecting the user to the second Experience Cloud site in a new tab or window. This avoids iframe restrictions altogether while maintaining user experience. You can achieve this in your LWC as follows:
import { LightningElement } from 'lwc';
export default class OpenExperienceCloudSite extends LightningElement {
openSite() {
window.open('https://adb-dev-ed.my.site.com/', '_blank');
}
}
Add a button in your HTML file to trigger the openSite
method:
<template>
<lightning-button label="Open Second Site" onclick={openSite}></lightning-button>
</template>
Explanation: The openSite
method in the JavaScript file uses window.open()
to open the second Experience Cloud site in a new browser tab. The _blank
target ensures the new site opens in a separate tab, bypassing iframe restrictions. The button in the HTML file triggers this method, providing a simple, user-friendly way to access the second site. This solution avoids CSP and clickjack protection issues entirely.
4.Use a Reverse Proxy
A reverse proxy can act as an intermediary between the two Experience Cloud sites. By hosting the second site’s content on the same domain as the first site, you can bypass the CSP restrictions. This approach requires careful implementation and configuration of a reverse proxy server like Nginx or Apache.
5.Single Sign-On (SSO) Implementation
Ensure that both Experience Cloud sites use Single Sign-On (SSO). With SSO, the user logged in to the primary site will automatically authenticate with the second site, bypassing the login page. This reduces friction and may resolve certain redirection issues.
6.Embed a Custom Component Instead of an iframe
If embedding the second site within an iframe is not critical, replicate the required functionality of the second site using a custom LWC or Aura component. This avoids CSP-related issues while ensuring a seamless user experience.
Each of these solutions has its own trade-offs in terms of security, complexity, and user experience. The ideal approach depends on your organization’s policies and technical requirements. If modifying security settings is an option, the first and second solutions should work effectively. If not, consider alternatives like opening the site in a new tab or using a custom component.
Summing Up
To resolve the issue of embedding one Experience Cloud site within an iframe on another, I can adjust the Content Security Policy (CSP) and Clickjack Protection settings on the target site to allow framing from the host site. If modifying security settings isn’t feasible due to organizational policies, I can use alternatives like opening the second site in a new tab using window.open()
, implementing Single Sign-On (SSO) for seamless user authentication, or using a reverse proxy to bypass CSP restrictions. Alternatively, I could replicate the required functionality with a custom Lightning Web Component (LWC), ensuring a secure and seamless experience without relying on an iframe.
Empower Your Career with Salesforce Training in Dallas
Elevate your professional journey with CRS Info Solutions’ top-rated Salesforce training, crafted to provide the skills and expertise required to excel in the ever-evolving Salesforce ecosystem. Our industry-focused courses span Salesforce Admin, Developer, and AI modules, blending in-depth theoretical knowledge with hands-on experience through practical, real-world projects. Whether you’re new to Salesforce or a seasoned professional, our well-structured program ensures you master the tools and techniques needed to stand out.
With a strong emphasis on practical application, Salesforce training in Dallas we offer personalized mentorship, detailed study resources, and expert-led certification preparation to fully equip you for success in interviews and beyond. Gain the confidence and skills to thrive in your Salesforce career. Don’t wait—join our free demo class today and take the first step toward a rewarding future! Enroll now for a free demo!