Error logging
Automatic and custom error logging.
Smartlook automatically catches all unhandled Javascript errors. However, Smartlook cannot log the precise error message if the error is from a script that is different in origin. This is known as a CORS (Cross Origin Resource Sharing) error. CORS is a set of APIs (mostly HTTP headers) that dictate how files should be handled when used from a different origin (domain).
When a CORS error occurs in the Smartlook Javascript console, you see this message:
Cross-origin error - look at https://smartlook.github.io/docs/web/error-logging/ for more info.
Fixing CORS errors
To fix any CORS errors:
- Add a
crossorigin="anonymous"
script attribute:
<script src="http://different-domain.com/script.js" crossorigin="anonymous"></script>
- Add a Cross Origin HTTP header:
Access-Control-Allow-Origin: *
You can use Smartlook’s Custom Errors API if you cant fix the CORS errors.
Custom errors API
With the Custom Errors API, you can customize how Smartlook logs errors that were handled in your application. You can then use these logs in Smartlook analytics and session recordings to visualize and understand where the errors occured.
Custom Errors API is used as follows:
smartlook('error', errorArg)
errorArg
errorArg
can be either an instance of the error object, or a simple string message.The maximum size of
errorArg
is 5kb.
Examples
try {
// ...custom code
} catch (e) {
// ...custom code that handles the error
// log error using Smartlook API
smartlook('error', e);
}
// ...custom code
// log some unexpected behaviour using Smartlook API
smartlook('error', 'calendar showing bad week');
Updated over 1 year ago