Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any good or reliable way to figure out where a JavaScript error is using only an Internet Explorer error message?

I'm writing an app which for various reasons involves Internet Explorer (IE7, for the record), ActiveX controls, and a heroic amount of JavaScript, which is spread across multiple .js includes.

One of our remote testers is experiencing an error message and IE's error message says something to the effect of:

Line: 719
Char: 5
Error: Unspecified Error
Code: 0
URL: (the URL of the machine)

There's only one JavaScript file which has over 719 lines and line 719 is a blank line (in this case).

None of the HTML or other files involved in the project have 719 or more lines, but the resulting HTML (it's sort of a server-side-include thing), at least as IE shows from "View Source" does have 719 or more lines - but line 719 (in this case) is a closing table row tag (no JavaScript, in other words).

The results of "View Generated Source" is only 310 lines in this case.

I would imagine that it could possibly be that the entire page, with the contents of the JavaScript files represented inline with the rest of the HTML could be where the error is referring to but I don't know any good way to view what that would be,

So, given a JavaScript error from Internet Explorer where the line number is the only hint but the page is actually spread across multiple files?

UPDATE: The issue is exacerbated by the fact that the user experiencing this is remote and for various network reasons, debugging it using something like Visual Studio 2008 (which has awesome JavaScript debugging, by the way) is impossible. I'm limited to having one of us look at the source to try and figure out what line of code it's crapping out on.

UPDATE 2: The real answer (as accepted below) seems to be "no, not really". For what it's worth though, Robert J. Walker's bit about it being off by one did get me pointed in the right direction as I think it was the offending line. But since that's not really what I'd call good or reliable (IE's fault, not Robert J. Walker's fault) I'm going to accept the "no, not really" answer. I'm not sure if this is proper SO etiquette. Please let me know if it's not via the comments.

like image 821
Tom Kidd Avatar asked Oct 07 '08 15:10

Tom Kidd


People also ask

Which JavaScript function is most useful for finding errors?

log() is a good way to debug errors but setting breakpoint is a faster, efficient and better method. In this method, Breakpoints are set in code which stops the execution of code at that point so that the values of variables can be examined at that time.


9 Answers

In short. Not really. Try finding the error in FF first, and if that fails, you can get an almost as good debugger with Visual Web Developer. Debugging IE just sucks for the most part.

like image 59
noah Avatar answered Sep 27 '22 15:09

noah


The web developer toolbar in IE7 can give you a rendered source view.

View > Source > Dom (Page)

This might be more accurate when you consider the line numbers provided by IE for script errors.

like image 33
EndangeredMassa Avatar answered Sep 25 '22 15:09

EndangeredMassa


The best way I found to debug javascript was to add several Response.Write() or alert message near the place i believed the code broke. The write or alert that doesn't show is closest to the problematic area of the code.

I did it this way because I haven't found an easier way.

Update: If you use this method of debugging you can use the writes/alerts to the contents of variables as well.

like image 27
Matt R Avatar answered Sep 27 '22 15:09

Matt R


Tip: I find that many IE error message line numbers are off by one!

like image 36
Robert J. Walker Avatar answered Sep 26 '22 15:09

Robert J. Walker


By installing firebug lite on your server for that page:

<script type='text/javascript' 
    src='http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js'>
</script>

you can log to a virtual console with,

firebug.d.console.log("stuff and things")
firebug.d.console.dir( {returnedObject:["404", "Object Not Found"]} )

and ask your remote tester to get more details for you by pressing F12.

I sort of suspect there's an unterminated string or an unmatched parenthesis or bracket out there.

like image 45
dlamblin Avatar answered Sep 29 '22 15:09

dlamblin


Nope, there isn't a way to make the built-in exception message suck less.

Instead you'll need to use a debugger with IE. The best tutorial I've found for this is here:

http://www.berniecode.com/blog/2007/03/08/how-to-debug-javascript-with-visual-web-developer-express/

Follow these instructions and when an error or exception occurs you will be shown the exact line in the correct file. You'll also see the value of variables in the current scope and you can setup "watched" items to help you debug.

Aside from that, if you need logging and CSS Cascade inspection like Firebug I've had good results with DebugBar and JSCompanion:

http://www.debugbar.com/ http://www.my-debugbar.com/wiki/CompanionJS/HomePage

like image 25
morganizeit Avatar answered Sep 29 '22 15:09

morganizeit


Try Firebug. I is available for IE: http://getfirebug.com/lite.html

like image 22
Zombies Avatar answered Sep 25 '22 15:09

Zombies


Have you checked whether this error is also present in Firefox using Firebug? That would be my first step in attempting to figure out where this error is occurring.

If it isn't present in Firefox, then I would progress to enabling script debugging in IE.

like image 34
steve_c Avatar answered Sep 26 '22 15:09

steve_c


My only advice: don't use IE for debugging like this. It's the absolute worst of the mainstream browsers: I try to use Firefox (with Firebug) or Chrome/Safari to handle most issues.

If you absolutely have to use IE, install the IE Developer Toolbar (which doesn't seem to help much with JavaScript errors), and/or install the Script Debugger

like image 43
matt b Avatar answered Sep 29 '22 15:09

matt b