watch this  

the official mrchucho blog

Firefox autoproxy Support

Posted 2004 Dec 16

One of my favorite things about Firefox is support for autoproxies via a javascript file. I don’t know how well-known this feature is (and when I see extensions like SwitchProxy, I worry that it is not). Basically, you can use javascript to examine a URL and decide whether or not to proxy requests to it and, if so, how and where. Below is an example that I use. Note that I use an ssh tunnel (listening on port 8080) to port-forward to my machine at home. My machine at home, in turn, runs TinyProxy.

<pre><code>
function FindProxyForURL(url, host)
{
    if  (dnsDomainIs(host,"mail.yahoo.com") ||
        shExpMatch(url,"*mail.yahoo.com*") ||
        dnsDomainIs(host,"gmail.google.com")) {

        return "PROXY localhost:8080; DIRECT";
    }
     else {
        return "DIRECT";
    }
}
</code>

The code (API here) basically does comparisons on the URL and host and, if there’s a match, sends it to the proxy (or tries to connect directly on failure), otherwise it makes a direct connection. To use this in Firefox, put the code in a file called “autoproxy.js”, then go to “Connection Settings…” under the “General” preference and put your entry in the “Automatic Proxy configuration URL”. The format is like so:

file://&lt;directory&gt;/autoproxy.js

This works well in conjuction with this hint. For my local ssh tunnel, I use the autossh to keep the link alive, like so:

autossh -M 20000 -NnqxT -L 8080:127.0.0.1:8080 home

Responses to "Firefox autoproxy Support"

No responses yet.

Comments are now closed.
atom rss