Internet Explorer reporting Invalid Character errors when debugging with Visual Studio
The following is search-engine bait; I didn't get any hits when trying to track this down.
I normally do my first pass of Web page testing using Chrome, but when I published the source to travellermap.com I was sent a report by a developer that when debugging with IE he was seeing errors.
Here's how to reproduce the problem:
I normally do my first pass of Web page testing using Chrome, but when I published the source to travellermap.com I was sent a report by a developer that when debugging with IE he was seeing errors.
Exception was thrown at line 15, column 399 in http://www.google-analytics.Whoah - errors in Google, Facebook, and Twitter scripts? As background, those are the scripts behind the "social" widgets for "+1", "Like" and "Tweet" widgets that appear on pages such as http://travellermap.com - but how could those errors be appearing without the whole Intarwebz being up in arms? They didn't show up on the console in Chrome... nor in IE. (Win7/IE10).com/ga.js
0x800a139e - JavaScript runtime error: aborted
Exception was thrown at line 28, column 1602 in http://connect.facebook.net/en_US/all.js#xfbml=1 0x800a03f60x800a03f6 - JavaScript runtime error: Invalid character
Exception was thrown at line 13, column 1602 in http://static.ak.facebook.com/connect/xd_arbiter.php? version=25 0x800a03f60x800a03f6 - JavaScript runtime error: Invalid character
Exception was thrown at line 13, column 1602 in https://s-static.ak.facebook.com/connect/xd_arbiter.php? version=25 0x800a03f60x800a03f6 - JavaScript runtime error: Invalid character
Exception was thrown at line 17, column 915 in https://apis.google.com/js/plusone.js0x800a139e - JavaScript runtime error: InvalidCharacterError
Here's how to reproduce the problem:
- Create a project in Visual Studio Express 2012 for Web
- Add blank web page, set it as the startup page (right-click in the Solution Explorer)
- Use Facebook's wizard on http://developers.facebook.com/docs/reference/plugins/like/ to generate the code for a Like button, copy/paste it into the page's source
- Make sure that Internet Explorer is selected as the debug target in the Visual Studio toolbar
- Click Debug in the Visual Studio toolbar
- View the Output window
Digging into the above scripts, it turns out there's a simple repro that matches what they're doing:
<script> try { JSON.parse('"\t"'); } catch (e) {} </script>
That is, they're parsing an invalid JSON fragment and catching the exception. But why? It turns out that at least the Facebook instance is due to a specific line in the "JSON3" library. The library is probing for known bugs in browser JSON implementations, to see if the built in JSON.parse() method is "safe enough"to use, or if a JS implementation should be used instead.
So this is good news: the site and script are fine - everything is working as intended. Internet Explorer is just being chatty when exceptions are thrown because you, as a developer, might want to be aware of them even if they're being caught.
(I admit, I didn't look at all of the errors. I'm assuming the rest are variations of this case.)
Comments
Post a Comment