0

I catch JS errors by subscribing to window.onerror event, so if someone catches 'undefined variable' error, I send it to server for debugging purposes. As you know this event return 'message of error', 'url' and 'line' where error occurred.

The problem are in compressed files.

If file is compressed, all the code goes in one line and it's big problem to determine the exact place of error.

Is there any solution for this problem?

Denis
  • 2,429
  • 5
  • 33
  • 61

4 Answers4

0

No. There is no way to "unminify" a JavaScript include for the purposes of error logging.

Your best bet is probably to log the Error Type in the hope that this will help you debug the problem.

If you really want to get to the specific line number you would have to remove the minimization and rely on browser caching to attain performance.

Dave
  • 10,748
  • 3
  • 43
  • 54
0

JavaScript compressors usually do two things:

  1. Remove all unneccessary white-space (“unneccessary” in terms of syntactical validaty).
  2. shorten variable names, if possible. This applies to local variables, i.e. those which are not in the global scope or members of an object.

There are some other optimizations, such as function inlining, but these are usually not so problematic.

As for the first point, you can run the code through one of the many JavaScript source formatters. This should give you a pretty readable JavaScript file.

As for the second point, the obfuscation is usually not reversible. If “speaking” variable names like width, height or whatever have been changed to a or b, you cannot know what they were meant to express in the first place.

If this problem applies to an open source product, you can usually download the sources and try to reconstruct the problem with them.

If it's closed source, and only “beautifying” the code doesn't help, you have to write a bug report to the vendor.

lxg
  • 12,375
  • 12
  • 51
  • 73
0

I think you could use source maps... Its a file that can be generated when minifying, and can be used to map the line/character of the minified file to the original source.

http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/

Tiago Coelho
  • 5,023
  • 10
  • 17
0

The best answer regarding this question I found here

Malyw suggests yo use Uglify with max-line-len option and sourcemaps.
That's probably the best solution to identify exact place in code

Denis
  • 2,429
  • 5
  • 33
  • 61