@@ -2,6 +2,7 @@ import log from "loglevel";
22import { v4 as uuidv4 } from "uuid" ;
33
44let iFrameSandboxScriptRunner : HTMLIFrameElement | null = null ;
5+ let iFrameSandboxReady = false ;
56
67export interface ScriptResponse {
78 functionReturnValue : any ;
@@ -95,6 +96,7 @@ const buildSandboxIframe = async (): Promise<HTMLIFrameElement> => {
9596 event . source === iFrameSandboxScriptRunner ?. contentWindow
9697 ) {
9798 log . debug ( "The script runner iframe has started" ) ;
99+ iFrameSandboxReady = true ;
98100 window . removeEventListener ( "message" , onMessage ) ;
99101 resolve ( iFrameSandboxScriptRunner as HTMLIFrameElement ) ;
100102 }
@@ -129,6 +131,18 @@ export const executeDynamicScriptInSandbox = async (
129131 await buildSandboxIframe ( ) ;
130132 }
131133
134+ if ( ! iFrameSandboxReady ) {
135+ // The iFrame sandbox is still starting up, this can happen on app startup.
136+ // We don't want to block, so log and return an empty response.
137+ log . warn (
138+ "The Iframe sandbox is starting up, dynamic script execution skipped on this occasion."
139+ ) ;
140+ return {
141+ functionReturnValue : "" ,
142+ widgetProps : { }
143+ } ;
144+ }
145+
132146 if ( ! iFrameSandboxScriptRunner ?. contentWindow ) {
133147 throw new Error ( "Iframe content window not available" ) ;
134148 }
0 commit comments