14

I need to debug obfuscated JavaScript like this example:

__d("DataStore",[],function(a,b,c,d,e,f){var g={},h=1;function i(l){if(typeof l=='string'){return 'str_'+l;}else return 'elem_'+(l.__FB_TOKEN||(l.__FB_TOKEN=[h++]))........

JavaScript debuggers embedded in MSIE, Opera and Chrome do not understand that JS uses semicolons and not CRLF as a line breaks; so it is impossible to debug a script like that, because entire function is located on one large line, and the debugger always highlights this one line disallowing me to see what part of code is actually executed.

Is there any way to debug JavaScript files that contain a very long line of code and don't use CRLF to separate code lines?

0

4 Answers 4

36

The Chrome devtools "Scripts/Sources" pane has a "pretty print" mode (look for the {} button in the bottom toolbar).

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

1 Comment

returned to frontend and completely forgot about this small icon. Thank you
3

Use a Javascript Beautifier to reformat the code and then debug the code.

Check out http://jsbeautifier.org/

Comments

1

Google Chrome has a "Pretty print" function that allows to reindent the code.

I don't normally use it, so I don't know since when it exists, but it's present in Chrome 21 dev.

Comments

1

There is no single solution for this. The first thing you can to to have something a bit more readable is to copy/paste the javascript code into http://jsbeautifier.org/

1 Comment

not directly your chrome solution seems better if it works. But you can modify the script tag to load the beautified version and then debug it.

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.