1 Uncaught SyntaxError: Unexpected end of JSON input - javascript

I have a site that randomly throws this JavaScript error. If you refresh the site it almost always occurs and it prevents the site from loading. Instead, you just see a blank white page.
The console states there is an "Uncaught SyntaxError: Unexpected end of JSON input" in require.js on line 8. The line reads:
html{color:#000;background:#FFF;}body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,textarea,p,blockquote,th,td{margin:0;padding:0;}table{border-collapse:collapse;border-spacing:0;}fieldset,img{border:0;}address,caption,cite,code,dfn,em,strong,th,var{font-style:normal;font-weight:normal;}li{list-style:none;}caption,th{text-align:left;}h1,h2,h3,h4,h5,h6{font-size:100%;font-weight:normal;}q:before,q:after{content:'';}abbr,acronym{border:0;font-variant:normal;}sup{vertical-align:text-top;}sub{vertical-align:text-bottom;}input,textarea,select{font-family:inherit;font-size:inherit;font-weight:inherit;}input,textarea,select{*font-size:100%;}legend{color:#000;}
Is there something wrong with this line that I'm not seeing?
The site
Chrome console output
Firefox console output

define("lib/config", [], function() {
"use strict";
var e = document.getElementById("app-config");
return e ? JSON.parse(e.innerHTML) : {}
})
That's the problematic section of code. the app-config element isn't always loaded before this part is being executed. If possible, hard code your app-config into your html

Related

"Script error" reported in window.onerror without cross-site scripting

Almost every JS error I get using window.onerror is the unhelpful "Script error" message.
I have read everything I can find on this but it is always said it is caused by cross-site scripting, but there's none in my code.
Why do these unhelpful error messages appear and how can I replace them with the full messages that appear in the console?
As a test example, I created a minimal HTML/JS code pair. This is the HTML page, testpage.html:
<html>
<head></head>
<body>
<script src="/js/testpage.min.js"></script>
</body>
</html>
and JS script:
window.onerror = function(msg, url, lineNo, columnNo, error) {
// code goes here to generate log entry on the server
return true;
}
// generate illustrative sample error
var jsonData = "";
var data = JSON.parse(jsonData);
Running this, msg = "Script error" and other parameters are either null or zero. The Google DevTools console displays the full error:
Uncaught SyntaxError: Unexpected end of JSON input
at JSON.parse (<anonymous>)
at testpage.min.js:7
Any help towards being able to log the full error messages will be most welcome. I'm at a complete loss.
EDIT: Recast to make problem clearer.

Seeing which line can be debugged in firefox

I have a script with around 30 lines, and I'm trying to to debug it in firefox, but when I get the error it doesn't tell me what line is getting the error? It says 4:370, does it mean at line 370, but I only have 30 lines?
ERROR: Execution of script 'test' failed! sessionStorage.getItem(...) is null userscript.html:4:370
That output means the error occurred on column 370 of line 4 in userscript.html. You can trace the error by clicking the userscript.html:4:370 on the right of the console and it should show you script and the line/command that caused the error.

Why my operators <= are converted in <?

I'm in Appearance --> Theme Option, where I put my JavaScript code, so I do this:
if(price<=LIMITLESS){
console.log("home 1");
}else{
console.log("Home2");
}
So when I load the web site, I read the console and I read this error:
Unexpected token ;
and when I click the line where the exception is thrown
if(price<LIMITLESS)
Anyone can help me to avoid this error?

Troubleshooting a JS code snippet that receives error message. Verify if the error is correct?

This particular chunk of code is receiving an error of a missing semi-colon. What is odd is that the code itself is a direct duplicate of code that is saving without the error in another file.
This is the only message I am receiving from the compiler (Hubspot). The error is supposedly happening on the first line. I am limited in my Javascript knowledge and thus am unable to verify with certainty that the error message I am receiving is correct. Could it be an incorrect error? If it is not, could someone help me with correcting what is causing the error?
Thanks in advance.
var isIE = /*#cc_on!#*/false || !!document.documentMode; // At least IE6
if (isIE) {
$("#svg >g, #logos, #logos > g, g.text, .services-svg, .services-svg > g, #a-experience-svg-figure,#experience-a-svg-group a.paragraph.link")
.each(function() {
$(this).attr('transform', $(this).css('transform'));
});
}
In your code fragment are not problem with semicolon.

Jsdom throws an error on a external resource script (script on the page) after returning the result

I am getting an error which seems to be originating from one of the page scripts.
file://cdn.widgets.webengage.com/js/widget/webengage-min-v-3.0.js:1
return c.apply(undefined,a)}catch(d){webengage.eLog(d);if(!b){throw d}}}else{t
^
TypeError: Cannot call method 'call' of undefined
at new exports.NOT_IMPLEMENTED (/usr/local/lib/node_modules/jsdom/lib/jsdom/browser/utils.js:9:13)
at Object.webengage.eLog (file://cdn.widgets.webengage.com/js/widget/webengage-min-v-3.0.js:1:366)
at t.extend.u (file://cdn.widgets.webengage.com/js/widget/webengage-min-v-3.0.js:1:19160)
at Object.t.extend.error (file://cdn.widgets.webengage.com/js/widget/webengage-min-v-3.0.js:1:19299)
at file://cdn.widgets.webengage.com/js/widget/webengage-min-v-3.0.js:1:66518
at Object.webengage.withELog (file://cdn.widgets.webengage.com/js/widget/webengage-min-v-3.0.js:1:640)
at Timer.<anonymous> (file://cdn.widgets.webengage.com/js/widget/webengage-min-v-3.0.js:1:937)
at Timer.exports.setInterval.timer.ontimeout (timers.js:234:14)
I am getting this error from the following code:
try {
var document = jsdom.jsdom(str, null, {});
} catch(e) {
console.log("Got ERROR...");
console.log(e);
}
console.log("Page Document Loaded.");
var window = document.parentWindow;
//console.log(window.document.innerHTML);
console.log(window.innerWidth);
console.log(typeof window.document.getElementsByClassName);
here str is the html that i got earlier. I am able to see printed results, the html the innerWidth and the typeof getElementsByClassName i.e.. function. But after around 20 seconds i am getting the above error and my application crashes, without printing Got ERROR... from above.
The first question that i have is why is my application still running after printing the last thing. Is this a normal behavior for jsdom that it keeps on running like how in a browser a script keeps on running until window.close() is given.
The actual problem is, how can i resolve this. I want to trigger few events in this window object and interact with it but it keeps on crashing.
The url for the script is a little confusing:
file://cdn.widgets.webengage.com/js/widget/webengage-min-v-3.0.js:1
this is because the page is fetching this script resource in an ajax call with the url:
//cdn.widgets.webengage.com/js/widget/webengage-min-v-3.0.js:1
although jsdom is able to get the resource, i checked that this script has that line where it is showing the error.

Categories