Did this JavaScript break the console?

As discussed in the comments, there are actually many different ways of constructing a string that causes this issue, and it is not necessary for there to be two percent signs in most cases.

http://example.com/%
http://%%%
http://ab%
http://%ab
http://%zz

However, it’s not just the presence of a percent sign that breaks the Chrome console, as when we enter the following well-formed URL, the console continues to work properly and produces a clickable link.

http://ab%20cd

Additionally, the strings http://%, and http://%% will also print properly, since Chrome will not auto-link a URL-link string unless the http:// is followed by at least 3 characters.

From here I hypothesized that the issue must be in the process of linking a URL string in the console, likely in the process of decoding a malformed URL. I remembered that the JavaScript function decodeURI will throw an exception if given a malformed URL, and since Chrome’s developer tools are largely written in JavaScript, could this be the issue that is evidently crashing the developer console?

To test this theory, I ran Chrome by the command link, to see if any errors were being logged.

Indeed, the same error you would see if you ran decodeURI on a malformed URL (i.e. decodeURI('http://example.com/%')) was being printed to the console:

[4810:1287:0107/164725:ERROR:CONSOLE(683)] “Uncaught URIError: URI malformed”, source: chrome-devtools://devtools/bundled/devtools.js (683)

So, I opened the URL chrome-devtools://devtools/bundled/devtools.js in Chrome, and on line 683, I found the following.

{var parsedURL=new WebInspector.ParsedURL(decodeURI(url));var origin;var folderPath;var name;if(parsedURL.isValid){origin=parsedURL.scheme+"://"+parsedURL.host;if(parsedURL.port)

As we can see, decodeURI(url) is being called on the URL without any error checking, thus throwing the exception and crashing the developer console.

A real fix for this issue will come from adding error handling to the Chrome console code, but in the meantime, one way to avoid the issue would be to wrap the string in a complex data type like an array to prevent parsing when logging.

var x = "http://example.com/%";
console.log([x]);

Thankfully, the broken console issue does not persist once the tab is closed, and will not affect other tabs.

Update:

Apparently, the issue can persist across tabs and restarts if Preserve Log is checked. Uncheck this if you are having this issue.

Update 2:

As of Chrome 40, this issue is fixed.

Leave a Comment