Log JavaScript Errors Using an AJAX-driven Web Service | 2 | WebReference

Log JavaScript Errors Using an AJAX-driven Web Service | 2


Log JavaScript Errors Using an AJAX-driven Web Service [con't]

Garson cleverly creates a new Image object to send the log entry via what he calls a "fire-and-forget" GET request:

The last step is to disable the error handler as subsequent errors tend to be noise—a byproduct caused by cascading effects from the first problem. Hence, they are not usually very useful and can be ignored. A handler can easily be cleared by assigning a null to it:

Developers can then read error reports in real-time on the ScriptCanary site or get daily updates in an RSS reader:

Sample Error Report

Error details include the date, description, URL, line number, browser name and version, and the User Agent string:

Error Details

The Server Component

On the server, you can choose from any number of web languages to parse the input parameters from the URL and save the error details. It is also possible to send an email out to developers informing them that an error has occurred. The .NET Framework provides a class called SmtpMail for ASP.NET applications. It can be found in the library System.Web.Mail namespace. To include a Reference to the file, right-click on References in your Project explorer and click on Add reference:

For those of you who aren't inclined to write all of the server code yourselves, I would strongly suggest that you consider using a reporting service like ScriptCanary. It's inexpensive and easy to use. In fact, the ScriptCanary service will be completely free until March 1, to encourage people to give it a try. Thanks to Dorian for sharing his innovative ideas with me.


Have an suggestion for an article topic? Do you have a product or service that you'd like reviewed? Email it to Rob at

Rob Gravelle combined his love of programming and music to become a software guru and accomplished guitar player. He created systems that are used by Canada Border Services, CSIS and other Intelligence-related organizations. As a software consultant, Rob has developed web applications for many businesses and recently created a MooTools version of PHPFreechat for ViziMetrics. Musically, Rob recently embarked on a solo music career, after playing with Ivory Knight since 2000. That band was rated as one of Canada's top bands by Brave Words magazine (issue #92) and released two CDs. Rob's latest, entitled KNIGHTFALL, was a collaboration between himself, the former Ivory Knight vocalist, and legendary guitarist/producer, Jeff Waters of Annihilator fame. Rob is available for short-term software projects and recording session work. to inquire, but note that, due to the volume of emails received, he cannot respond to every email. Potential jobs and praise receive highest priority!