2

I have a window.onerror handler that sends JavaScript errors to our server. I was hoping to analyse these by using source maps to link errors in the minified source back to the original code, but it seems Chrome and Firefox only provide line numbers on error. As far as I can see, source maps are not useful without a column number.

So, given a line number of minified source and an error message of the form x is undefined, what steps can I take to debug?

(If it makes any difference, I'm using the asset pipeline in Rails 3.2).

4
  • 12
    ditch the minified code while debugging and use the full-blown original code. Commented May 8, 2013 at 15:46
  • Expand your minified code with jsbeautifier.org, then check the line number of the error, if you can't look at the original source. Commented May 8, 2013 at 15:49
  • Further to this, if you only have the minified code for some reason, you can stick it through JSBeautifier to make it readable: jsbeautifier.org Commented May 8, 2013 at 15:49
  • I assume you've read sites like this and this. The screenshots in both those pages show Chrome giving column numbers for errors and thus making Source Maps work, so it clearly is possible. However I note that they describe Source Maps as being an experimental feature you need to enable explicitly in Chrome Canary, so perhaps that's what you're missing. Commented May 8, 2013 at 15:55

3 Answers 3

1

Chrome (and IE10) will now give you the column number as the fourth argument in the window.onerror callback. Here's the Firefox bug for adding column numbers, but it doesn't look too promising.

Sign up to request clarification or add additional context in comments.

1 Comment

Interesting, thanks for commenting. I ultimately ended up preserving line numbers, it seemed a reasonable compromise.
0

If you want to use Source Maps, you'll need to download Chrome Canary (ie the pre-release dev version of Chrome).

It's an experimental feature and isn't in the main Chrome release yet. (even in Canary it has to be switched on explicitly in the browser options).

1 Comment

Source maps work just fine for me locally - my issue arises when I try to debug an error that occurred for a user. The window.onerror handler is called with just three params, none of which is the column. developer.mozilla.org/en-US/docs/DOM/window.onerror
0

I recommend using firebug with firefox, here's a tutorial to get you started:

http://thecodecentral.com/2007/08/01/debug-javascript-with-firebug

I've used this a few times to debug really bad JS, however I usually just do this:

Firefox drop down > Web developer > Web console. This will show you the line # and the error being thrown (most important), which I find is typically sufficient without going through the debugging effort.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.