JavaScript Errors in the Mainstream
I kept a list of a few major sites that have been bombing for me with JavaScript errors just today in the last few hours since I decided to write this up:
- Hawaiian Airlines
- Expedia
- Amazon's MP3 Download Site
- Facebook (Email app)
- Musician's Friend Checkout site
- Authorize.NET's Admin interface
- American Express Bill Payment
- Yahoo - certain news stories of the portal home page
And here are a few more non-high visibility ones (all today):
- PInvoke.NET
- Maui Weather Today
- Nova Savings Bank
- Bank of Hawaii
It's amazing to see errors so prominently in major online applications and not just in some offbeat obscure areas of Web sites. As more and more JavaScript is showing up on the client side it's inevitable that there are more errors cropping up, but it's surprising how many of these errors apparently are missed by site designers. Some errors are specific to Internet Explorer, some specific to FireFox, some happen in both, but errors there are plenty of.
I usually am curious as to what the nature of errors are and it seems there are two kinds of prominent errors:
- Load Errors
- DOM Elements are null
Load errors seem to occur because of timing typically. Content's not quite ready because JavaScript is accessing content that's not quite loaded yet. Other errors occur because - well - elements are just null. You look at the source and you find that this or that element that the JavaScript is referencing simply doesn't exist either because it wasn't loaded properly or because the designers simply fucked up.
Ironically most of the bogus code when I've looked at it has something to do with effects and fancy graphics arrangements in the page - shadows, popups, effects. Do we really need to have shadow code update after typing every character at the cost of a constant barrage of errors that page designers hope the browser will just eat and skip over?
But this really begs the question: Are site designers not even bothering testing at least in the two most popular browsers?
Most errors trigger in IE specifically which seems to indicate that more designers are targeting Mozilla, and starting to simply ignore IE's fucked up standard support. Maybe this is what it takes to get Microsoft to clean up IE once and for all. It used to be the other way around in that Microsoft was counting on site designers who wanted to make sure that 98% of the browsers out there work with their sites and other browsers be damned. Now it seems the tide is actually going the other way with more sites failing with IE and working with more standards compliant browsers, regardless of the fact that Microsoft still holds well over 80% of the browser share. Ironic, ain't it?
I's pretty frustrating to see so much bad Web code out there so prominently displayed for general consumption. To be fair though all of the errors I've run into are non-fatal errors. If ignored, pages continue to run apparently unencumbered. I guess that almost makes it more frustrating: what a lame piece of code it must be, if it isn't even missed if it doesn't fire? <g>
I'm railing in futility against this phenomenon because I happen to run frequently with IE and script debugging enabled. IE maddingly pops up a modal debugger dialog on every error:
If I abort the error the page usually continues to load and even work Ok despite the error, but some errors (like the one on Facebook's email message editor) apparently triggers on repeating events like a keypress or hover or mouseclick and I end up stuck on the page and have to kill IE. A modal dialog for the error is a killer in this scenario.
IE really needs a better way to deal with error handling - you have two choices: ignore errors altogether and show a completely worthless warning icon with incomplete error popup for the first error. Or you can go the full Script Debugging (Tools | Options | Advanced) route that pops up the modal blocking dialog on each error. For day to day browsing it would seem ideal to turn off script debugging, but then I use the debugger all day while working in Visual Studio for debugging my own JavaScript/Ajax code and I rarely turn off this option.
I know what you're going to say - don't use IE. Use FireFox or Opera which have better error handling and I do use FireFox most of the time. Firefox mercifully eats JavaScript errors and never throws up a modal dialog. But while FireBug for FireFox is very useful and cool for debugging on FireFox, it doesn't always work in all scenarios for debugging especially when debugging document (top) level script code. In addition, it's often necessary to debug IE specific issues inside of IE. And if you work in VS.NET the script debugging in VS 2008 is actually useful and often easier to work through than with FireBug in deep debugging scenarios when you need to inspect lots of objects and look up the call stack. You can't completely get away from not debugging in IE after all...
But, hey maybe those fancy Web Designers skip that step - they don't test for IE right? <g>
The errors I've been seeing though are hardly specific to IE though - some also show up in FireFox although FireFox in combination with FireBug certainly makes it much nicer to review the errors with an icon in the browser's statusbar and a quick access list to jump to the errors or at the very least be aware of the errors on the page.
FireBug however doesn't let you stop on an error and step into the code at the error (even as an option) either which on occasion is useful.
In the end I use FireBug for most of my debugging, IE for IE specific debugging and some heavy debugging scenarios where I need to step through lots of code - it's a lot of back and forth and I wish I could stick to one environment but it seems that's just not possible given browser DOM differences.
Ultimately though JavaScript error handling in browsers is pretty arcane. The actual JavaScript behavior is to ignore the error and abort the current block of code that's executing, but other code that follows outside of this block will continue to execute which can often result in less than accurate results and very unpredictable behavior. Trying to track down even errors in JavaScript event code is an excercise in sleuthing supreme as you get to back step through events several levels back to see where a failure occured.
It's no wonder there's so much bad JavaScript code out there - the tools are lacking.
Plain old HTML apps may have been clanky and conservative but they just worked. Now there's a lot of crap being introduced that adds little value, except try to feed our deficit attention spans and in the process make our lives more difficult. I'm all for fancier user interfaces and making applications more interactive and easy on the eyes, but when it comes to usability my first interest is that the application works! Everything else is secondary by a long shot.
There's little we can do with other sites. But we as developers ourselves can do the best we can with our own applications and not contribute to the problem. It's not always easy because JavaScript is inherently a runtime error detection environment. Let's ensure our apps at least don't bomb by testing at least with the two mainstream browsers. That's the least we can do for our users, no?
So, is this sort of thing happening to you as well frequently? Are you running with debugging features off or are you too suffering through dialogs and error displays on common Web pages?
The Voices of Reason
# re: JavaScript Errors in the Mainstream
Both files when debugged in VS2005 yield the following:
<HTML> <HEAD></head> <body> </BODY> </HTML>
# re: JavaScript Errors in the Mainstream
Google aren't without fault ether - Google Reader throw the following with Firefox 2 on Windows:
ul is not defined
http://www.google.com/reader/ui/1616651859-en-scroll.js?hl=en
Line 80
[)amien
# re: JavaScript Errors in the Mainstream
# re: JavaScript Errors in the Mainstream
Also... here this one. I'm somewhat known for my Firefox advocacy and I've done a popular video series on web development in Firefox... BUT... I must say that VS2008's attachment to iexplore.exe is phenomenal. Furthermore, while the web developer toolbar that MS ships is absolutely worthless, Nikhil Kothari's web developer helper is a very nice utility to help out with those moments when debugging IE makes you want to change careers.
I think a deeper problem is that most people have no understanding of JavaScript before they start hammering away at it. The idea of LEARNING something before DOING something is obsolete I suppose. If you have the title "web developer" or "software engineer", surely you know everything... right? Of course I see the same thing in .NET code as well. When you don't follow the framework design guidelines, you WILL get burned. Arrogant use of "subjectivity" and placing your opinions against it isn't something that's appropriate in a professional world. This is EXACTLY what I see in JavaScript constantly. People just do NOT get the idea of checking for undefined objects, they don't get the process of a page load, and also don't even remotely get the idea behind JavaScript scope. I actually hear people tell me "JavaScript scoping is stupid". How exactly does that statement change the fact that you still have to follow its rules??
The tools could use some help for sure, but I blame the people.
# re: JavaScript Errors in the Mainstream
# re: JavaScript Errors in the Mainstream
- Forrest
# re: JavaScript Errors in the Mainstream
Sounds like you're running an ad blocking host file, or some other filter. If you attempt to access those URLs directly, what do you get?
I've seen it quite a bit where users install a hosts file to remove ads, then wonder why they're getting tons of IE error dialogs..
# re: JavaScript Errors in the Mainstream
Jeff
# re: JavaScript Errors in the Mainstream
Beside a good built-in IE7 Script Debugger I would wish myself two tools: one would be a global JavaScript Error handler, that collects Script errors and sends them via AJAX to the server, from where the error can be logged or send by Email - just like the most Custom Error handlers for server-side code do.
Second would be a Website like validator.w3.org or other Markup/CSS validation services, just for JavaScript. It should test a given URL with he mainstream browsers in a sandbox and
returns a list of Errors, possibly with suggestions how to fix it. At least that would show up all load-errors ...
Tom
# re: JavaScript Errors in the Mainstream
# re: JavaScript Errors in the Mainstream
As one who's been thrown into JavaScript coding kicking and screaming myself I can relate to the difficulties in dealing with JavaScript. While I feel pretty confident with JS now, it took a while for the mindshift to kick in coming from 'conventional' languages. It doesn't help that JavaScript's been around forever but I like many others never really looked at it seriously until the AJAX rush started. Any way I look at it though JS (or DOM programming maybe) even with help of tools like jQuery feels very shaky at best.
However, testing - even if it's just top level UI testing - should be vital. It's really hard to see why so many sites are failing downright, especially bigger sites where it seems there surely must be somebody doing the final UI checking...
# re: JavaScript Errors in the Mainstream
Where are you getting that number from? The numbers I see reported vary pretty wildly depending on the source, but most have it around 55%.
# re: JavaScript Errors in the Mainstream
Good post. I wonder too why so many websites produces javascript-errors nowadays. I surf with IE7 with IE7Pro installed. And I do have AD Blocker enabled. Funny, I don't see any javascript errors on this site with AD Blocker enabled/disabled. I too have to run IE7 with debugging features off because of those annoying popups. My 2 cents (in euros ;)).
# re: JavaScript Errors in the Mainstream
What I've found is that most of the times it's the ads that contain the most errors.
# re: JavaScript Errors in the Mainstream
# re: JavaScript Errors in the Mainstream
@Rick: I'm really looking forward to playing with the new in place editing component you built with jQuery a couple weeks ago. Very neat!
# re: JavaScript Errors in the Mainstream
Right on the desktop the dialog says something like 'JavaScript error, do you want to continue?'
The users are unable to print Forms until I remote into the Server and click OK.
I may have to put all my JS statements in try/catch statements when .Net is generating it, but I was hoping for a quicker solution. Any ideas, Rick? Thanks for the great Blog. Say aloha to Hawaii for me.
# re: JavaScript Errors in the Mainstream