Experimenting with window.onerror , trying to make JavaScript debugging easy.
Provides JavaScript error details in a readable format. Recently added a feature where developers can log messages on their remote server by enabling remoteLogging feature of logerr. By enabling remoteLogging , logerr will send a post request to desired action/url with JavaScript error details along with custom parameters if required.
Lets take a simple code snippet which will raise an exception.
var test = a + 1;
//a is not defined
Instead of javascript throwing Uncaught ReferenceError: a is not defined , using logerr will output something like
Type
:
error
Error
:
Uncaught ReferenceError: a is not defined
File Name
: logerr.js
Path
: http://localhost:8888/logerr/logerr.js
Line
: 51
Column
: 12
Date
: Tue Jun 28 2016 19:51:22 GMT+0530 (IST)
Debug
: http://localhost:8888/logerr/logerr.js:51
Get Help
:
https://stackoverflow.com/search?q=Uncaught+ReferenceError:+a+is+not+defined
<!DOCTYPE html>
<html lang="en">
<head>
<script src="
logerr.js
"></script>
<script>
Logerr.init();
</script>
</head>
<body>
Am fancy
</body>
</html>
Make sure you have CORS enabled if logging cross-domain.
Logerr.init({
remoteLogging: true,
remoteSettings: {
url: 'REMOTE_URL',
additionalParams: {
logged_by: 'Sam'
},
successCallback: function () {
console.log('Im logged.');
},
errorCallback: function () {
console.log('Err! Something went wrong.');
}
}
});
detailedErrors: true
//Boolean true/false, Optional
remoteLogging: false
//Boolean true/false, Optional
remoteSettings: {
//Object {}, required if remoteLogging is set to true
url: null,
//String '', required if remoteLogging is set to true
additionalParams: null,
//Object {}, optional
successCallback: null,
//function() {}, optional
errorCallback: null
//function() {}, optional
}