Uncaught Error: getSessionData requires two non-null arguments JavaScript

Uncaught Error: getSessionData requires two non-null arguments JavaScript

我正在 android 设备的 Webview 中加载 JavaScript 文件。加载文件时,我没有在 webview 上获取内容,它只是显示为空,并且在日志中出现错误

[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,不是正确的 url,下面是正确的 ulr

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

下面是我正在使用的文件

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

您可以获得更多关于我在做什么的信息from here。在此link ulr 未被使用,使用本地文件。

我想知道如何修复 getSessionData requires two non-null arguments?这是一个非常痛苦的错误。

这个错误我们可以在这个url

上看到
https://service.force.com/embeddedservice/5.0/frame/session.esw.min.js

Salesforce 尝试解析您的 Web 视图的 URL 以提取域。
然后将域传递给多个函数调用,包括 getSessionData。
您可以打开 non-minified https://service.force.com/embeddedservice/5.0/eswFrame.js 文件并注意此块:

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

此函数无法从使用 file:/// 加载的本地文件解析域,这是您在加载 webview 时所做的。因此错误。

解决方案是在您的应用程序中托管本地服务器或将您的 webview 脚本存储在远程服务器上,以便 Salesforce 可以从 webview 正确解析域 url。

例如,使用 http://localhost URL 加载以下脚本会在 Chrome 桌面上正确显示聊天代理:

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

getSessionData requires two non-null arguments,这意味着您的 getSessionData(a,b) 函数正在为 ab 或两者获取 null 值。 为什么它得到 null,之前调用 getSessionsData() 函数的函数之一有问题,或者你实际上是 运行 这个函数,参数中有 null 数据。