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
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>