As with most web 2.0 platforms, a large part of the platform interaction on XING is handled via JavaScript. In total, 25,000 lines of code render dynamic content on our platform. Dragging and dropping the boxes of your start page, editing settings in your profile, a live search selecting your contacts when you type a new message – AJAX is just about everywhere.
The challenge: debugging user-sided script
Although this has many advantages, it’s also quite a challenge. In web 1.0 times, quality assurance consisted of ensuring a consistent design of the mostly static HTML on the user’s browser and debugging the code meant going through the CGI scripts running on your server – with known hardware, software and preferences.
A platform relying heavily on JavaScript changes this. The scripts run on many different browsers in many different versions whose JavaScript implementation may vary a lot. My colleague Ingo Chao wrote about the problem of degradation without grace. Now, where a non-standard interpretation of CSS might merely lead to an broken design, a script waiting for an event not set in the browser could lead to a drastically reduced functionality of some features. Plus, engineers are (despite to all rumors:) humans and thus make mistakes.
Compiling an error report
So how do we log JavaScript errors? Besides the internal testing on several browsers in different versions, we actually record all error messages that occur on the user’s side.
To do this, we use the event handler window.onerror:
window.onerror = function(errorMessage, url, line) { var loggerUrl = "https://www.xing.com/js/logger"; var parameters = "?description=" + escape(errorMessage) + "&url=" + escape(url) + "&line=" + escape(line) + "&parent_url=" + escape(document.location.href) + "&user_agent=" + escape(navigator.userAgent); /** Send error to server */ new Image().src = loggerUrl + parameters; };
So, whenever an error occurs, we record the user’s browser, the URL of both the script file and the HTML container, the code line and the error message in a log file. Private data such as the user id, the company, a possible premium membership or anything else that falls into that category is not transmitted. We record every error, from division by zero (unless you are Chuck Norris) to infinite loops. The only errors left out are those appearing in Internet Explorer 5.5 and earlier.
Based on the above mentioned URL and error message, the server then builds a hash as a unique id for this error. The catalogized errors are counted and sorted in descending order.
- URL: https://www.xing.com/app/profile?op=myprofile
- Line: 1369
- Parent URL: https://www.xing.com/app/profile?op=myprofile
- User Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6
- Count: 292
- Latest appearance: 2009-04-15 22:59:08
A cronjob initiates that an error report showing all messages and their frequency of occurence to the frontend engineering department so the team knows where it needs to focus. This way, we receive a list of errors that are often not even perceived by the end user, and we also know which errors are most pressing.




XING´s official twitter account
Link to this article:
http://blog.xing.com/2009/04/how-to-log-javascript-errors/trackback/
[...] View original here: net.work.xing – The corporate blog of XING » How to log JavaScript … [...]
net.work.xing - The corporate blog of XING » How to log JavaScript …Read more in
Recorded on 16.04.2009 at 21:45h CET
Leave a comment
Hi Christopher,
the concept of this logging function is very clever.
May I use it for my debugging projects?
By the way: the variable ‘url’ seems to be defined twice.
PC’L
Hey Peter,
Feel free to use it in your own projects.
…and thanks for the note on the variable “url”.
Cheers,
Christopher
One question remains: how do you determine the line number? I can only think of hard coding, but that would be stupid, because it’s hard to maintain.
And shouldn’t you use encodeURIComponent instead of escape? (OK that was a second question, but since it’s a rhetorical one you could count that as a statement.)
Hi Matthias,
the line numer is given by the browser. There’s no need to determine it manually.
Regarding your second question:
Thanks for the hint. We used “escape” in the beginning to track errors in old browsers that doesn’t support encodeURIComponent. This became obsolete after we decided to stop logging errors that were happening in old user agents.
Cheers,
Christopher
How do you protect your logger against abuse?
http://www.xing.com/js/logger?description=I%20hate%20this%20blog%20comment%21
Bastian
Hi Bastian,
we have set a limit of errors logged each day and our daily report only contains errors that occured more than a given number.
Cheers,
Christopher