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>
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.
Related
I want to execute a batch file on a button click event from simple HTML page.
In IE, I can use ActiveXObject to achieve this however in other browser ActiveXObject is not supported.
Sample HTML File:
<html>
<head>
<title>Run Batch</title>
<HTA:APPLICATION
APPLICATIONNAME="Run Batch"
ID="MyHTMLapplication"
VERSION="1.0"/>
</head>
<script type="text/javascript">
function RunBat(){
var shell = new ActiveXObject("WScript.Shell");
var path = "D:/Test.bat";
shell.run(path);
}
</script>
</head>
<form>
Execute:
<input type="button" Value="Run" onClick="RunBat();"/>
</form>
</html>
I have gone through many questions on different forums and what I have found is that, in other browsers it is possible through some add-ons.
Is there any other way to execute it without using any add-ons in other browser?
If no, what are the add-ons I can use for Firefox, Chrome and Edge browsers to achieve this?
Due to security reasons it's not possible to launch user files (as batch scripts) from the web browser. This is unless you're trying to develope an electron app, which i think you could see, in that case try this code:
(REQUIRES NODE.JS INTEGRATION)
"use strict";
var myBatFilePath = "C:\\Path\\To\\User\\s\\file.bat";
const spawn = require('child_process').spawn;
var bat = spawn('cmd.exe', ['/c', myBatFilePath]);
bat.stdout.on('data', (data) => {
//Logs the batch's echos to the console
var str = String.fromCharCode.apply(null, data);
console.info(str);
});
bat.stderr.on('data', (data) => {
//Logs as error the batch's echos that end with "1>&2"
var str = String.fromCharCode.apply(null, data);
console.error(str);
});
bat.on('exit', (code) => {
//Handles batch exit codes
var preText = `Child exited with code ${code} : `;
switch(code){
case 0:
console.info(preText); // EXIT CODE 0 (no exit code provided)
break;
case 1:
console.info(preText); // EXIT CODE 1
break;
case 2:
console.info(preText); // EXIT CODE 2
break;
case 3:
console.info(preText); // EXIT CODE 3
break;
//AND SO ON
}
});
I'm getting the following error in my notify.js :
Uncaught ReferenceError: Notify is not defined
here is the code in my js
function onPermissionGranted() {
doNotification("Notification Allowed", "You will now receive notifications once your checking is complete.")
}
function onPermissionDenied() {
console.warn("Permission has been denied by the user")
}
function doNotification(t, e) {
new Notify(t,{
body: e
}).show()
}
window.onbeforeunload = function() {
if ("" != $("#live").val() || "" != $("#cclist").val())
return "You're about to leave this page. Are you done saving your live results?"
}
,
Notify.needsPermission && Notify.requestPermission(onPermissionGranted, onPermissionDenied);
var timer, list, tlist, tw = 191, stop = !0, ct = 0, akey = "10001|BB21C00153BEEE1A0419ED806D47E63E9054CA1CAA0DEF2DBC4FEB9365992243F33707C0EEC6B3643EB77D41D6BF48F2F015C83CCAE6CC7D1C54D3ECEAC45E00A443AFFD8E2642EAB3A68BCE0841E7FB3EC257D51BBA3A35FD378D551E5F08BDB55F9CDBCF7F363E1857D85B0B62760294FFC8395ECEC42C9BC3EDC71E06FA7D188C594F1D17D4392308F1123CAA89DF1099EF729DA723654FBEFCD9884885DD3EEED42E97C462788D685587518FB62883AF0739594D67C42F77466A276D34AD1461FA60DCB0A5A2AFC9A02F4E800CA9DB2AC5C010697CF0F0479E9710F849A052E949DC9082E7A67E43A9BF722354AB3616F1C4ECACD616950CCED7702C5A17";
when I run the page I got the console error.
Your Notify class is most likely in a different file that is not referred in the file where you get this error.
The error
Uncaught ReferenceError: [ref] is not defined
is an error telling you your code has a reference that cannot be understood by the JavaScript interpreter and that it can't... well... interpret it. [ref] is the name of the reference triggering the error. It can be an unknown class, an undefined variable or an undefined function. Check for typos and make sure the class is both declared and included.
Also, make sure that the imported JavaScript file of your class is imported before the script using it :
<script src="path/notify.js" type="text/javascript" />
<script src="path/usingnotify.js" type="text/javascript" />
would work, whereas
<script src="path/usingnotify.js" type="text/javascript" />
<script src="path/notify.js" type="text/javascript" />
would not.
Connecting to a non-existent web socket server results in loud errors being logged to the console, usually to the tune of ... net::ERR_CONNECTION_REFUSED.
Anyone have an idea for a hackaround to silence this output? XMLHttpRequest won't work since it yields the same verbose error output if the server is not reachable.
The goal here is to test if the server is available, if it is then connect to it, otherwise use a fallback, and to do this without spamming the console with error output.
Chrome itself is emitting these messages, and there is no way to block them. This is a function of how chrome was built; whenever a ResourceFetcher object attempts to fetch a resource, its response is passed back to its context, and if there's an error, the browser prints it to the console - see here.
Similar question can be found here.
If you'd like, you can use a chrome console filter as this question discusses to block these errors in your console, but there is no way to programmatically block the messages.
I don't know why do you want to prevent this error output. I guess you just want to get rid of them when debugging. So I provide a work around here may be just useful for debugging.
Live demo: http://blackmiaool.com/soa/43012334/boot.html
How to use it?
Open the demo page, click the "boot" button, it will open a new tab. Click the "test" button in the new tab and check the result below. If you want to get a positive result, change the url to wss://echo.websocket.org.
Why?
By using post message, we can make browser tabs communicate with each other. So we can move those error output to a tab that we don't concern.
P.S. You can refresh the target page freely without loosing the connection between it and boot page.
P.P.S You can also use storage event to achieve this.
boot.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>boot page</title>
</head>
<body>
<button onclick="boot()">boot</button>
<p>BTW, you can boot the page without the button if you are willing to allow the "pop-up"</p>
<script>
var targetWindow;
function init() {
targetWindow
}
function boot() {
targetWindow = window.open("target.html");
}
boot();
window.addEventListener('message', function(e) {
var msg = e.data;
var {
action,
url,
origin,
} = msg;
if (action === "testUrl") {
let ws = new WebSocket(url);
ws.addEventListener("error", function() {
targetWindow.postMessage({
action: "urlResult",
url,
data: false,
}, origin);
ws.close();
});
ws.addEventListener("open", function() {
targetWindow.postMessage({
action: "urlResult",
url,
data: true,
}, origin);
ws.close();
});
}
});
</script>
</body>
</html>
target.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>target page</title>
</head>
<body>
<h4>input the url you want to test:</h4>
<textarea type="text" id="input" style="width:300px;height:100px;">
</textarea>
<br>
<div>try <span style="color:red">wss://echo.websocket.org</span> for success result(may be slow)</div>
<button onclick="test()">test</button>
<div id="output"></div>
<script>
var origin = location.origin;
var testUrl = origin.replace(/^https?/, "ws") + "/abcdef"; //not available of course
document.querySelector("#input").value = testUrl;
function output(val) {
document.querySelector("#output").textContent = val;
}
function test() {
if (window.opener) {
window.opener.postMessage({
action: "testUrl",
url: document.querySelector("#input").value,
origin,
}, origin);
} else {
alert("opener is not available");
}
}
window.addEventListener('message', function(e) {
var msg = e.data;
if (msg.action === "urlResult") {
output(`test ${msg.url} result: ${msg.data}`);
}
});
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script>
window.onload = function(){
var oInput = document.getElementById('input1');
var oDiv = document.getElementById('div1');
var iNow = 1;
oInput.onclick = function(){
var number = randomNum(35,7);
oDiv.innerHTML = number;
history.pushState(number,'');
}
window.onpopstate = function(event){
var number = event.state || '';
oDiv.innerHTML = number;
}
function randomNum(alls,now){
var arr = [];
var newArr = [];
for(var i=1;i<=alls;i++){
arr.push(i);
}
for(var i=0;i<now;i++){
newArr.push(arr.splice(Math.floor(Math.random()*arr.length),1));
}
return newArr;
}
}
</script>
</head>
<body>
<input type="button" id="input1" value="35選7" />
<div id="div1"></div>
</body>
I don't know why history.pushState does not work, it throws the error:
history.html:14 Uncaught SecurityError: Failed to execute 'pushState' on
'History': A history state object with URL
'file:///C:/Users/TED/Documents/HBuilderProjects/javascript-%E7%9F%A5%E8%AD%98%E9%A1%9E/history.html' cannot be created in a document
with origin 'null' and URL
'file:///C:/Users/TED/Documents/HBuilderProjects/javascript-%E7%9F%A5%E8%AD%98%E9%A1%9E/history.html'.oInput.onclick # history.html:14
Don't pretend that file:/// is the same as "web pages": they didn't get loaded by the browser using the same mechanism that real web pages go through, and lots of things that web pages can do will not work for "plain files".
If you want to see how your code behaves as web page, using web APIs, then you'll need to load it properly using http(s). That means using a simple server (not even a full blow Apache or the like, just a one-liner http server like python -m SimpleHTTPServer, or php -S localhost:8000 or node.js's http-server or live-server packages, etc. etc.) and then load it through http://localhost:someport/yourfilename, where "someport" is whatever port number the one-line server says is being used, and "yourfilename" is obviously the name of your file.
An interesting problem about dojo toolkit and javasacript.
I am using a visual studio to developing application
I have created a module as following and named its file as calc.js
djConfig.js
var pathRegex = new RegExp(/\/[^\/]+$/);
var locationPath = location.pathname.replace(pathRegex, '');
var dojoConfig = {
async: true,
packages: [
{
name: 'application',
location: locationPath + '/js/application'
}
};
calc.js
define(["dojo/_base/declare"], function(declare) {
return declare(null, {
Sum: function(x,y) {
return x + y;
}
}); })
Once created this file I references this file in index.html file as following,
index.html
<script type="text/javascript" src="/js/application/djConfig.js"></script>
<script type="text/javascript">
require(["application/calc"],
function(calc) {
var c = new calc();
console.log(c.Sum(1, 2));
}
);
</script>
This code is wirking at first.Calculating sum and writing in concole of browser.
But than I am changing something in calc.js (ex. return x+y-1;).
The browser is giving a script error.
If I change something in index.html page - for example type a whitespace- than script is working.
All changes in calc.js file is throwing script error, if I do not change somewhere in index.html
Even If I type a whitespace or add a line in index page, every thing is working.
Did you encounter a problem like this?