I have the following doubt. I have always worked with jQuery looking for all the possible crashes by mistake, and avoiding doing other functionalities. However, the following question popped up. Is there a way to rescue an error that is thrown in jQuery by syntax?
Since I often work with dynamic data, it may sometimes have a problem that I did not anticipate, and knowing if and how it can be done would be very helpful.
The idea is that you can catch any jQuery crashes, so you can take statistical measurements to generate future patches and resolve without the client having to realize there was a bug.
In the client you can do it through
eval
, but its use is dangerous because it can be used for attacks such as XSS.eval
In a nutshell, use makes your site vulnerable .The best option in this case would be to use a parser on the server to find out if a script is valid or not. I don't know what language you use in the backend, but for example, in Node.js you can use the syntax-error package that evaluates a module (JS file) or a plain text code in search of errors and if it finds them, you report in detail (line where it occurred).
If you use Browserify it is possible to use syntax-error in the browser. For example, if we evaluate the following:
It will show us the following error message:
If you work with plugin systems or extensions, without a doubt it will be quite useful.