@@ -24,6 +24,7 @@ export default class GleapFrameManager {
2424 frameUrl = "https://messenger-app.gleap.io" ;
2525 gleapFrameContainer = null ;
2626 gleapFrame = null ;
27+ comReady = false ;
2728 injectedFrame = false ;
2829 widgetOpened = false ;
2930 listeners = [ ] ;
@@ -57,14 +58,14 @@ export default class GleapFrameManager {
5758 function appHeight ( ) {
5859 try {
5960 const doc = document . documentElement ;
60- doc . style . setProperty ( ' --glvh' , ( window . innerHeight * .01 ) + 'px' ) ;
61- } catch ( e ) { }
61+ doc . style . setProperty ( " --glvh" , window . innerHeight * 0 .01 + "px" ) ;
62+ } catch ( e ) { }
6263 }
6364
6465 try {
65- window . addEventListener ( ' resize' , appHeight ) ;
66+ window . addEventListener ( " resize" , appHeight ) ;
6667 appHeight ( ) ;
67- } catch ( e ) { }
68+ } catch ( e ) { }
6869 }
6970 }
7071
@@ -73,7 +74,11 @@ export default class GleapFrameManager {
7374 }
7475
7576 isSurvey ( ) {
76- return this . appMode === "survey" || this . appMode === "survey_full" || this . appMode === "survey_web" ;
77+ return (
78+ this . appMode === "survey" ||
79+ this . appMode === "survey_full" ||
80+ this . appMode === "survey_web"
81+ ) ;
7782 }
7883
7984 setAppMode ( appMode ) {
@@ -84,7 +89,9 @@ export default class GleapFrameManager {
8489 ".gleap-frame-container-inner"
8590 ) ;
8691 if (
87- ( this . appMode === "widget" || this . appMode === "survey_full" || this . appMode === "survey_web" ) &&
92+ ( this . appMode === "widget" ||
93+ this . appMode === "survey_full" ||
94+ this . appMode === "survey_web" ) &&
8895 innerContainer
8996 ) {
9097 innerContainer . style . maxHeight = `${ widgetMaxHeight } px` ;
@@ -173,8 +180,7 @@ export default class GleapFrameManager {
173180 showImage = ( url ) => {
174181 runFunctionWhenDomIsReady ( ( ) => {
175182 var elem = document . createElement ( "div" ) ;
176- elem . className =
177- "gleap-image-view" ;
183+ elem . className = "gleap-image-view" ;
178184 elem . innerHTML = `<div class="gleap-image-view-close">
179185 <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512zm97.9-320l-17 17-47 47 47 47 17 17L320 353.9l-17-17-47-47-47 47-17 17L158.1 320l17-17 47-47-47-47-17-17L192 158.1l17 17 47 47 47-47 17-17L353.9 192z"/></svg>
180186 </div><img class="gleap-image-view-image" src="${ url } " />` ;
@@ -226,9 +232,9 @@ export default class GleapFrameManager {
226232 const flowConfig = GleapConfigManager . getInstance ( ) . getFlowConfig ( ) ;
227233 if (
228234 flowConfig . feedbackButtonPosition ===
229- GleapFeedbackButtonManager . FEEDBACK_BUTTON_CLASSIC ||
235+ GleapFeedbackButtonManager . FEEDBACK_BUTTON_CLASSIC ||
230236 flowConfig . feedbackButtonPosition ===
231- GleapFeedbackButtonManager . FEEDBACK_BUTTON_CLASSIC_BOTTOM
237+ GleapFeedbackButtonManager . FEEDBACK_BUTTON_CLASSIC_BOTTOM
232238 ) {
233239 styleToApply = classicStyle ;
234240 }
@@ -399,14 +405,14 @@ export default class GleapFrameManager {
399405 sendMessage ( data , queue = false ) {
400406 try {
401407 this . gleapFrame = document . querySelector ( ".gleap-frame" ) ;
402- if ( this . gleapFrame && this . gleapFrame . contentWindow ) {
408+ if ( this . comReady && this . gleapFrame && this . gleapFrame . contentWindow ) {
403409 this . gleapFrame . contentWindow . postMessage ( JSON . stringify ( data ) , "*" ) ;
404410 } else {
405411 if ( queue ) {
406412 this . queue . push ( data ) ;
407413 }
408414 }
409- } catch ( e ) { }
415+ } catch ( e ) { }
410416 }
411417
412418 sendSessionUpdate ( ) {
@@ -459,6 +465,7 @@ export default class GleapFrameManager {
459465 // Listen for messages.
460466 this . addMessageListener ( ( data ) => {
461467 if ( data . name === "ping" ) {
468+ this . comReady = true ;
462469 this . sendConfigUpdate ( ) ;
463470 this . sendSessionUpdate ( ) ;
464471 this . workThroughQueue ( ) ;
@@ -517,7 +524,9 @@ export default class GleapFrameManager {
517524 ".gleap-frame-container-inner"
518525 ) ;
519526 if (
520- ( this . appMode === "survey" || this . appMode === "survey_full" || this . appMode === "survey_web" ) &&
527+ ( this . appMode === "survey" ||
528+ this . appMode === "survey_full" ||
529+ this . appMode === "survey_web" ) &&
521530 innerContainer
522531 ) {
523532 innerContainer . style . maxHeight = `${ this . frameHeight } px` ;
@@ -590,7 +599,10 @@ export default class GleapFrameManager {
590599
591600 // Add window message listener.
592601 window . addEventListener ( "message" , ( event ) => {
593- if ( ( event . origin !== this . frameUrl && event . origin !== GleapBannerManager . getInstance ( ) . bannerUrl ) ) {
602+ if (
603+ event . origin !== this . frameUrl &&
604+ event . origin !== GleapBannerManager . getInstance ( ) . bannerUrl
605+ ) {
594606 return ;
595607 }
596608
@@ -601,7 +613,7 @@ export default class GleapFrameManager {
601613 this . listeners [ i ] ( data ) ;
602614 }
603615 }
604- } catch ( exp ) { }
616+ } catch ( exp ) { }
605617 } ) ;
606618 }
607619
0 commit comments