Internet Explorer and console.log woes

Posted in Web Development on by Jeff

I cannot begin to count the number of hours I have wasted trying to figure out what the hell Internet Explorer is doing. This latest one really threw me for a loop, so I thought I would share what I learned so someone else doesn’t waste the time that I did.

Internet Explorer does not support console.log but you will never know that once you open the Developer Tools!

Internet Explorer 8′s javascript support is less than stellar. Its better than it was, but still far from perfect. If you are like me, you probably develop your apps with a real browser like Chrome, Safari, or perhaps some of  are still using Firefox. Then you run it in IE and hope for the best. So when I finished coding a new release today, everything ran fine in IE so out the door it went.

Sure enough, a few hours later, the client comes back reporting a bug. My javascript was broken but for the life of me I couldn’t find where or why. It turns out that I had gotten lazy and left an unwrapped console.log message in my code. There are a million blogs out there that show you how to safe guard against this for IE  (window.console && console.log && console.log(“foo bar”); ). But I was lazy.

I admit… its partially my fault. But here is why I hate IE – once you open the Developer Tools, console.log is available from that point forward. An end user that has no idea what the Developer Tools are will see code that crashes due to an “Unsupported Object or Property”, essentially a Null Pointer Exception. But as a developer who has used the Developer Tools, everything works fine and dandy. Ugh.

So take heed. Don’t be lazy and leave unchecked console.log messages in your code. If you do, it could cause trouble for your users without you even realizing it.

One Response to Internet Explorer and console.log woes

  1. harlo says:

    Seriously, thank you. Although I wish it wasn’t 2:45 in the morning on a Friday night, and I had found this post 4 hours ago!

Leave a Reply