This tutorial is out of date and no longer maintained.
Over the last few years, browsers got some superpowers. They evolved from simple viewers for HTML & CSS to platforms executing our beloved web applications.
This is opening the doors for developers to do incredible things. And this is awesome. However, there is one big challenge that comes with every new shiny application.
With everything that is new, chances are high for bugs and issues to occur.
With Usersnap, I’ve found a great solution for that: its console log recorder enables me to record client-side JavaScript errors. One by one.
In this tutorial, I’ll walk you through the process of setting up the client-side of JavaScript error logging.
There are a couple of reasons why client-side JavaScript errors have become more and more important to log than ever before.
First, JavaScript is the most popular programming language of the web. With new JavaScript libraries going mainstream every day, developers are demonstrating that almost everything is possible inside browsers.
The short answer is: Because writing good code is hard. And reproducing client-side errors is even harder.
Especially if you’re using non-trivial JavaScript in your codebase, you will have a hard time finding those bugs. Just think about all these different browser versions and devices for a moment.
Let’s keep this short. Too few websites log JavaScript errors. – Karl Seguin
The basic problems of client-side JavaScript errors are:
At this point, you probably agree that it is time for a way to attach the console output to get high-quality bug reports.
With the use of the Usersnap console recorder I found a great solution for recording, reproducing, and fixing front-end errors.
Basically, the Usersnap Console Recorder is a tool to record every front-end error, such as XHR traces, JavaScript exceptions, etc.).
And it sends this information along with an annotated screenshot to the developer of the site.
The setup process for the Usersnap console recorder is simple:
You can sign up for a free Usersnap trial here. Create the first project and add the URLs you want to track.
After creating your first project, you need to add the URLs of your site and embed the Usersnap widget.
It’s pretty simple and there are also available plugins for various CMS available.
After you embed the javascript widget on your site or app, you’ll see a little feedback button on your site.
The feedback button is fully customizable in the project settings.
Enabling the console recorder is very easy. Open the widget configuration tab in the project settings and click on “change color and features of the widget”.
Enable the console recorder feature by clicking on the on/off checkbox.
Every submitted report will now contain the log output in the Usersnap dashboard.
You’re done. Every created bug report with the embedded Usersnap feedback widget will now attach client-side errors as well.
In our example below, we see that there is an error:
Uncaught SyntaxError: Unexpected token {
We also see the call stack, and it looks like JSON.parse
method failed.
Imagine that this JSON was generated specifically for a client’s account. Without this error log, the only way to reproduce the issue would be to log into your user’s account and repeat the same actions your user made. In most cases, this isn’t possible.
According to my experience, the console recorder works with every modern web framework out of the box.
However, there are some limitations listed in the documentation of the console recorder.
Errors that occur very early (e.g., a body onload function that fails) could be missed by the recorder. Usersnap is loaded asynchronously to not hit your page loading time and therefore this might be missed.
If you are using AngularJS, the console recorder needs a little modification from your end.
If you add this library to your Angular JS project you’ll get AngularJS errors attached to your bug reports with the console recorder.
Inject it into your dependencies in your main app like this:
angular.module('yourapp', ["usersnapLogging”])
In most cases, we cannot access our user’s account in order to reproduce certain issues. The debugging of such client-side errors might take hours or even days.
The Usersnap console recorder fixes this problem and hands us the information we need to have.
As a developer, I’m now able to solve such client-side errors quickly. And most importantly, without spending too much time on finding my client’s bugs.
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!