圧縮されたjavascriptをfirebugでデバッグしたい

コードが一行にまとまっているとブレークポイントが打てなくて困る。とりあえずの対処としてHTTPプロキシを噛ませます。コードの整形には http://jsbeautifier.org/ を使用。

#!/usr/bin/env ruby
require 'webrick'
require 'webrick/httpproxy'
require 'zlib'

SCRIPT_PATH = File.expand_path('../jsbeautifier.py', __FILE__)
handler = Proc.new do |req, res|
  if %r{^[^/]+/javascript}.match(res['content-type'])
    if res.header["content-encoding"] == "gzip"
      Zlib::GzipReader.wrap(StringIO.new(res.body)) do |gz|
        res.body = gz.read
      end
      res.header.delete("content-encoding")
    end
    IO.popen("#{SCRIPT_PATH} -i", "r+") do |io|
      io.print res.body
      io.close_write
      res.body = io.read
    end
    res.header.delete('content-length')
  end
end

s = WEBrick::HTTPProxyServer.new(:Port => 8800, :ProxyContentHandler => handler)
[:INT, :TERM].each{|sig| Signal.trap(sig){s.shutdown} }
s.start

Content-Encoding: deflate の解凍法がよくわからなかったので about:config で network.http.accept-encoding を gzip のみにするてきとー対応。

Javascript Deminifier

This addon will deminify javascript before it is downloaded. This is useful when using firebug to debug a javascript application that uses javascript that has been minified.

https://addons.mozilla.org/ja/firefox/addon/javascript-deminifier/

というのをあとからみつけたけど試してません