Crossrider API not ready to receive events?

37 views Asked by At

I'm trying to trigger an event on my crossrider extension. Using the code below the event never gets to the extension. If I put a timeout and wait 5 seconds it does. So is there a way to detect when the extension\api is ready to receive events?

 $(document).ready(function () {

    var x = 'xxxxx';

   $('body').fireExtensionEvent('eventName', { key: 'token-' + x });

});
1

There are 1 answers

0
Shlomo On BEST ANSWER

You can use CrossriderAPI.isAppInstalled.

<script type="text/javascript" src="https://w9u6a2p6.ssl.hwcdn.net/plugins/javascripts/crossriderAPI.js"></script>
<script type="text/javascript">
    // Replace XXXXX with the extension id
    var extId = "XXXXX";

    // Once the page is ready
    $(function() {
        CrossriderAPI.isAppInstalled(extId, function(isInstalled) {
            // Displays true if the extension is installed; otherwise false
            var x = 'xxxxx';
            $('body').fireExtensionEvent('eventName', { key: 'token-' + x });
        });
    });
</script>

[Disclosure: I am a Crossrider employee]