3

I use Firefox on Windows and need a somewhat exotic proxy configuration, as I am on a network from which i must go through a proxy to reach certain sites. Some sites will not be reachable through the proxy server, and most public web sites will work, albeit performance will be poor.

Therefore, I need the inverse of the usual “connect directly to X, Y and Z, use the proxy for all others”—what I need is “use the proxy for X, Y and Z, connect directly to all others”.

To this end, I have created a .pac file with the desired rules. In Firefox’s proxy config, I have entered the URL to that file as a proxy auto-config URL. The path looks like this: file:///c:/Users/myself/Application%20Data/proxy.pac.

When I try it out, I can browse the Internet but cannot connect to sites which require going through the proxy server.

I have tried dropping the file:/// prefix, which gives the same results.

If I change the prefix to file://, Firefox will add the missing slash. If I replace %20 with a space character, Firefox will escape it again. The Reload button for the URL is available (it is grayed out if I change the URL to point to a nonexistent file). So apparently Firefox can find the file but it does not have the desired effect.

What is wrong here, or what can I try to figure out why this doesn’t work?

user149408
  • 1,010
  • 3
  • 15
  • 31
  • In Internet Explorer 11, the WinINET team has disabled WinINET’s support for file:// based scripts to promote interoperability across network stacks. Corporations are advised to instead host their proxy configuration scripts on a HTTP or HTTPS server https://superuser.com/a/1569042/392629 – iMath Jul 06 '21 at 07:56

4 Answers4

4

Got it.

File URLs do not seem to be a problem as of Firefox 57.0.2.

Upon examining my PAC file, I spotted a syntax error (missing closing parenthesis in an expression). After I fixed that and reloaded the PAC file (with the file:/// version of the URL), it seemed to work. I can now access the site which requires the proxy.

What I haven’t figured out yet is whether Firefox logs an error message somewhere—I spotted the syntax error by coincidence.

user149408
  • 1,010
  • 3
  • 15
  • 31
  • 2
    There are some tools out there (apologies, I cannot search) both command line based and web-based which can validate a PAC file for you. – Richard Dec 19 '17 at 14:17
  • @Richard, I use pactester from https://github.com/pacparser/pacparser – selurvedu Jun 03 '19 at 13:03
1

Assuming that your PAC is correctly written then the reason it's not working with the specific sites in the PAC is because Firefox is not parsing it.

[update] The original answer incorrectly asserted that paths for PAC files did not work. Whilst this might have been true for older versions of Firefox, this is now incorrect.

One possible solution is to run an extremely small web-server on your computer and host the pac file using that. This thread over at Stack Overflow seems to recommend Mongoose.

If you do that then you can set the URL in Firefox to http://127.0.0.1/proxy.pac and it should load just fine.

Richard
  • 5,831
  • 9
  • 44
  • 73
0

In the Windows platform, proxy file in the local drive should be input as:

"file:///c|/Users/myself/Application%20Data/proxy.pac"

replace ":" with pipe '|'

DarkDiamond
  • 1,875
  • 11
  • 12
  • 19
CKYFIFHA
  • 1
  • 1
0

Since I spent a few hours with a similar issue, here is my piece of advice.

A local proxy.pac file can be loaded in Firefox under Windows using the file:///c:/Users/myself/Application%20Data/proxy.pac URL.

Some hints:

  • check if the URL works in the browser
  • debug proxy.pac using alert statements
  • don't forget to reload proxy.pac every time you change it

Sample proxy.pac with debugging statements

// setup tunneled connection to proxy_host
// ssh -D 9981 user@proxy_host

// hosts *.localdomain are only known to (and reachable from) proxy_host
function FindProxyForURL(url, host) {
if (shExpMatch(host,"*.localdomain")) {
    alert("applying localdomain rule");
    return "SOCKS5 localhost:9981;";
 }  
 
 // Everything else
 alert("DIRECT connection");
 return "DIRECT";
}

The alert() statements in proxy.pac are there for debugging purposes and their output can be viewed in the Browser Console (that's not the Web developer console! -- see also Debugging autoproxy (PAC) javascript with alert()?).

user2314737
  • 101
  • 2