As of October 7, 2026, Shifter has the largest pool of live US IPs, more than Oxylabs and Bright Data, at a fraction of the cost.Shifter now has the largest pool of live US IPs

See benchmarks

Proxy PAC Files Explained, With Ready-to-Use Examples

What a proxy PAC file is, how FindProxyForURL works, four ready-to-use examples, where to set the PAC URL on each system, and the mistakes that leak traffic.

Engineering · Updated November 14, 2026 · 8 min read
FindProxyForURL(url, host)example-shop.comPROXY p.shifter.io:443intranetDIRECTproxy down + "; DIRECT"your own IP
One function decides site by site. The amber fallback loads the page from your own IP.
Knowledge
On this page
  1. How a PAC file works
  2. The helper functions you will use
  3. Four ready-to-use examples
  4. Where to set the PAC file
  5. Sign-in, and why the location is set once
  6. Mistakes that send traffic around the proxy
  7. Check that it works
  8. The bottom line

A PAC file tells a browser which proxy to use for which site. Instead of sending everything through one proxy, or nothing, you write a short rule: these shops go through a residential proxy in Germany, the company intranet goes direct, everything else follows a default. The browser reads the rule before every request.

PAC stands for proxy auto-config. The format dates back to Netscape in the 1990s and is still supported by every major browser and operating system. This guide explains how the file works, gives four examples you can copy, shows where to set it on each system and lists the mistakes that quietly send traffic outside the proxy.

How a PAC file works

A PAC file is plain JavaScript with one required function:

function FindProxyForURL(url, host) {
  return "PROXY p.shifter.io:443";
}

The browser calls FindProxyForURL for each request, with the full URL and the host name. The function returns a string that says where the request goes:

Return valueMeaning
DIRECTConnect without a proxy
PROXY host:portUse an HTTP proxy
HTTPS host:portUse an HTTP proxy over a TLS connection to the proxy
SOCKS5 host:portUse a SOCKS5 proxy

You can chain several answers with semicolons, such as PROXY p.shifter.io:443; DIRECT. The browser tries them in order and moves to the next one if a proxy cannot be reached. That fallback is useful, and it is also the most common way traffic escapes the proxy, as shown below.

For Shifter, use PROXY. Browsers do not support signing in to a SOCKS5 proxy from a PAC file, and the gateway accepts HTTP proxy connections on the same port.

The helper functions you will use

The PAC environment adds a few functions to plain JavaScript. These four cover most rules:

  • isPlainHostName(host): true for names without a dot, such as intranet.
  • dnsDomainIs(host, ".example.com"): true when the host ends with that domain.
  • shExpMatch(host, "*.example.*"): matches shell-style wildcards.
  • isInNet(ip, "10.0.0.0", "255.0.0.0"): true when an IP is inside a network range.

There is also dnsResolve(host), which looks up the IP of a host. Use it sparingly, for reasons covered under mistakes.

Four ready-to-use examples

Replace the domains with your own. Each example works as a complete file.

1. Everything through the proxy, local addresses direct

function FindProxyForURL(url, host) {
  if (isPlainHostName(host) ||
      host === "localhost" ||
      shExpMatch(host, "*.local") ||
      shExpMatch(host, "127.*") ||
      shExpMatch(host, "10.*") ||
      shExpMatch(host, "192.168.*")) {
    return "DIRECT";
  }
  return "PROXY p.shifter.io:443";
}

This keeps your router, printers and local development servers reachable while every website goes through the proxy.

2. Only a list of sites through the proxy

var VIA_PROXY = [".example-shop.com", ".example-news.de"];

function FindProxyForURL(url, host) {
  host = host.toLowerCase();
  for (var i = 0; i < VIA_PROXY.length; i++) {
    if (dnsDomainIs(host, VIA_PROXY[i]) || "." + host === VIA_PROXY[i]) {
      return "PROXY p.shifter.io:443";
    }
  }
  return "DIRECT";
}

This is the most common reason to write a PAC file. Your normal browsing stays on your own connection, and only the sites you are checking leave through the proxy, which also keeps per-GB traffic low. QA teams use it to see a storefront or an app’s web view from another market while the rest of their tools work as usual; our page on localization QA with proxies covers that workflow.

3. Choose between falling back and failing closed

function FindProxyForURL(url, host) {
  if (dnsDomainIs(host, ".example-shop.com")) {
    // Fail closed: if the proxy is down, the page does not load.
    return "PROXY p.shifter.io:443";
  }
  if (dnsDomainIs(host, ".example-news.de")) {
    // Fall back: if the proxy is down, the page loads from your own IP.
    return "PROXY p.shifter.io:443; DIRECT";
  }
  return "DIRECT";
}

Examples 1, 2 and 4 all fail closed: there is no ; DIRECT after the proxy. If the proxy is unreachable, those pages show an error instead of quietly loading from your real IP. When the point of the proxy is to see a site from somewhere else, an error is better than a wrong answer that looks right. Add the fallback only for sites where any answer is better than none.

4. Everything through the proxy except a few sites

var DIRECT_SITES = [".zoom.us", ".slack.com", ".yourcompany.com"];

function FindProxyForURL(url, host) {
  host = host.toLowerCase();
  if (isPlainHostName(host)) return "DIRECT";
  for (var i = 0; i < DIRECT_SITES.length; i++) {
    if (dnsDomainIs(host, DIRECT_SITES[i])) return "DIRECT";
  }
  return "PROXY p.shifter.io:443";
}

Calls, chat and internal tools stay on your own connection, where they are fastest, and the rest of the browser uses the proxy.

Where to set the PAC file

A PAC file is set as a URL, not pasted as text. Serve it from a web server you control, with the type application/x-ns-proxy-autoconfig. Windows does not accept a local file path for the script, so a web URL is the safe choice everywhere.

  • Windows 11: Settings > Network & internet > Proxy. Under Automatic proxy setup, turn on Use setup script and enter the URL.
  • macOS: System Settings > Network > your connection > Details > Proxies. Turn on Automatic proxy configuration and enter the URL.
  • Firefox: Settings > Network Settings > Automatic proxy configuration URL.
  • Chrome and Edge: they follow the system setting above.
  • iPhone: Settings > Wi-Fi > the info button > Configure Proxy > Automatic, then the URL.
  • Android: the Wi-Fi network’s Advanced options > Proxy > Proxy Auto-Config, then the URL.

Our guide to setting up a proxy on Windows and macOS shows the manual version of the same screens, if you want one proxy for everything instead.

Sign-in, and why the location is set once

A PAC file has no place for a username or password. When a request reaches the proxy, the proxy asks for credentials and the browser shows a sign-in prompt. Type your full proxy username and your password. If the prompt keeps returning, the credentials are rejected: copy both again from the dashboard and check the spelling of the targeting part.

With Shifter, the location and session live in the username, for example customer-USERNAME-country-de-sid-qa1-ttl-1800 for a German IP that holds for 30 minutes. So a PAC file decides which sites use the proxy, and the username you sign in with decides where they appear from. One browser session means one location. If you need different countries for different sites at the same time, use separate browser profiles, or the Shifter browser extension, which switches location with a click.

Mistakes that send traffic around the proxy

  • A fallback you did not mean. PROXY ...; DIRECT loads the page from your real IP whenever the proxy fails. Use it only where that is acceptable.
  • A broken or unreachable file. If the PAC URL does not load, or the script throws an error, most browsers connect directly. Test after every edit and keep the file small.
  • Rules on the path of HTTPS URLs. Browsers strip the path and query from HTTPS URLs before calling the function, so url holds only something like https://example.com/. Match on host.
  • DNS lookups inside the rules. dnsResolve and isInNet on a host name look the name up on your own network first. That slows every request, and it sends the names of the sites you visit to your local DNS resolver even when the page itself goes through the proxy. Our guide to preventing DNS leaks with residential proxies covers why that matters. Prefer dnsDomainIs and shExpMatch, which work on the name alone.
  • A cached old version. Browsers cache the PAC file. After an edit, restart the browser or re-apply the settings (in Chrome, chrome://net-internals/#proxy).
  • Automatic discovery you never asked for. “Automatically detect settings” (WPAD) lets the network you join hand your device a PAC file. On networks you do not trust, switch it off.

Check that it works

Add a test domain to your rules, then open ip-info.com once with the rule pointing it through the proxy and once with it going direct. The first visit should show the proxy’s IP and the location in your username; the second, your own. Then open a site outside your list and confirm it still loads normally.

The bottom line

A PAC file is a few lines of JavaScript that decide, site by site, whether a request goes through a proxy. Keep the rules on host names, avoid DNS lookups in them, choose deliberately between falling back and failing closed, and serve the file from a URL. The proxy username still sets the location, so plan one location per browser profile.

Frequently asked questions

What is a PAC file?

A PAC (proxy auto-config) file is a small JavaScript file with one function, FindProxyForURL(url, host). The browser or operating system calls it for every request and uses the answer to decide whether that request goes through a proxy or connects directly.

Can a PAC file contain the proxy username and password?

No. A PAC file only names the proxy host and port. When the proxy asks for credentials, the browser shows a sign-in prompt, or uses credentials the system has stored.

Why does my PAC file not match the path of an HTTPS URL?

Modern browsers pass only the scheme and host of HTTPS URLs to the PAC file and strip the path and query, so they do not leak the full address to the script. Write your rules on the host name.

What happens if the PAC file cannot be loaded?

Most browsers then connect directly, without a proxy. If going direct must never happen, test the file after every change and watch for errors in the browser's network tools.

Ready to get started?

Try Shifter's residential proxies, 205M+ IPs, 195+ countries, from $0.10/GB.

Get Started