4

I could never view a script correctly in Firebug,every one of them is displayed in one line.Like shown on the image below:

http://img716.imageshack.us/img716/1126/54274507.png How do I view it correctly so I could debug it?

Thank you in advance!

Ivan Prodanov
  • 34,634
  • 78
  • 176
  • 248
  • Related question: [4279319: Is there a plugin that allows me to automatically unminify the Javascript included on a site?](http://stackoverflow.com/questions/4279319/is-there-a-plugin-that-allows-me-to-automatically-unminify-the-javascript-include) – Henrik Heimbuerger Jan 07 '11 at 16:09

3 Answers3

3

This script has been minified by removing all extraneous whitespace.

You cannot easily debug such scripts.

Scripts that you write yourself and that are not minified or compressed will appear on normally on multiple lines and can be debugged.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • 2
    Minifying (as noted in Umair's answer) also often changes variable names to be as short as possible (generally a single character) to save even more bytes. – Cameron Feb 10 '10 at 20:19
0

Script writers minify and often change variable names to difficult alphanumeric names, basically wanting the script to be least human readable so that no one copies their code/logic, as one can easily do that using firebug and similar stuff. such scripts can be a real pain to debug and there are very few chances that you will be able to understand this one. All the best with the task anyhow.

have you tried debugging it anyhow by having a breakpoint on this only available line ?

Umair Jabbar
  • 3,596
  • 5
  • 30
  • 42
  • 2
    Minifying is also useful for reducing the download size of the JavaScript, thus making the page load faster. – aem Feb 10 '10 at 20:20
  • yeah correct the basic aim foe minification and merging scripts into one is lower page load times, i didn't mention that here in details just because the issue was related to debugging a minified script. Thanks for mentioning it too – Umair Jabbar Feb 11 '10 at 08:02
  • @Umair: `..basically wanting the script to be least human readable so that no one copies their code/logi`. As stated the main reason for minification is size and not security. Otherwise jQuery or other library providers would not offer the un-minified version to download in the first place. – Nope Aug 05 '12 at 23:40
0

For your own scripts, simply call:

console.log(someObject);

I usually hang around the "Console" tab, and see which errors or logged items come in, or use the console itself to type in code I want to run.

I never use the "Script" tab.

If you just want to view the code nicely, use a beautifier:jsbeautifier.org

Avindra Goolcharan
  • 4,032
  • 3
  • 41
  • 39
  • 1
    Thank you! Just what I was searching for. – Ivan Prodanov Feb 10 '10 at 20:20
  • 3
    You're kidding, right? The scripts tab is by far the most useful firebug tab. You can step in and debug your code, set watches, inspect variables, etc. Basically it lets you see your code, living and breathing; and you can modify that code on the fly to test assumptions about how you think it is supposed to work. I'm sorry, but to just blow all of that off and say console.log is good enough... madness! – Justin Ethier Feb 10 '10 at 20:24
  • Debugging using the Console tab and the DOM Inspector work fine enough for me, with the least glitches. I don't use "Script" because I remember I had far too many problems with it. Maybe it's better now? – Avindra Goolcharan Feb 10 '10 at 20:48
  • @Justin Ethier: but that just doesn't work if the code is minified, as is the case for the question we're discussion here. Or do you know a workaround for using the Script tab then? (A common problem when writing Greasemonkey scripts, for example.) – Henrik Heimbuerger Nov 24 '10 at 15:36
  • 1
    @hheimbuerger - Fair enough, although typically a non-minified version is available if you need it for debugging purposes. Or you could generate it using the jsbeautifier this answer mentions. Then you would just swap in the non-minified version to use for debugging. To get back to my original point, simply ignoring the Script tab is to ignore perhaps the most powerful feature that FireBug offers. – Justin Ethier Nov 24 '10 at 17:22