0

Implementing live agent embedded service code snippet and when testing through google tag manager we inject the HTML portion for the embedded service snippet through the following javascript code:

var parentDiv = document.createElement('div');
parentDiv.setAttribute('id', 'snapins_invite');
parentDiv.setAttribute('inert', 'true');
parentDiv.setAttribute('aria-live', 'assertive');
parentDiv.setAttribute('role', 'dialog');
parentDiv.setAttribute('aria-atomic', 'true');
parentDiv.setAttribute("class","embeddedServiceInvitation");
parentDiv.innerHTML =
             '<div>\
              <button type="button" id="closeInvite" class="embeddedServiceCloseIcon" aria-label="Exit invitation">&times;</button>\    
              <div class="embeddedServiceInvitationHeader" aria-labelledby="snapins_titletext" aria-describedby="snapins_bodytext">\
              <span class="embeddedServiceTitleText" id="snapins_titletext">Need help from a trusted expert? </span>\
              </div>\
              <div class="embeddedServiceInvitationBody">\
                  <p id="snapins_bodytext"></p>\
              </div>\
              </div>\
              <div class="embeddedServiceInvitationFooter" aria-describedby="snapins_bodytext">\
                  <button type="button" class="embeddedServiceActionButton" id="acceptInvite">Chat Now</button>\
                  <button type="button" class="embeddedServiceActionButton" id="rejectInvite">No thanks</button>\
               </div>';

document.getElementsByTagName('body')[0].appendChild(parentDiv);

<script type='text/javascript' 
src='https://service.force.com/embeddedservice/5.0/esw.min.js'>. 
</script>
<script type='text/javascript'>
  var initESW = function(gslbBaseURL) {
      embedded_svc.settings.displayHelpButton = false; //Or false
      embedded_svc.settings.language = ''; //For example, enter 'en' 
      or 'en-US'
      embedded_svc.settings.enabledFeatures = ['LiveAgent'];
      embedded_svc.settings.entryFeature = 'LiveAgent';

      embedded_svc.init(
        'https://atstaging.my.salesforce.com',
        'https://atstaging-gochat.cs126.force.com',
        gslbBaseURL,
        '00D3L0000008',
        'GoCo_Popup_60secs',
        {
            baseLiveAgentContentURL: 'https://c.la1-c1cs-lo2.salesforceliveagent.com/content',
            deploymentId: '5723L000000',
            buttonId: '5733L000000',
            baseLiveAgentURL: 'https://d.la1-c1cs-lo2.salesforceliveagent.com/chat',
            eswLiveAgentDevName: 'EmbeddedServiceLiveAgent_Parent04I3L0000004CALUA2_17178fccc46',
            isOfflineSupportEnabled: false
        }
    );
};

if (!window.embedded_svc) {
    var s = document.createElement('script');
    s.setAttribute('src', 'https://gocogroup--atstaging.my.salesforce.com/embeddedservice/5.0/esw.min.js');
    s.onload = function() {
        initESW(null);
    };
    document.body.appendChild(s);
} else {
    initESW('https://service.force.com');
}
</script>

The scripts all load correctly and when the chat invitation comes up and "Chat now" is clicked the following error is picked up on the dev console.

VM3146 aura_prod.js:856 Uncaught TypeError: Cannot set property 'innerHTML' of null
at $.B.message (VM3146 aura_prod.js:856)
at $.B.handleError (VM3146 aura_prod.js:853)
at $.B.ra (VM3146 aura_prod.js:855)
at a (VM3146 aura_prod.js:936)
at VM3146 aura_prod.js:936

Has anyone come across this error before or can point me in the right direction of where to look?

  • When are you running this script ? – Sudarshan May 12 at 12:13
  • Hard to tell without all the relevant logic showing here – PepeFloyd May 12 at 16:00
  • the script runs on page load and I only get the error when cache is enabled. if using chrome and I disable cache then it works – JPG May 13 at 9:56
0

can you please try removing the backslash in the innerhtml div tag.

looks like first tag is misinterpreted with backlash in the inner html line of code

please change the following line like below :

parentDiv.innerHTML =
             '<div>
              <button type="button" id="closeInvite" class="embeddedServiceCloseIcon" aria-label="Exit invitation">&times;</button>\    
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.