8

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.

Tom Kidd
  • 12,830
  • 19
  • 89
  • 128
  • What does line 718 look like? IE usually specifies the line-number + 1 in it's error dialog. – Jared Oct 07 '08 at 16:49
  • Can you put the version in the subject? Apparently IE 8 is a lot better about the line number... – benc Apr 01 '09 at 00:30
  • Also, maybe you could change the subject and description to indicate that this is a situation where you are analyzing an end-user problem. Hence, you cannot use a debugger. (I'm in a similar situation, so I'm watching this thread carefully). – benc Apr 01 '09 at 00:32

10 Answers10

5

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.

noah
  • 21,289
  • 17
  • 64
  • 88
  • I was gonna say it if you weren't - it feels wrong to say, "no, you can't do that," but in IE's case... sometimes you've gotta say it. – matt lohkamp Oct 07 '08 at 20:36
3

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.

Matt R
  • 2,577
  • 5
  • 30
  • 46
3

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.

EndangeredMassa
  • 17,208
  • 8
  • 55
  • 79
  • this looks useful - I didn't know the developer toolbar had this option before - thanks! – matt b Oct 07 '08 at 15:44
  • This is pretty handy - but doesn't help me in this instance I'm afraid. It produces source code that doesn't have enough lines and doesn't include JavaScript inline (if that's the issue). The crux of this issue is that the only thing I have to go on is a line number which is apparently useless. – Tom Kidd Oct 07 '08 at 15:49
3

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

Robert J. Walker
  • 10,027
  • 5
  • 46
  • 65
2

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.

dlamblin
  • 43,965
  • 20
  • 101
  • 140
2

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

1

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

Zombies
  • 25,039
  • 43
  • 140
  • 225
  • "View Source" will return the source of the document - not any javascript files included with script src="blah" – matt b Oct 07 '08 at 15:39
  • This project kills Firebug for IE (I've tried it), probably due to the ActiveX involvement. – Tom Kidd Oct 07 '08 at 15:39
1

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.

steve_c
  • 6,235
  • 4
  • 32
  • 42
  • The ActiveX involvement negates being able to try this in Firefox. – Tom Kidd Oct 07 '08 at 15:40
  • OK, so then I would enable script debugging in IE. To do this: tools > Internet Options -> Advanced -> uncheck 'Disable Script Debugging (Internet Explorer) This will allow you to break into a debugger (such as VS.NET) and will highlight the line where the error occurs. – steve_c Oct 07 '08 at 15:44
  • Yeah, and this is what I do locally, but the user/tester that's having this issue does not have any development software so they can't debug nor can I debug remotely. – Tom Kidd Oct 07 '08 at 15:50
1

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

matt b
  • 138,234
  • 66
  • 282
  • 345
0

I use Web Development Helper

sebagomez
  • 9,501
  • 7
  • 51
  • 89