Amazing legacy bug in Google Chrome!

Published on
Nov 22, 2011

So you thought Google Chrome is almost perfect, bullet-proof, iz-da-browser, and, what say you? Sure, it would be unfair, almost untrue to claim the opposite, however, there is a neat bug, and you could argue that it's not a bug but a feature, and I could argue back, and... you got it.

But since the people who wrote the Chrome are from Venus and Mars, just like you and me, their main belief is that user's experience should be comfortable, easy, and fun. You could think that I'm getting paid for this implicit advertisement, but I'm not. What they did to Chrome is this: they taught him to automatically fix errors that a programmer presumably created. And since they're awesome, all this error fixing is of course super fast, it's realtime.

The problem? Sure there's a problem. It goes like that: when you have written some Javascript code which updates the innerHTML with some, say, unclosed <table> element, at this point of time, the browser will fix that line, and add the closing tag somewhere at the end. But hey - you would say - what if I provide the innerHTML with the closing tag on the next line? Well, it's too late, because, Google Chrome is amazing.

element.innerHTML = '' + "Some text with or withot HTML tags "; element.innerHTML += "Another textual string with or withot HTML tags"; element.innerHTML += '
';

And with legacy code, things like these can take a long time to determine. Days. Weeks. Don't believe me? Try to hide this somewhere in your website and tell your friends about amazing bug, which happens only in Chrome, and, surprisingly, not in IEs. But luckily, there's this article, so we're safe. The solution? Well, you already guessed. If not, here it comes:

var long_string = '' + "Some text with or withot HTML tags "; long_string += "Another textual string with or withot HTML tags"; long_string += '
'; element.innerHTML = long_string;

In this case, the browser eats the whole thing like a creamy chocolate cake with a lot of ganache, and everybody's happy.

So if you don't think it's a bug, please debug. But if you think it is a bug, please don't debug. In any case, I will be happy if you leave a comment, because, well, why not?

Also, by this chance, I'd like to introduce you our new project, and it's called Open Website Project. It is a place where the good people (!!), or in other words professionals like you can find fellows, and build something different together or just discuss interesting topic.. It's small, almost private, and that's the big difference. So long.