0

I am loading JavaScript file in Webview in android device. While loading file, I am not getting content on webview, it just shows empty and in logs getting error

[chromium] [INFO:CONSOLE(2)] "Uncaught Error: getSessionData requires two non-null arguments (domain, keys).", source: https://service.force.com/embeddedservice/5.0/frame/session.esw.min.js (2)
[chromium] [INFO:CONSOLE(5)] "No domain set!", source: https://service.force.com/embeddedservice/5.0/eswFrame.min.js (5)
The thread 0x1d has exited with code 0 (0x0).
Thread finished: <Thread Pool> #29
Thread finished: <Thread Pool> #7
The thread 0x7 has exited with code 0 (0x0).
Thread finished: <Thread Pool> #31
The thread 0x1f has exited with code 0 (0x0).
[Choreographer] Skipped 1299 frames!  The application may be doing too much work on its main thread.
[chromium] [INFO:CONSOLE(1)] "Uncaught ReferenceError: initESW is not defined", source: https://service.force.com/embeddedservice/5.0/esw.html (1)

ulr in above error, is not the exact url being reguested, below is the correct ulr

https://service.force.com/embeddedservice/5.0/esw.min.js

Below file I am using

<html>
<body>
<button onclick="Chat1()">Submit</button>
<script type='text/javascript' src='https://service.force.com/embeddedservice/5.0/esw.min.js'></script>
<script type='text/javascript'>
    function Chat1() {
        var initESW = function (gslbBaseURL) {
        embedded_svc.settings.displayHelpButton = true; //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://ulr.my.salesforce.com',
            'https://ulr.force.com/visualforce',
            gslbBaseURL,
            '00D7a00000055uj',
            'Products',
            {
                'baseLiveAgentContentURL': 'https://c.la3-c1cs-cdg.salesforceliveagent.com/content',
                'deploymentId': '720008Oqg',
                'buttonId': '5730PID',
                'baseLiveAgentURL': 'https://d.la3-c1cs-cdg.salesforceliveagent.com/chat',
                'eswLiveAgentDevName': 'EmbeddedServiceLiveAgent_Parent0000000jLUAQ_17d9a605e8e',
                'isOfflineSupportEnabled': false
            }
        );
    };
    if (!window.embedded_svc) {
        var s = document.createElement('script');
        var jsUlr1 = 'https://ulr.salesforce.com/embeddedservice/5.0/esw.min.js/'
        console.log("Control here2")
        s.src = jsUlr1;
        s.onload = function () {
            initESW(null);
        }
        document.body.appendChild(s);
    }
    else {
        initESW('https://service.force.com');
    }
    }
</script>
</body>
</html>

You can get more information from here regarding what I am doing. In this link ulr not being used, using local file.

I want to know how to fix getSessionData requires two non-null arguments ? this is really painful error .

This error we can see on this url

https://service.force.com/embeddedservice/5.0/frame/session.esw.min.js
R15
  • 13,982
  • 14
  • 97
  • 173

2 Answers2

2

Salesforce attempts to parse the URL of your webview in order to extract a domain.
The domain is then passed to multiple function calls, including getSessionData.
You can open the non-minified https://service.force.com/embeddedservice/5.0/eswFrame.js file and notice this block:

window.location.search.replace(/([a-zA-Z0-9]+)=([\S]+)/g, function(match, key, value) {
  if(key === "parent") {
    // Only take the parts between the first instance of // and the / following it.
    this.parentOrigin = value;
  }
}.bind(this));

This function is unable to parse a domain from a local file loaded with file:///, which is what you do when you load the webview. Thus the errors.

The solution is to host a local server within your app or to store your webview script on a remote server so Salesforce can properly parse the domain from the webview url.

For instance, loading the following script using a http://localhost URL displays the chat agent properly on Chrome desktop:

<html>
<body>
<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 = true; //Or false
        embedded_svc.settings.language = 'en'; //For example, enter 'en' or 'en-US'
        embedded_svc.settings.enabledFeatures = ['LiveAgent'];
        embedded_svc.settings.entryFeature = 'LiveAgent';
        embedded_svc.init(
            'https://ulr.my.salesforce.com',
            'https://ulr.force.com/visualforce',
            gslbBaseURL,
            '00D7a00000055uj',
            'Products',
            {
                'baseLiveAgentContentURL': 'https://c.la3-c1cs-cdg.salesforceliveagent.com/content',
                'deploymentId': '720008Oqg',
                'buttonId': '5730PID',
                'baseLiveAgentURL': 'https://d.la3-c1cs-cdg.salesforceliveagent.com/chat',
                'eswLiveAgentDevName': 'EmbeddedServiceLiveAgent_Parent0000000jLUAQ_17d9a605e8e',
                'isOfflineSupportEnabled': false
            }
        );
    }
    initESW('https://service.force.com');
</script>
</body>
</html>
Jean-Baptiste Martin
  • 1,399
  • 1
  • 10
  • 19
  • Hi, I have tried doing it. I kept my html content on `run.mocky.io` and got an url. Now I am getting error `[chromium] [INFO:CONSOLE(7)] "Message origin must match parent origin!", source: https://service.force.com/embeddedservice/5.0/eswFrame.min.js (7)`. I assigned you bounty even before trying this solution so that it wont go unused :). Please help me for this issue? – R15 Mar 23 '22 at 08:53
  • What happens if you use this URL in a regular desktop browser? Do you have a URL to share that I can inspect? – Jean-Baptiste Martin Mar 23 '22 at 09:06
  • I've edited my answer with additional details. – Jean-Baptiste Martin Mar 23 '22 at 09:10
  • 1
    When I use same file in w3school online html editor, I can see chat buttons coming up. Not sure why this error coming in mobile application. Above url in comment gives me that error. This is the url I am using https://run.mocky.io/v3/0093032c-1e40-4c0f-bba1-08241a4fed64 – R15 Mar 23 '22 at 09:16
  • I've just loaded this URL in an Android webview and it works properly: `https://run.mocky.io/v3/b4625e05-9f46-4d93-b1c6-4f12066e931f`. It must be something with your webview config. Can you enable DomStorageEnabled on your webview? Salesforce needs local storage. – Jean-Baptiste Martin Mar 23 '22 at 09:55
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/243228/discussion-between-jean-baptiste-martin-and-r15). – Jean-Baptiste Martin Mar 23 '22 at 10:17
  • Hi, can you please have a look on my another question if you have idea https://stackoverflow.com/questions/71708368/webview-is-not-rendering-css-styles-with-loaddatawithbaseurl-only-loading-plain – R15 Apr 01 '22 at 14:29
0

getSessionData requires two non-null arguments, meaning your getSessionData(a,b) function is getting null value for a or b or both of them. Why is it getting null, there's something wrong in one of the previous functions which calls getSessionsData() function or you are actually running this function with null data in parameter.