Skip to main content
No Result Found

What is a PAC file?

A Proxy Auto-Configuration (PAC) file contains a set of rules coded in JavaScript which allows a web browser to determine whether to send web traffic directly to the Internet or be sent via a proxy server.

PAC files can control how a web browser handles HTTP, HTTPS, and FTP traffic.

Simple PAC file
 function FindProxyForURL(url, host)
{
   return 'PROXY localhost:8888';
}

How does it work?

Local Binary

You can pass --pac-file to the Local binary using the following commands:

# Linux/Mac
BrowserStackLocal --key <your access key> --pac-file <file path>

# Windows
BrowserStackLocal.exe --key <your access key> --pac-file <file path>

<file path> should be an absolute/relative file path on the local machine, preferably in the same directory as the Local Binary. In case the PAC file is a URL, please download and store the PAC file and use it instead of a URL.

Local Native App

Steps to use PAC File:

  • Open the Local Console by accessing localhost:45454
  • Enter your unique BrowserStack access key
  • Open Settings
  • Drag-and-Drop your PAC file after selecting the “Select PAC file” radio button

Screenshot showing how to add pac file

Sample PAC files for various use cases:

  1. Route one public URL via proxy and the rest directly
    function FindProxyForURL(url, host) {
      if (dnsDomainIs(host, "google.com"))
     return "PROXY localhost:8888";
      else {
     return "DIRECT";
      }
    }
    
  2. Route two public URLs via different proxies and rest directly
    function FindProxyForURL(url, host) {
      if (dnsDomainIs(host, "google.com")) {
     return "PROXY localhost:8888";
      } else if (dnsDomainIs(host, "wordpress.com"))
     return "PROXY localhost:9999";
      } else {
     return "DIRECT";
      }
    }
    
  3. Route private URLs via proxies and rest DIRECT
    function FindProxyForURL(url, host) {
     if (isPlainHostName(host) ||
         shExpMatch(host, "*.local") ||
         isInNet(dnsResolve(host), "10.0.0.0", "255.0.0.0") ||
         isInNet(dnsResolve(host), "172.16.0.0",  "255.240.0.0") ||
         isInNet(dnsResolve(host), "192.168.0.0",  "255.255.0.0") ||
         isInNet(dnsResolve(host), "127.0.0.0", "255.255.255.0")) {
    return "PROXY 1.2.3.4:8080";
      } else {
     return "DIRECT";
      }
    }
    }
    

Supported JS Functions

PAC Function Name Supported?
alert No
dateRange Yes
dnsDomainIs Yes
dnsDomainLevels Yes
dnsResolve Yes
isInNet Yes
isPlainHostName Yes
isResolvable Yes
localHostOrDomainIs Yes
myIpAddress Yes
shExpMatch Yes
timeRange Yes
weekdayRange Yes

More supported functions(not part of PAC spec)

Browser Function Support Implementation
split String.prototype.split

Features which don’t work with PAC Files

Feature Alternative
URL based rules in FindProxyForURL function Please use host parameter instead.
Debug Utility Use the proxy directly with –proxy-host, –proxy-port

FAQ

Q1. Debug Utility (--debug-utility, --debug-url <>) does not work with PAC File(--pac-file)

A. PAC files do not work with Debug Utility. You need to run the binary with --proxy-host and --proxy-port to test connectivity. To find these proxy details, you can check the PAC file.

An easy method to find the proxy used is running the binary(with pac file) after enabling verbose logs(–verbose 3). The proxy that is used for a given site will be given like this in the logs

[Pac Resolver] Proxy to use for edgedl.me.gvt1.com is localhost:8888

You might have to enable --force-local and --force-proxy to force the traffic to flow through proxy in order to see these logs.

Q2. Getting HTTP error code 407 on the proxies used, when debugging with --proxy-host, --proxy-port

A. A PAC File on its own does not support authentication. If you are getting a 407 when testing with BrowserStackLocal but not with Chrome/Firefox, it may imply presence of some implicit authentication. Please check if you are using Kerberos, NTLM, or any custom authentication mechanism. We don’t support authentication when using PAC files. Contact your own development team for alternatives.

Q3. Getting “Unable to parse the supplied PAC file”

A. Make sure that the PAC file is a valid javascript, and not minified. In case of minified JS, there is chance that comments can get merged with the code and make it impossible to parse for the internal PAC resolver.

References

http://findproxyforurl.com/pac-file-introduction/

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback

Is this page helping you?

Yes
No

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback!

Talk to an Expert
Download Copy Check Circle