Over the years, I have encountered a few web developers who ignore client side (JavaScript) errors in their applications. Some have even asked me for ways to suppress client-side errors all together. With the growing amount of client-side code in web applications, this is a big concern.
It may seem to some that JavaScript errors are inconsequential, but this is not the case. They are errors just like any other. Whenever an error occurs, your application is no longer doing what you designed it to do.
The problem might have to do with the separation of client and server. Developers may feel that nothing can be done about client-side errors because they aren’t notified of them as they are when a server-side error occurs.
This is why I have decided to release a server control designed to allow .Net developers to log JavaScript errors on the server the same way they can log server-side errors. The control has a very small footprint. It’s simple to use. And it takes up no visible space on the page.
The control uses window.onerror to capture JavaScript errors and send the error information to the server using the iCallbackEventHandler interface (note: As of this writing, window.onerror doesn’t work in Google Chrome). Whenever a JavaScript error occurs, the control raises an event on the server that can be handled in the page.
To use the control is very easy. Simply add this to your markup:
<cc1:JSErrorNotifier ID="JSErrorNotifier1" runat="server"
OnJavaScriptError="JSErrorNotifier_JavaScriptError">
</cc1:JSErrorNotifier>
and this to your code-file:
protected void JSErrorNotifier_JavaScriptError(object sender, WebControls.JavaScriptErrorEventArgs e)
{
e.DisplayMessage = "A JavaScript error has been received by the page";
}
This software is subject to the Microsoft Public License (Ms-PL)