Skip to content

Test your real workload on 1 TB of free traffic, until December 11.Claim 1 TB free

What Is a PAC File?

A PAC file is a JavaScript file that tells a browser which proxy to use for each URL, through a FindProxyForURL function that returns DIRECT or a proxy.

Shafayat HossainPublished 5 min read

Rayobyte is the proxy and scraping network priced for the AI era. We own our residential network and run heavy compute on bare metal, so Residential Proxies cost from $0.0095/GB.Start free trial

AI made it possible to use far more of the web than anyone collected before.Read the full thesis

On this page 7 sections
  1. How does a PAC file work?
  2. What does a PAC file look like?
  3. What can a PAC file return?
  4. Which functions can you use in a PAC file?
  5. How do you set up a PAC file?
  6. How do you test a PAC file?
  7. When should you use a PAC file?

Residential Proxies from $0.0095/GB.

We own our residential network and run heavy compute on bare metal, so collecting more costs less.

Start free trial

Free trial on self-serve products · No credit card

A PAC (proxy auto-config) file is a small JavaScript file that tells a browser or operating system which proxy to use for each web address. It defines one function, FindProxyForURL(url, host), which returns DIRECT for a direct connection or one or more proxies, such as PROXY proxy.example.com:8080, to send that request through.

PAC file at a glance
Full name Proxy auto-config file
Language JavaScript
Required function FindProxyForURL(url, host)
Returns DIRECT, PROXY host:port or SOCKS host:port, or several separated by semicolons
Usual file name proxy.pac
MIME type application/x-ns-proxy-autoconfig
Where you set it The automatic proxy setup or configuration URL in your OS or browser

How does a PAC file work?

A PAC file works by running its FindProxyForURL function every time the browser is about to make a request, then following the proxy instructions the function returns.

  1. You enter the PAC file's URL in your operating system or browser proxy settings.
  2. The browser downloads the file and loads the FindProxyForURL function.
  3. Before each request, the browser calls the function with the full URL and the hostname.
  4. The function returns a string such as PROXY proxy.example.com:8080; DIRECT.
  5. The browser tries the left-most option first and moves to the next one if it can't connect.

Companies use PAC files so one setting covers many rules: intranet sites connect directly, web traffic goes through the office proxy server, and a backup proxy takes over when the main one is down.

What does a PAC file look like?

A PAC file looks like a short JavaScript function with if statements that match hostnames and return proxy instructions. This example sends intranet traffic direct, routes shop sites through a rotating proxy, and sends everything else through an office proxy with a backup:

JavaScript
function FindProxyForURL(url, host) {
  // Short intranet names and the company domain connect directly
  if (isPlainHostName(host) || dnsDomainIs(host, ".corp.example.com")) {
    return "DIRECT";
  }
  // Shop sites go through a rotating proxy, or direct if it's down
  if (shExpMatch(host, "*.shop.example.net")) {
    return "PROXY rotating.proxy.example.com:8000; DIRECT";
  }
  // Everything else uses the office proxy, then a backup
  return "PROXY proxy.example.com:8080; PROXY backup.example.com:3128";
}

We evaluated this file in November 2026 with the pac-resolver library (version 7.0.1) in Node.js 22. These are the results it returned:

Request PAC result
http://intranet/home DIRECT
https://wiki.corp.example.com/page DIRECT
https://www.shop.example.net/item/42 PROXY rotating.proxy.example.com:8000; DIRECT
https://news.example.org/ PROXY proxy.example.com:8080; PROXY backup.example.com:3128

What can a PAC file return?

A PAC file can return DIRECT, a PROXY or SOCKS instruction, or a list of them separated by semicolons. MDN's PAC file reference lists these return values:

Return value Meaning
DIRECT Connect without a proxy
PROXY host:port Use this HTTP proxy
SOCKS host:port Use this SOCKS server
HTTP host:port, HTTPS host:port, SOCKS4 host:port, SOCKS5 host:port More specific forms that recent Firefox versions support

With several values, the browser uses the left-most one until it fails to connect, then moves to the next. MDN notes that Firefox retries an unresponsive proxy after 30 minutes, and that if every proxy is down and there's no DIRECT fallback, Firefox asks whether to connect directly. The return string has no field for a username or password, so a proxy that needs credentials makes the browser ask for them, or relies on IP whitelisting.

Which functions can you use in a PAC file?

You can use a set of built-in helper functions in a PAC file to match hostnames, IP ranges and times. The most common ones:

  • isPlainHostName(host): true when the hostname has no dots, such as intranet.
  • dnsDomainIs(host, domain): true when the host is inside a domain, such as .corp.example.com.
  • shExpMatch(str, pattern): matches a shell-style pattern, where * is any number of characters and ? is one character.
  • isInNet(host, pattern, mask): true when the host's IP address falls in a range. It resolves the hostname through DNS first.
  • dnsResolve(host) and myIpAddress(): return the IP address of a host or of the local machine.
  • weekdayRange, dateRange and timeRange: match the day, date or time, so rules can change outside office hours.

MDN advises using isInNet, isResolvable and dnsResolve with care, because they query a DNS server for each request, while the other functions only compare strings. Put string checks first so DNS runs only when it has to.

How do you set up a PAC file?

You set up a PAC file by hosting it on a web server with the right MIME type, then entering its URL in each device's proxy settings.

  1. Save the file as proxy.pac and host it on a web server your users can reach.
  2. Serve it with the MIME type application/x-ns-proxy-autoconfig.
  3. Point each device at the file's URL:
    • Windows 11: Settings > Network & internet > Proxy, then turn on Use setup script and enter the script address.
    • macOS: System Settings > Network, select your connection, then Details > Proxies > Automatic proxy configuration.
    • Firefox: Settings > Network Settings > Automatic proxy configuration URL.
  4. Test a few addresses in a browser to confirm each one takes the route you expect.

Our guide to setting up and configuring proxies covers manual proxy settings, and how to disable a proxy on Windows 11 shows how to switch a PAC file off again.

How do you test a PAC file?

You test a PAC file by running its FindProxyForURL function against sample addresses and checking each result, before you roll it out. In Node.js, the pac-resolver library runs a PAC file in a sandbox:

JavaScript
import { readFileSync } from "node:fs";
import { createPacResolver } from "pac-resolver";
import { getQuickJS } from "@tootallnate/quickjs-emscripten";

const qjs = await getQuickJS();
const FindProxyForURL = createPacResolver(qjs, readFileSync("proxy.pac", "utf8"));

console.log(await FindProxyForURL("https://www.shop.example.net/item/42"));
// PROXY rotating.proxy.example.com:8000; DIRECT

Keep in mind that browsers strip the path and query from https:// URLs before they call FindProxyForURL, so rules that match on the path of an HTTPS address won't work. MDN notes that Chrome has offered no way to turn this off since version 75.

When should you use a PAC file?

Use a PAC file when different destinations need different proxies, or when you need automatic failover, and use a single proxy setting when all traffic takes the same route. A PAC file only covers browsers and apps that read the system proxy settings. Scrapers and scripts usually set their proxy in code instead, which is simpler to test and version.

On Rayobyte, IP whitelisting is set up in the dashboard under Proxy Access, then IP Authorization, and lets a PAC file's PROXY rule work without login prompts. Scale logins support only a username and password, so route browser traffic from a PAC file through a Premium product.

Rayobyte's rotating proxies and residential proxies start with a free trial, so you can test them in a PAC file before you roll it out.

Share this post

// written by

Shafayat Hossain

Product Marketing Manager

Shafayat Hossain is the Product Marketing Manager at Rayobyte.

// faq

Frequently asked questions

What is the difference between a PAC file and WPAD?

A PAC file holds the proxy rules, while WPAD (Web Proxy Auto-Discovery) is a way for devices to find a PAC file's URL on their own. With WPAD, a device looks up the PAC file's location through DHCP or DNS, usually as a file named wpad.dat, instead of having the URL typed into its settings.

Can a PAC file use a SOCKS5 proxy?

Yes, a PAC file can send traffic to a SOCKS proxy by returning SOCKS host:port. Recent Firefox versions also accept the more specific SOCKS5 host:port and SOCKS4 host:port forms. Support for these keywords varies by browser, so test your PAC file in every browser your team uses before you rely on SOCKS5 rules.

Can a PAC file include a proxy username and password?

No, a PAC file can't include a proxy username and password, because its return value only names a proxy's host and port. When a proxy asks for credentials, the browser shows a login prompt or uses saved credentials. To avoid prompts, use IP whitelisting so the proxy accepts connections from your network's IP address without a login.

Why is my PAC file not working?

A PAC file usually fails for one of four reasons: a JavaScript syntax error, the wrong MIME type on the server, an unreachable URL, or a rule that matches on the path of an HTTPS address, which browsers strip. Open the PAC URL in a browser to confirm it loads, then test the function against sample addresses before you change device settings.

Collect more. Spend less.

The proxy and scraping network priced for the AI era.

// self-serve

Start in minutes

Every self-serve product has a free trial, and no credit card is needed.

Start free trial
// for teams

Talk to sales

Sales offers volume pricing below our published rates, custom plans and a direct line to the people who run the network.

Contact sales

AI made it possible to use far more of the web than anyone collected before. Read the full thesis