Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

422 lines (355 sloc) 19.735 kB
<!DOCTYPE html>
<!--[if lt IE 7]><html lang="en-us" class="ie6"><![endif]-->
<!--[if IE 7]><html lang="en-us" class="ie7"><![endif]-->
<!--[if IE 8]><html lang="en-us" class="ie8"><![endif]-->
<!--[if gt IE 8]><!--><html lang="en-us"><!--<![endif]-->
<meta charset="utf-8">
<title>Online JavaScript beautifier</title>
<link rel="icon" href="favicon.png" type="image/png">
<script src="third-party/codemirror2/lib/codemirror.js"></script>
<script src="third-party/codemirror2/mode/javascript/javascript.js"></script>
<link rel="stylesheet" href="third-party/codemirror2/lib/codemirror.css">
body {
background: #eee;
color: #333;
img {
border: 0;
a.self { font-weight: bold; text-decoration: none; color: #444; border-bottom: 1px solid #aaa }
p, select, label, .blurb, a.turn-off-codemirror {
font:13px/1.231 arial, sans-serif;
a {
color: #36d;
a.turn-off-codemirror {
margin-left: 25px;
button#submit {
clear: both;
margin-top: 5px;
width: 100%;
padding: 10px 0;
cursor: pointer;
#source {
width: 100%;
padding-left: 0;
padding-right: 0;
button#submit em {
font-size: 11px;
font-style: normal;
color: #999;
label {
cursor: pointer;
select {
width: 220px;
table#options {
float: right;
table#options td {
vertical-align: top;
padding-left: 10px;
#about p {
margin: 0 6px 6px 0;
li {
line-height: 150%;
li.writeme {
padding-top: 8px;
#testresults {
display: none;
font-family: monaco, "lucida console", "courier new", monospace;
.CodeMirror {
border: 1px solid #ccc;
margin-bottom: 6px;
background: white;
.CodeMirror-scroll {
min-height: 400px;
max-height: 100%;
height: auto;
overflow-y: hidden;
overflow-x: auto;
width: 100%
.contributors a {
white-space: nowrap;
<script src="third-party/jquery/jquery.js"></script>
<script src="third-party/jquery/jquery.cookie.js"></script>
<script src="beautify.js"></script>
<script src="beautify-css.js"></script>
<script src="beautify-html.js"></script>
<script src="tests/sanitytest.js"></script>
<script src="tests/beautify-tests.js"></script>
<script src="unpackers/javascriptobfuscator_unpacker.js"></script>
<script src="unpackers/urlencode_unpacker.js"></script>
<script src="unpackers/p_a_c_k_e_r_unpacker.js"></script>
<script src="unpackers/myobfuscate_unpacker.js"></script>
var the = {
use_codemirror: ( ! window.location.href.match(/without-codemirror/)),
beautify_in_progress: false,
editor: null // codemirror editor
function run_tests() {
var st = new SanityTest();
// $('#testresults').html(results.replace(/r/g, '').replace(/\n/g, '<br>'));
var results = st.results_raw().replace(/ /g, '&nbsp;').replace(/\r/g, '·').replace(/\n/g, '<br>');
function any(a, b) {
return a || b;
function read_settings_from_cookie() {
$('#tabsize').val(any($.cookie('tabsize'), '4'));
$('#brace-style').val(any($.cookie('brace-style'), 'collapse'));
$('#detect-packers').attr('checked', $.cookie('detect-packers') !== 'off');
$('#preserve-newlines').attr('checked', $.cookie('preserve-newlines') !== 'off');
$('#keep-array-indentation').attr('checked', $.cookie('keep-array-indentation') === 'on');
$('#break-chained-methods').attr('checked', $.cookie('break-chained-methods') === 'on');
$('#indent-scripts').val(any($.cookie('indent-scripts'), 'normal'));
$('#space-before-conditional').attr('checked', $.cookie('space-before-conditional') !== 'off');
$('#wrap-line-length').val(any($.cookie('wrap-line-length'), '0'));
$('#unescape-strings').attr('checked', $.cookie('unescape-strings') === 'on');
function store_settings_to_cookie() {
var opts = { expires: 360 };
$.cookie('tabsize', $('#tabsize').val(), opts);
$.cookie('brace-style', $('#brace-style').val(), opts);
$.cookie('detect-packers', $('#detect-packers').attr('checked') ? 'on' : 'off', opts);
$.cookie('preserve-newlines', $('#preserve-newlines').attr('checked') ? 'on' : 'off', opts);
$.cookie('keep-array-indentation', $('#keep-array-indentation').attr('checked') ? 'on' : 'off', opts);
$.cookie('break-chained-methods', $('#break-chained-methods').attr('checked') ? 'on' : 'off', opts);
$.cookie('space-before-conditional', $('#space-before-conditional').attr('checked') ? 'on' : 'off', opts);
$.cookie('unescape-strings', $('#unescape-strings').attr('checked') ? 'on' : 'off', opts);
$.cookie('wrap-line-length', $('#wrap-line-length').val(), opts);
$.cookie('indent-scripts', $('#indent-scripts').val(), opts);
function unpacker_filter(source) {
var trailing_comments = '',
comment = '',
unpacked = '',
found = false;
// cut trailing comments
do {
found = false;
if (/^\s*\/\*/.test(source)) {
found = true;
comment = source.substr(0, source.indexOf('*/') + 2);
source = source.substr(comment.length).replace(/^\s+/, '');
trailing_comments += comment + "\n";
} else if (/^\s*\/\//.test(source)) {
found = true;
comment = source.match(/^\s*\/\/.*/)[0];
source = source.substr(comment.length).replace(/^\s+/, '');
trailing_comments += comment + "\n";
} while (found);
var unpackers = [P_A_C_K_E_R, Urlencoded, JavascriptObfuscator, MyObfuscate];
for (var i = 0; i < unpackers.length; i++) {
if (unpackers[i].detect(source)) {
unpacked = unpackers[i].unpack(source);
if (unpacked != source) {
source = unpacker_filter(unpacked);
return trailing_comments + source;
function beautify()
if (the.beautify_in_progress) return;
the.beautify_in_progress = true;
var source = the.editor ? the.editor.getValue() : $('#source').val(),
opts = {};
opts.indent_size = $('#tabsize').val();
opts.indent_char = opts.indent_size == 1 ? '\t' : ' ';
opts.preserve_newlines = $('#preserve-newlines').attr('checked');
opts.keep_array_indentation = $('#keep-array-indentation').attr('checked');
opts.break_chained_methods = $('#break-chained-methods').attr('checked');
opts.indent_scripts = $('#indent-scripts').val();
opts.brace_style = $('#brace-style').val();
opts.space_before_conditional = $('#space-before-conditional').attr('checked');
opts.unescape_strings = $('#unescape-strings').attr('checked');
opts.wrap_line_length = $('#wrap-line-length').val();
opts.space_after_anon_function = true;
if (looks_like_html(source)) {
output = style_html(source, opts);
} else {
if ($('#detect-packers').attr('checked')) {
source = unpacker_filter(source);
output = js_beautify(source, opts);
if (the.editor) {
} else {
the.beautify_in_progress = false;
function looks_like_html(source)
// <foo> - looks like html
// <!--\nalert('foo!');\n--> - doesn't look like html
var trimmed = source.replace(/^[ \t\n\r]+/, '');
var comment_mark = '<' + '!-' + '-';
return (trimmed && (trimmed.substring(0, 1) === '<' && trimmed.substring(0, 4) !== comment_mark));
$(function() {
var default_text = "// This is just a sample script. Paste your real code (javascript or HTML) here.\n\nif ('this_is'==/an_example/){of_beautifer();}else{var a=b?(c%d):e[f];}";
if (the.use_codemirror && typeof CodeMirror !== 'undefined') {
the.editor = CodeMirror.fromTextArea($('#source').get(0))
$('.CodeMirror').click(function () {
if (the.editor.getValue() == default_text) {
} else {
$('#source').val(default_text).bind('click focus', function () {
if ($(this).val() == default_text) {
}).bind('blur', function () {
if ( ! $(this).val()) {
$(window).bind('keydown', function (e) {
if (e.ctrlKey && e.keyCode == 13) {
<table id="options">
<select name="tabsize" id="tabsize">
<option value="1">indent with a tab character</option>
<option value="2">indent with 2 spaces</option>
<option value="3">indent with 3 spaces</option>
<option value="4">indent with 4 spaces</option>
<option value="8">indent with 8 spaces</option>
<select name="wrap-line-length" id="wrap-line-length">
<option value="0">Do not wrap lines</option>
<option value="40">Wrap lines near 40 characters</option>
<option value="70">Wrap lines near 70 characters</option>
<option value="80">Wrap lines near 80 characters</option>
<option value="110">Wrap lines near 110 characters</option>
<option value="120">Wrap lines near 120 characters</option>
<option value="160">Wrap lines near 160 characters</option>
<select id="brace-style">
<option value="collapse">Braces with control statement</option>
<option value="expand">Braces on own line</option>
<option value="end-expand">End braces on own line</option>
<!-- option value="expand-strict">Braces always on own line (not recommended)</option -->
<p style="margin:6px 0 0 0">HTML &lt;style&gt;, &lt;script&gt; formatting:</p><select id="indent-scripts">
<option value="keep">Keep indent level of the tag</option>
<option value="normal">Add one indent level</option>
<option value="separate">Separate indentation</option>
<input class="checkbox" type="checkbox" id="preserve-newlines"><label for="preserve-newlines"> Preserve empty lines?</label><br>
<input class="checkbox" type="checkbox" id="detect-packers"><label for="detect-packers"> Detect packers and obfuscators?</label><br>
<input class="checkbox" type="checkbox" id="keep-array-indentation"><label for="keep-array-indentation"> Keep array indentation?</label><br>
<input class="checkbox" type="checkbox" id="break-chained-methods"><label for="break-chained-methods"> Break lines on chained methods?</label><br>
<input class="checkbox" type="checkbox" id="space-before-conditional"><label for="space-before-conditional"> Space before conditional: "if(x)" / "if (x)"</label><br>
<input class="checkbox" type="checkbox" id="unescape-strings"><label for="unescape-strings"> Unescape printable chars encoded as \xNN or \uNNNN?</label>
<br><a href="?without-codemirror" class="turn-off-codemirror">Use a simple textarea for code input?</a>
<div id="about">
<p><a class="self" href="./">Beautify, unpack or deobfuscate JavaScript and HTML, make JSON/JSONP readable, etc.</a></p>
<p>All of the source code is completely free and open, available on the <a href="">github</a> under MIT licence, <br>and we have a command-line version and a python library as well.
<button id="submit"><strong>Beautify JavaScript or HTML</strong> <em>(ctrl-enter)</em></button>
<textarea id="source" rows="30" cols="160"></textarea>
<div class="blurb">
<div style="float:right; width: 210px;">
<a style="display:block; float: left; padding-top: 3px" href="" target="_blank"><img src="" alt="Flattr" /></a>
<form action="" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="TL28UJK2ARCUJ">
<input style="border:0" type="image" src="" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" src="" width="1" height="1">
<p>Browser extensions and other uses:</p>
<ul id="uses">
<li>A <a href="javascript:(function(){s=document.getElementsByTagName('SCRIPT');tx='';sr=[];for(i=0;i<s.length;i++){with(s.item(i)){t=text;if(t){tx+=t;}else{sr.push(src)};}};with({document.write('<textarea id=&quot;t&quot;>'+(sr.join(&quot;\n&quot;))+&quot;\n\n-----\n\n&quot;+tx+'</textarea><script src=&quot;;></script><script>with(document.getElementById(&quot;t&quot;)){value=js_beautify(value);with(style){width=&quot;99%&quot;;height=&quot;99%&quot;;borderStyle=&quot;none&quot;;}};</script>');document.close();}})();"><strong>bookmarklet</strong></a> (drag it to your bookmarks) by Ichiro Hiroshi to see all scripts used on the page,</li>
<li style="margin-top: 8px"><strong>Chrome</strong>: <a href="">jsbeautify-for-chrome</a> by Tom Rix,</li>
<li><strong>Chrome</strong>: <a href="">Pretty Beautiful JavaScript</a> by Will McSweeney,</li>
<li><strong>Chrome</strong>: <a href="">Quick source viewer</a> by Tomi Mickelsson (<a href="">github</a>, <a href="">blog</a>),</li>
<li style="margin-top: 8px"><strong>Firefox</strong>: <a href="">Javascript deminifier</a> by Ben Murphy, to be used together with the firebug (<a href="">github</a>),</li>
<li style="margin-top: 8px"><strong>Safari</strong>: <a href="">Safari extension</a> by Sandro Padin,</li>
<li style="margin-top: 8px"><strong>Opera</strong>: <a href="">Readable JavaScript</a> (<a href="">github</a>) by Dither,</li>
<li><strong>Opera</strong>: <a href="">Source</a> extension by Deathamns,</li>
<li style="margin-top: 8px"><strong>Sublime Text 2:</strong> <a href="">JsFormat</a>, a javascript formatting plugin for this nice editor by Davis Clark,</li>
<li style="margin-top: 8px"><strong>vim:</strong> <a href="">sourcebeautify.vim</a>, a plugin by michalliu (requires node.js, V8, SpiderMonkey or cscript js engine),</li>
<li><strong>vim:</strong> <a href="">vim-jsbeautify</a>, a plugin by Maksim Ryzhikov (node.js or V8 required),</li>
<li style="margin-top: 12px"><a href="">Fiddler</a> proxy: <a href="">JavaScript Formatter addon</a>,
<li><a href="">gEdit tips</a> by Fabio Nagao,</li>
<li><a href="">Akelpad extension</a> by Infocatcher,</li>
<li>Beautifier in <a href="">Emacs</a> write-up by Seth Mason,</li>
<li><a href="">Cloud9</a>, a lovely IDE running in a browser, working in the node/cloud, uses jsbeautifier (<a href="">github</a>),</li>
<li><a href="">Shrinker</a>, a non-free JavaScript packer for Mac. I&nbsp;haven't used it, so I&nbsp;have no idea if it's any good,</li>
<li><a href="">REST Console</a>, a request debugging tool for Chrome, beautifies JSON responses (<a href="">github</a>),</li>
<li><a href="">mitmproxy</a>, a nifty SSL-capable HTTP proxy, provides pretty javascript responses (<a href="">github</a>).</li>
<li><a href="">wakanda</a>, a neat IDE for web and mobile applications has a <a href="">Beautifier extension</a> (<a href="">github</a>).</li>
<li><a href="">Burp Suite</a> now has a <a href="">beautfier extension</a>, thanks to Soroush Dalili,</li>
<li><a href="">Netbeans jsbeautify</a> plugin by Drew Hamlett (<a href="">github</a>).</li>
<li><a href="">brackets-beautify-extension</a> for <a href="">Adobe Brackets</a> by Drew Hamlett (<a href="">github</a>).</li>
<li class="writeme">Doing anything interesting? Write me to and I'll include your link.</li>
<p class="me-me-me">Written by Einar Lielmanis, <a href=""></a>, Python version flourished by <a href="">Stefano Sanfilippo</a>. We use the wonderful <a href="">CodeMirror</a> syntax highlighting editor, written by Marijn Haverbeke.</p>
<p class="contributors">Made with a great help of Jason&nbsp;Diamond, Patrick&nbsp;Hof, Nochum&nbsp;Sossonko, Andreas&nbsp;Schneider, Dave&nbsp;Vasilevsky, <a href="">Vital&nbsp;Batmanov</a>, Ron&nbsp;Baldwin, Gabriel&nbsp;Harrison, <a href="">Chris&nbsp;J.&nbsp;Shull</a>, <a href="">Mathias Bynens</a>, <a href="">Vittorio Gambaletta</a>, <a href="">Liam Newman</a> and others.
<p style="text-align:right">
<a href="#" style="color: #ccc; border-bottom: 1px dashed #ccc; text-decoration: none;" onclick="run_tests(); return false;">Run the tests</a>
<div id="testresults"></div>
var _gaq = [['_setAccount', 'UA-7409939-1'], ['_trackPageview']];
(function(d, t) {
var g = d.createElement(t),
s = d.getElementsByTagName(t)[0];
g.src = '//';
s.parentNode.insertBefore(g, s);
}(document, 'script'));
Jump to Line
Something went wrong with that request. Please try again.