Random app is not defined frontend JS error

Hello readers,

I am currently developing a custom application which is displaying a phone dialer in a page on the cti_global_sidebar.

On random refreshes, the contents of the cti_global_sidebar defined within my index.html and app.js do not load : The button to display the cti_global_sidebar with my app logo is still here and works but the content of the cti_global_sidebar is completely empty. The web console displays a JS error : App is not loaded

I first initialized the code using freshdesk doc Your First App and got this issue

I then found this topic App is not defined error in Freshdesk frontend application which seems to be about the same behaviour I’m trying to fi. I followed the recommendation and I changed my initialization code to resemble this one https://github.com/freshworks/marketplace-sample-apps/blob/master/Freshworks-Samples/Freshdesk/sample_cti_app/app/app.js#L113C1-L113C1 Unfortunately the behaviour is still here and I randomly get this App is not defined error.

Here is the gist of my app initialization code :

function onDocumentReady() {
        .then(async function (_client) {
            window.client = _client;
            try {
         // Initialisation Actions Here
     } catch (error) {
         console.error("Problem with retrieving Installation Parameters", error);
     console.debug('RC APP init finished');
     client.interface.trigger("show", { id: "softphone" })
        }).catch(function (error) {
            console.error('The app failed to get initialized');

Would anyone know where this random behaviour could be coming from or have an idea on how to fix it ?

If you need any additional information, please let me know :slight_smile:

Thanks for your help on this !

I seem to have found a satisfactory solution on my own. I tweaked the code from https://github.com/freshworks/marketplace-sample-apps/blob/master/Demo-Apps/twilio_sms_freshdesk/app/scripts/app.js#L41

The condition readystate == “interactive” never fired for what I could see in the logs (the only readystate value I could log was "complete) so I updated the condition and it fixed my issue

document.onreadystatechange = function () {
  if (document.readyState === "complete") renderApp();

  function renderApp() {
    var onInit = app.initialized();

      console.error('RC app failed to initialize');

    function getClient(_client) {
      window.client = _client;

Public use of Chatbot has only been permitted in these Categories: #product-apis, #customize-workflows