Monday 29 December 2014

Debugging in IE with Visual Web Developer: Breakpoint cannot be set in this location, the code in the document is not loaded

Today I was testing one of my websites in IE7, and had an error message popping up, saying there was a javascript error, and would I like to debug it. So I clicked Yes, but nothing happened.

I opened Visual Web Developer 2010 Express to start debugging from that, since there is no Developer Tools for debugging js in old versions of IE. I started debugging, loaded the page, and got the same message. Clicked OK to debug, but nothing happened still. In Visual Web Developer it had opened the js file where the error had occured, but it hadn't paused the script at all. I couldn't see any error at the line the error was occuring.

So I tried adding a breakpoint before where the error was occuring, but the breakpoint was a yellow outline of a circle with a small warning notice, rather than the usual filled red circle. Hovering the mouse over the breakpoint gave a tooltip that stated Breakpoint cannot be set in this location, the code in the document is not loaded. Strangely I couldn't set any breakpoints at all in this script file, they all gave the same result (and wouldn't be hit when running the page, yet the error caused by that script file was still occuring).

I found a list of suggested solutions here: ie8 javascript not running or loading. However, none of them helped. Eventually I had to try commenting out a block of js in the javascript file, refreshing and seeing if the error still occured. If not, comment out a smaller block to try and find exactly where the error was occuring.

After doing this I found what the issue was, and it was about where IE said it was (technically IE gave the correct line number, but I needed to look very carefully at the line above to spot the error). The problem was that I was declaring an object with various properties, but I had a trailing comma after the last property. So IE was being better than the other browsers by flagging this, and it was just a case of me not being able to spot the issue.

No comments: