I have the following .pac file:

function FindProxyForURL(url, host)
    return "PROXY proxy.example.com:8080; DIRECT;";

I'm using FoxyProxy with Firefox 13 and I was expecting it to fall back to DIRECT if the given proxy isn't available. Instead, I get the message Firefox is configured to use a proxy server that can't be found. Are my expectations misplaced? Is there any way to get it to behave as I would like?


You should tell it explicitly to go DIRECT.

The best way to control this is to detect what network you are on. Here is an example proxy.pac that is little more complex:

function FindProxyForURL(url, host) {
    // Variables
    var proxy_LAN1 = "PROXY; DIRECT;"; 
    var LAN1_addr_ip4 = ""; 
    var LAN1_addr_ip6 = "fe80::b892:6a74:9635:*"; // Needed for FF/TB (Mozilla)
    var proxy_no = "DIRECT";
    var alert_done = 99;

    //alert("My Addr: " + myIpAddress() + "\nURL: " + url + "\nHost: " + host);

    // If address is local, always go direct
    if( isPlainHostName(host) ) {
        //alert("Local address so no proxy");
        return proxy_no;

    // Proxy if PC is on LAN1
    if (isInNet(myIpAddress(), LAN1_addr_ip4, "") || shExpMatch(myIpAddress(), LAN1_addr_ip6) ) {
        //alert("LAN1 address & proxy");
        return proxy_LAN1;

    // Default to a direct connection
    // alert("Default proxy (none)");
    return proxy_no;

    Use alert("xxx") to find out what is happening. IE displays a pop-up, FF/TB use the error console
    Can have multiple proxies to try. Separate each with ;
    For local pac files, IE requires "file://c:\proxy.pac", FF/TB require file:///c:\proxy.pac" (extra /)
    FF/TB - myIpAddress() returns an IPv6 rather than IPv4 address for Vista and Win7 so isInNet() doesn't work!
    shExpMatch(lookup, match)
    isInNet(address, lookup.address, netmask)
    dnsDomainIs(host, ".foobar")
    if (shExpMatch(url, "*")) { return proxy_no; }
    if (isInNet(myIpAddress(), "", ""))

As you can see, this tries to detect if we are on a specific network and only sets the proxy if that is true.

  • I think the question was more related to availability, i.e. if the proxy server goes down. It is not possible to achieve this by differentiating the subnet. Oct 28 '12 at 5:42
  • Ah, I don't think this is how proxy.pac files work. Generally you should always have the same proxy address for the same network. You should make sure your proxies are resilient so that, if one fails, there are others to take up the load otherwise you are putting the whole network at risk. That is why the proxy.pac file focuses on understanding what network you are on. The other problem is that IE at least only checks the proxy for a specific URL once per session. Nov 3 '12 at 21:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.