Hacker News new | ask | show | jobs
by madethemcry 3033 days ago
One of the first heisenbugs I encountered was IE8's console.log.

That object/function was only defined when the developer tools were open. Otherwise you would get an exception (but of course you couldn't see that exception in any place).

Daily effect was funny: When you forgot a console.log in your code your page JS would hang. When you tried to debug it by opening the developer tools everything worked- and you started to doubt your sanity pretty soon.

I wasted hours of my life with that.

2 comments

But... how on earth did that escape QA? I mean surely even whoever was developing IE8's developer tools would have had accidentally forgotten a console.log() or two during development, surely?
You have to be mindful of the fact that IE8 was the first IE to have console.log[0] and that as a result it is possible that it wasn't used by the developers. It's also possible they always had the console open during development.

How did this ever manifest itself? The only thing that seems a plausible explanation is that the console injects the console object or the console.log function into the global JavaScript scope when it is opened and according to the behaviour described and either garbage collected or removed from scope when the console was closed. This seems like it could have only really been the intended behaviour.

[0] https://developer.mozilla.org/en-US/docs/Web/API/Console/log...

This is one of my "favorite". I often remind junior developers who just started coding in the last few years about stuff like this since a lot of our client's still insist on IE8 support (thankfully not IE 6 or 7 anymore).

Another fun one was dangling commas in arrays, which breaks IE 7 and lower.

It used to be somewhat common to put something like this at the top of scripts:

if ( window.console == undefined ) { window.console = { log: function() { }; }