Last active
March 6, 2019 20:05
-
-
Save FokkeZB/033d4a9089fff392f7990a452e1d323d to your computer and use it in GitHub Desktop.
Let a script loaded before Intercom wait until intercom has booted
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function afterIntercom() { | |
if (window.intercomSettings.is_intercom_bubble_enabled && window.intercomSettings.is_intercom_twoway_enabled) { | |
// do something | |
} | |
} | |
if (window.intercomSettings) { | |
afterIntercom(); | |
} else { | |
Object.defineProperty(window, 'intercomSettings', { | |
configurable: true, | |
enumerable: true, | |
get: function() { | |
return this._intercomSettings; | |
}, | |
set: function(val) { | |
this._intercomSettings = val; | |
afterIntercom(); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In the call to
Object.defineProperty
, the optionshould be eliminated. When using the correctly spelled option,
writable: true
, it is considered an error to have accessors and writable at the same time: