Javascript errors report
Feb. 7th, 2016 03:45 am![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
When users open my web site I want to know what JavaScript errors users have (if any).
That's why I append this javascript to almost every page on my web site:
Once per day our server aggregates these errors and emails to developers Javascript Errors report.
This is an example of what that report looks like:

We then review these errors on case-by-case basis and decide whether we want to fix that error or we want to suppress that error from report (because we can not fix it).
Still, there are challenges: sometimes it is hard to separate errors that we can fix from errors we can not fix.
For example, we can not fix the most frequent "Uncaught ReferenceError: google is not defined" error, because it is caused by occasional browsers that do not work well with Google Maps API.
But we do not want to suppress that error either, because sometimes, by mistake, we may introduce problem in our own javascript that would generate the same error messages on mass scale for our users.
See: discussion in ivan-gandhi blog.
That's why I append this javascript to almost every page on my web site:
window.onerror = function(errmessage, errurl, errline) { var params = { list: [], add: function(name, value) { if (value != null) this.list.push(name + '=' + encodeURIComponent(value)); return this; }, toString: function() { if (this.list.length) return '?' + this.list.join('&'); return ''; } }; new Image().src='/jeh' + params.add('errmessage', errmessage) .add('errurl', errurl) .add('errline', errline) .add('r', Math.floor((Math.random() * 10) + 1)); }That script reports javascript errors from user browser back to our server.
Once per day our server aggregates these errors and emails to developers Javascript Errors report.
This is an example of what that report looks like:

We then review these errors on case-by-case basis and decide whether we want to fix that error or we want to suppress that error from report (because we can not fix it).
Still, there are challenges: sometimes it is hard to separate errors that we can fix from errors we can not fix.
For example, we can not fix the most frequent "Uncaught ReferenceError: google is not defined" error, because it is caused by occasional browsers that do not work well with Google Maps API.
But we do not want to suppress that error either, because sometimes, by mistake, we may introduce problem in our own javascript that would generate the same error messages on mass scale for our users.
See: discussion in ivan-gandhi blog.
no subject
Date: 2016-02-07 03:21 pm (UTC)а можно её обвернуть в try catch с выдачей № браузера?
BrowserUserAgent
Date: 2016-02-07 03:25 pm (UTC)You do not need to do that.
When "new Image().src='...'" sends request to your server - your server has all that information available: IPAddress, BrowserUserAgent, Time + all data that is sent in errmessage, errurl, errline parameters.
no subject
Date: 2016-02-07 04:10 pm (UTC)no subject
Date: 2016-02-07 04:18 pm (UTC)Только сейчас kika предложил.
Но, мне кажется, не стоит подключать ещё одну систему. Лучше, чтобы всё выполнялось внутри сайта.
no subject
Date: 2016-02-07 06:29 pm (UTC)no subject
Date: 2016-02-08 01:43 am (UTC)no subject
Date: 2016-02-08 08:55 am (UTC)Why do you need to add a random value at the end of the error url?
Would you like to post server-side script which creates nice results table also? :)
no subject
Date: 2016-02-08 09:36 am (UTC)All following image requests would be cached.
With random value the same error can be reported up to 10 times from the same user.
2) Server-side code is quite a little longer and has multiple parts.
- Web handler that receives request from javascript and stores data to JavascriptException database table.
- Windows service that executes every day, produces HTML report and sends it by email.
To give you an idea, here is SQL script for JavascriptException table:
no subject
Date: 2016-02-08 10:06 am (UTC)I'm going to parse the logs with general bash approach...
no subject
Date: 2016-02-08 10:09 am (UTC)no subject
Date: 2016-02-08 10:14 am (UTC)no subject
Date: 2016-02-08 12:02 pm (UTC)2) Do you plan to manually run csv-file extraction from your log every day?
no subject
Date: 2016-02-08 12:05 pm (UTC)2. Cron
no subject
Date: 2016-02-08 12:12 pm (UTC)Are you appending javascript similar to what I showed in this posting to your web pages?
no subject
Date: 2016-02-08 12:21 pm (UTC)no subject
Date: 2016-02-08 12:24 pm (UTC)no subject
Date: 2016-02-08 01:24 pm (UTC)no subject
Date: 2016-02-08 10:15 am (UTC)