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.
- You enter the PAC file's URL in your operating system or browser proxy settings.
- The browser downloads the file and loads the FindProxyForURL function.
- Before each request, the browser calls the function with the full URL and the hostname.
- The function returns a string such as
PROXY proxy.example.com:8080; DIRECT. - 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:
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.
- Save the file as
proxy.pacand host it on a web server your users can reach. - Serve it with the MIME type
application/x-ns-proxy-autoconfig. - 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.
- 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:
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; DIRECTKeep 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.