@@ -45,6 +45,22 @@ export function getUpdatedChatUIConfig() {
4545 return chatUIConfig ;
4646}
4747
48+ function waitForCondition ( checkFn , timeout = 5000 , interval = 100 ) {
49+ return new Promise ( ( resolve ) => {
50+ const startTime = Date . now ( ) ;
51+ const check = ( ) => {
52+ if ( checkFn ( ) ) {
53+ resolve ( true ) ;
54+ } else if ( Date . now ( ) - startTime >= timeout ) {
55+ resolve ( false ) ;
56+ } else {
57+ setTimeout ( check , interval ) ;
58+ }
59+ } ;
60+ check ( ) ;
61+ } ) ;
62+ }
63+
4864async function openChatModal ( initialMessage , el ) {
4965 const innerModal = new DocumentFragment ( ) ;
5066 const title = createTag ( 'h1' , { class : 'bc-modal-title' } , chatLabelText ) ;
@@ -84,11 +100,22 @@ async function openChatModal(initialMessage, el) {
84100 const base = env . name === 'prod' ? 'experience.adobe.net' : 'experience-stage.adobe.net' ;
85101 const src = `https://${ base } /solutions/experience-platform-brand-concierge-web-agent/static-assets/main.js` ;
86102 await loadScript ( src ) ;
87- window . adobe . concierge . bootstrap ( {
88- instanceName : 'alloy' ,
89- stylingConfigurations : getUpdatedChatUIConfig ( ) ,
90- selector : `#${ mountId } ` ,
91- } ) ;
103+
104+ const bootstrapAPIReady = await waitForCondition (
105+ ( ) => ! ! window . adobe ?. concierge ?. bootstrap ,
106+ 5000 , // 5 seconds max wait
107+ 100 , // Check every 100ms
108+ ) ;
109+
110+ if ( bootstrapAPIReady ) {
111+ window . adobe . concierge . bootstrap ( {
112+ instanceName : 'alloy' ,
113+ stylingConfigurations : getUpdatedChatUIConfig ( ) ,
114+ selector : `#${ mountId } ` ,
115+ } ) ;
116+ } else {
117+ window . lana ?. log ( 'Brand Concierge: bootstrap API not available' , { tags : 'brand-concierge' , severity : 'critical' } ) ;
118+ }
92119 } else {
93120 // Legacy method: Use _satellite.track
94121 // eslint-disable-next-line no-underscore-dangle
0 commit comments