Fix JavaScript App Not Working in Office Add-ins and SharePoint
Question details
The user needs to resolve an issue where an externally hosted JavaScript application loads visually but fails to execute its interactive logic when embedded in Microsoft 365 environments.

- Product
- Microsoft 365
- Device & OS
- not provided
- Scenario
- Embedding an external interactive web application (like a Morse code translator) into SharePoint Online or Office for the web.
- Observed behavior
- The application's interface loads successfully in the frame, but the underlying JavaScript execution is blocked and the interactive features do not work.
Before modifying your environment settings, open your browser's Developer Tools (F12) and check the Console and Network tabs for Content Security Policy (CSP) errors or iframe sandboxing blocks.
Initialize a Supported Office Add-in for Word and Excel
Avoid external iframe embedding restrictions by converting your web application into a native Office Add-in.
Office for the web runs embedded content in a sandboxed runtime with strict security and performance isolation. Relying on a standard iframe often blocks interactive scripts. For an interactive tool inside Word or Excel, an Office Add-in is the supported approach.
Open your Office Add-in manifest file (XML or JSON format) and ensure your external application's domain is explicitly listed in the trusted domains section.
Include the official Office JavaScript API script tag (<script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js"></script>) in the header of your HTML file.
Wrap your core JavaScript execution logic inside the Office.onReady() method to guarantee the Office runtime is fully loaded before your custom code attempts to run.

Migrate the Script to SharePoint Framework (SPFx)
Bypass HTML Field Security restrictions in SharePoint by using SPFx instead of the default Embed web part.
Adjust HTML Field Security in SharePoint Settings
Allow specific external domains to load active iframe content directly in SharePoint pages.
Try WPS Office for a Hassle-Free Document Experience
Dealing with complex Microsoft Office Add-in development, SharePoint sandboxing, and strict Content Security Policies can be frustrating. If you simply need a lightweight, powerful office suite to create, edit, and share documents without the heavy administrative overhead, WPS Office is the perfect alternative.

Frequently Asked Questions
Why does my JavaScript work in a normal browser but fail in a SharePoint iframe?
SharePoint Online applies strict Content Security Policies (CSP) and iframe sandboxing rules to prevent malicious scripts from executing. This often inadvertently blocks legitimate interactive logic hosted in external iframes that haven't been explicitly trusted.
How can I check if Content Security Policy is blocking my Office add-in?
Open your browser's Developer Tools (typically by pressing F12), navigate to the Console and Network tabs, and look for red error messages mentioning 'Content Security Policy directive' or 'Blocked script execution'.
What is the recommended way to add interactive JavaScript to Excel for the web?
The recommended approach is to build a native Office Add-in using the Office.js API. You must configure your app's trusted domains in the manifest and initialize the logic within the Office.onReady() function to ensure compatibility with the Office sandbox.




