Friday, April 11, 2008

Fiddler in Firefox

The only reason that sometimes I use IE is Fiddler which is an excellent HTTP analytic and debugging tool. By searching around, I found that it could be used with Firefox besides IE. The official document is here http://www.fiddlertool.com/Fiddler/help/hookup.asp.

For Firefox 1.x, you need to select Tools -> Options -> General -> Connection Settings, then a pop-up windows is displayed. You select "Automatic proxy configuration URL" and input "C:\Documents and Settings\gerald\My Documents\Fiddler2\Scripts\BrowserPAC.js" in my case. You should modify the path accordingly. That file BrowserPAC.js is created and maintained by Fiddler which contains proxy information. Every time Fiddler is started or shutdown, that file is modified to reflect the state of Fiddler.

When Fiddler is started, the file is changed to:

function FindProxyForURL(url, host){
  return 'PROXY 127.0.0.1:8888';
}

From the content, you can guess that, actually Fiddler works as a proxy server which listens at port 8888. You can make any HTTP application which supports proxy setting redirect traffic to Fiddler.
Of course, you can set "Manual proxy configuration" for Firefox and type proxy address 127.0.0.1:8888. However, every time you want to  or don't want to use Fiddler, you must change the proxy setting. It is not convenient.

When Fiddler is shut down, the file is changed to:

function FindProxyForURL(url, host){
  return 'DIRECT';
}

That looks great, right? But there is a pitfall. Firefox does not detect change of the proxy configuration file. It means when you start or shut down Fiddler, Firefox will not be able to detect that. You must force Firefox to reload the proxy file:
 image