Why my operators <= are converted in <? - javascript

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?

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.

hard to understand error in angularjs app "Cannot read property 'buffer' of undefined"

I just added a block of code that works in other pages, but in this particular page I get this error, I am not sure why or how to read/understand what is wrong from this error message cause it doesn't seem to me that is pointing to anywhere in specific.
index.js:24 Uncaught TypeError: Cannot read property 'buffer' of undefined
at coerceArray (index.js:24)
at new AES (index.js:195)
at new ModeOfOperationCBC (index.js:444)
at _decrypt (bcs.cryptoStorage.js:51)
at Object.getSessionData (bcs.cryptoStorage.js:91)
at Object.isLogged (bcs.auth.js:30)
at AppBootRun (app.boot.js:112)
at Object.invoke (ionic.bundle.js:18000)
at ionic.bundle.js:17808
at forEach (ionic.bundle.js:13696)
the block of code I added was
$scope.lang = localStorage.getItem("i18n-lang");
$scope.activateLangEN = function () {
$scope.lang = "en-US";
console.log("was called activateLangEn " + $scope.lang);
localStorage.setItem("i18n-lang", $scope.lang);
localStorage.setItem("targetLang", $scope.lang);
location.reload();
}
I force the app to reload again to change it's language according to
what is in the localstorage, on app config I use translateProvider.
Not sure what went wrong here. Anything I should consider in specific?
html: <div class="langChange mt20"><span ng-click="activateLangPT()">PT</span> | <span ng-click="activateLangEN()">EN</span></div>

1 Uncaught SyntaxError: Unexpected end of JSON input

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

error params are null in window.onerror in google chrome

I have html page which causes js error and an global handler for it.
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8">
<script type="text/javascript" src="js/jquery-3.1.0.min.js"></script>
<script type="text/javascript">
$(function () {
window.onerror = function (errorMsg, url, lineNumber) {
alert('Error: ' + errorMsg + ' Script: ' + url + ' Line: ' + lineNumber);
}
throw new Error("this is error");
});
</script>
</head>
<body>
<div>Test page</div>
</body>
</html>
I receive alert: "Error: Script error. Script: Line: 0". As you can see error info is missing. How can I get this info here like I can see errors in developer tools. Any extensions for chrome are not suitable. I must catch errors with their info in javascript.
When a syntax(?) error occurs in a script, loaded from a different origin, the details of the syntax error are not reported to prevent leaking information (see bug 363897). Instead the error reported is simply "Script error." This behavior can be overriden in some browsers using the crossorigin attribute on and having the server send the appropriate CORS HTTP response headers. A workaround is to isolate "Script error." and handle it knowing that the error detail is only viewable in the browser console and not accessible via JavaScript.
I also ran into this. See notes section here: https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onerror
This implies the development setup might need some adjustment to avoid this policy issue. I'm merely guessing here, so don't take it for granted.
I am just adding answer for the sake of those who came here looking.
Source: https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onerror
Please go this URL, as you can see there are five parameters to
window.onerror = function(message, source, lineno, colno, error) { ... }
the last one is the one you need, it has complete record of what you see in console in case of error.
message: error message (string). Available as event (sic!) in HTML onerror="" handler.
source: URL of the script where the error was raised (string)
lineno: Line number where error was raised (number)
colno: Column number for the line where the error occurred (number)
error: Error Object (object)
Then Error Object has two properties
message
stack
stack is the one which will contain all the information you required.
use console.log(errorMsg, url, lineNumber)instead of alert to get more readable log. You can see the log in browser developer console. Also you can check the use of try..catch for better error handling.
use jquery script with anonymous attirbute, and the script server response header with [access-control-allow-origin:*]. Your error throw code is runned with jquery callback.
errorMsg is NOT the message "this is error"; it is Script error., which is precisely what you're seeing. You simply don't get the error message that way. onerror is unsuited to replace a try-catch block.

Angular displays url encoded errors, how to get decoded version?

When I have uncaught errors in my angular applications the console message looks like this:
Error: [$injector:modulerr] http://errors.angularjs.org/1.4.3/$injector/modulerr?p0=app&p1=%5B%24injector%3Aunpr%5D%20http%3A%2F%2Ferrors.angularjs.org%2F1.4.3%2F%24injector%2Funpr%3Fp0%3DENVIRONMENT%0AJ%2F%3C%40http%3A%2F%2Flocalhost%3A8600%2Flibs.js%3A11%3A416%0Aeb%2Fr.%24injector%3C%40http%3A%2F%2Flocalhost%3A8600%2Flibs.js%3A45%3A375%0Ad%40http%3A%2F%2Flocalhost%3A8600%2Flibs.js%3A43%3A364%0A%40http%3A%2F%2Flocalhost%3A8600%2Fapp%2Fapp.js%3A42%3A18%0Ae%40http%3A%2F%2Flocalhost%3A8600%2Flibs.js%3A44%3A154%0Ad%40http%3A%2F%2Flocalhost%3A8600%2Flibs.js%3A42%3A320%0Ag%2F%3C%40http%3A%2F%2Flocalhost%3A8600%2Flibs.js%3A42%3A452%0Am%40http%3A%2F%2Flocalhost%3A8600%2Flibs.js%3A12%3A320%0Ag%40http%3A%2F%2Flocalhost%3A8600%2Flibs.js%3A42%3A229%0Aeb%40http%3A%2F%2Flocalhost%3A8600%2Flibs.js%3A45%3A1%0AAc%2Fd%40http%3A%2F%2Flocalhost%3A8600%2Flibs.js%3A24%3A339%0AAc%40http%3A%2F%2Flocalhost%3A8600%2Flibs.js%3A25%3A151%0AZd%40http%3A%2F%2Flocalhost%3A8600%2Flibs.js%3A23%3A464%0A%40http%3A%2F%2Flocalhost%3A8600%2Flibs.js%3A294%3A428%0An.Callbacks%2Fj%40http%3A%2F%2Flocalhost%3A8600%2Flibs.js%3A2%3A26920%0An.Callbacks%2Fk.fireWith%40http%3A%2F%2Flocalhost%3A8600%2Flibs.js%3A2%3A27738%0A.ready%40http%3A%2F%2Flocalhost%3A8600%2Flibs.js%3A2%3A29530%0AI%40http%3A%2F%2Flocalhost%3A8600%2Flibs.js%3A2%3A29721%0AnrWrapper%40http%3A%2F%2Flocalhost%3A8600%2F%23%2Fdashboard%3A15%3A12749%0A
Which is not useful, but if I url_decode it it is much better, like this:
http://errors.angularjs.org/1.4.3/$injector/modulerr?p0=app&p1=[$injector:unpr] http://errors.angularjs.org/1.4.3/$injector/unpr?p0=ENVIRONMENT
J/<#http://localhost:8600/libs.js:11:416
eb/r.$injector<#http://localhost:8600/libs.js:45:375
d#http://localhost:8600/libs.js:43:364
#http://localhost:8600/app/app.js:42:18
e#http://localhost:8600/libs.js:44:154
d#http://localhost:8600/libs.js:42:320
g/<#http://localhost:8600/libs.js:42:452
m#http://localhost:8600/libs.js:12:320
g#http://localhost:8600/libs.js:42:229
eb#http://localhost:8600/libs.js:45:1
Ac/d#http://localhost:8600/libs.js:24:339
Ac#http://localhost:8600/libs.js:25:151
Zd#http://localhost:8600/libs.js:23:464
#http://localhost:8600/libs.js:294:428
n.Callbacks/j#http://localhost:8600/libs.js:2:26920
n.Callbacks/k.fireWith#http://localhost:8600/libs.js:2:27738
.ready#http://localhost:8600/libs.js:2:29530
I#http://localhost:8600/libs.js:2:29721
nrWrapper#http://localhost:8600/#/dashboard:15:12749
How can I get angular to output errors this way by default? Thanks.
It's url encoded because it's a link. Click it! :D
It will bring you to a webpage that explains the error.
This is your error
If you go to that page and look at the error it will say that it threw an error because of x error. Then that error will be a link to, so click that as well.
And now that you've gotten to that last page, the error is that you have an unknown provider called ENVIRONMENT.
You can override exception handler:
angular.module('exceptionOverride', []).factory('$exceptionHandler', function() {
return function(exception, cause) {
exception.message += ' (caused by "' + cause + '")';
throw exception;
};
});
More here

Categories