PAC function reference
Every built-in PAC helper function โ full signatures, parameters, and worked examples.
Returns true if host contains no dots โ meaning it is an unqualified short hostname like localhost or intranet rather than a fully-qualified domain name. The classic, zero-cost test for "is this an internal host?"
| Param | Type | Description |
|---|---|---|
| host | string | The hostname portion of the URL (no port). |
isPlainHostName("www") // true โ no dots isPlainHostName("www.google.com") // false โ has dots if (isPlainHostName(host)) { return "DIRECT"; // bypass proxy for intranet names }
Returns true if host belongs to the given domain via suffix match. The domain must start with a leading dot. Note: this does not match the bare apex domain โ "mozilla.org" does not match ".mozilla.org". No DNS lookup is performed.
| Param | Type | Description |
|---|---|---|
| host | string | Hostname to test. |
| domain | string | Domain to match โ must start with a dot, e.g. ".example.com". |
dnsDomainIs("www.mozilla.org", ".mozilla.org") // true dnsDomainIs("mozilla.org", ".mozilla.org") // false โ no subdomain! dnsDomainIs("www.google.com", ".mozilla.org") // false if ( dnsDomainIs(host, ".corp.internal") || dnsDomainIs(host, ".corp.com")) { return "DIRECT"; }
Returns true if host matches hostdom exactly, or if host is the short (unqualified) version of hostdom. This lets you match both www and www.example.com in a single call.
localHostOrDomainIs("www.mozilla.org", "www.mozilla.org") // true localHostOrDomainIs("www", "www.mozilla.org") // true (short name) localHostOrDomainIs("www.google.com", "www.mozilla.org") // false
Performs a live DNS lookup for host. Returns true if the hostname resolves, false if not. Triggers a real DNS query โ adds latency to every PAC evaluation. Prefer dnsDomainIs() or shExpMatch() where possible.
// Go direct if hostname resolves in internal DNS if (isResolvable(host)) { return "DIRECT"; } return "PROXY proxy.corp.com:8080";
Returns true if the IP address of host falls within the subnet defined by pattern and mask. If host is a hostname (not already an IP), a DNS lookup is triggered internally. Always pass a pre-resolved IP via dnsResolve(host) to avoid double lookups and silent failures.
pattern โ never hostnames. Passing a hostname to pattern can fail silently in some implementations.| Param | Type | Description |
|---|---|---|
| host | string | IP address or hostname to test. Prefer passing a pre-resolved IP. |
| pattern | string | Network address, e.g. "10.0.0.0". |
| mask | string | Subnet mask, e.g. "255.255.0.0". |
var ip = dnsResolve(host); // resolve once if (ip && ( isInNet(ip, "10.0.0.0", "255.0.0.0") || isInNet(ip, "172.16.0.0", "255.240.0.0") || isInNet(ip, "192.168.0.0", "255.255.0.0"))) { return "DIRECT"; }
Resolves a hostname to its IP address. Returns a dotted-decimal string (e.g. "93.184.216.34"), or an empty string "" on failure. Always store the result in a variable and reuse it โ calling dnsResolve() multiple times for the same host triggers multiple DNS queries.
var ip = dnsResolve(host); // one DNS call โ store and reuse if (!ip) { return "DIRECT"; } // guard against resolution failure if (isInNet(ip, "10.0.0.0", "255.0.0.0")) { return "DIRECT"; }
Returns the IP address of the client machine as a dotted-decimal string. Useful for routing decisions based on the client's subnet โ for example, picking a regionally appropriate proxy. In some environments this returns "127.0.0.1" โ see Troubleshooting.
// Select a regional proxy based on the client's subnet var myip = myIpAddress(); if (isInNet(myip, "10.1.0.0", "255.255.0.0")) { return "PROXY eu-proxy.corp.com:8080"; } if (isInNet(myip, "10.2.0.0", "255.255.0.0")) { return "PROXY us-proxy.corp.com:8080"; } return "DIRECT";
Returns the number of dots in the hostname. "intranet" โ 0, "mozilla.org" โ 1, "www.mozilla.org" โ 2. A DNS-free alternative to isPlainHostName() that also works for multi-level internal domains.
dnsDomainLevels("www") // 0 dnsDomainLevels("mozilla.org") // 1 dnsDomainLevels("www.mozilla.org") // 2 if (dnsDomainLevels(host) < 2) { return "DIRECT"; // treat short names as internal }
Matches str against a shell glob pattern. * matches any sequence of characters, ? matches any single character. This is not a regular expression. Can be applied to both host and the full url โ no DNS lookup is triggered.
shExpMatch("www.google.com", "*.google.*") // true shExpMatch("www.bing.com", "*.google.*") // false shExpMatch("ftp://example.com/pub", "ftp:*") // true // Match on full URL (including path โ works for HTTP, not HTTPS) if (shExpMatch(url, "https://api.example.com/*")) { return "PROXY fast-proxy.corp.com:8080"; }
Returns true if the current day falls within the specified range. Valid values: "SUN" "MON" "TUE" "WED" "THU" "FRI" "SAT". Ranges wrap around โ weekdayRange("FRI","MON") matches Fri, Sat, Sun, Mon. Append "GMT" to use UTC.
if ( weekdayRange("MON", "FRI") && timeRange(8, 18)) { return "PROXY proxy.corp.com:8080"; // business hours } return "DIRECT"; // evenings and weekends go direct
Returns true if the current date falls within the given range. Month names: "JAN"โ"DEC". Day numbers: 1โ31. Years: four-digit. Arguments can be mixed and matched โ you can specify just months, just years, or full date ranges. Append "GMT" for UTC.
dateRange("JAN", "MAR") // true in Q1 dateRange(1, "JAN", 2025, 31, "DEC", 2025) // true all of 2025 dateRange(1, 15) // true on days 1โ15 of any month
Returns true if the current time falls within the given range. Hours use 24-hour format (0โ23). Specify just hours, hours+minutes, or full hours+minutes+seconds. Append "GMT" for UTC evaluation.
timeRange(9, 17) // true between 09:00 and 17:00 timeRange(9, 30, 17, 0) // true between 09:30 and 17:00 timeRange(12) // true during 12:00:00โ12:59:59
Outputs a debug message during PAC evaluation. In Firefox it appears in the browser console. Not available in all environments โ in some browsers, calling alert() silently breaks PAC evaluation entirely.
alert() calls in a production PAC file. Remove all debug calls before deploying.alert("PAC: evaluating host = " + host); alert(isInNet(dnsResolve(host), "10.0.0.0", "255.0.0.0"));
IPv6 extensions โ the Ex functions
Microsoft's IPv6-aware variants of the core helpers.
The original Netscape helpers are IPv4-only. Microsoft extended the PAC format with
IPv6-capable Ex variants, implemented by the WinHTTP / WinINET
stack (Internet Explorer 10+, legacy Edge, and Windows services that consume PAC files).
To activate them, the PAC file must define
FindProxyForURLEx(url, host) instead of
FindProxyForURL โ the engine then evaluates that function with
the extended helpers available.
Ex functions or FindProxyForURLEx โ they evaluate plain
FindProxyForURL only. Use the Ex family only for PAC files
targeting Windows/WinHTTP environments, and always keep a standard
FindProxyForURL for everything else.
IPv6-aware version of dnsResolve(). Resolves both A (IPv4) and AAAA (IPv6) records and returns all addresses as a semicolon-separated list, e.g. "2001:db8::1;192.0.2.10". Returns an empty string on failure. Like its IPv4 counterpart, every call triggers a blocking DNS lookup โ resolve once and reuse the result.
var list = dnsResolveEx(host); // "2001:db8::1;192.0.2.10" if (!list) { return "DIRECT"; } // guard resolution failure if (isInNetEx(list, "fd00::/8")) { return "DIRECT"; // internal IPv6 ULA range }
IPv6-aware version of isResolvable(). Returns true if host resolves to any IPv4 or IPv6 address. Performs a live, blocking DNS lookup on every call โ prefer string checks like dnsDomainIs() where possible.
if (isResolvableEx(host)) { return "DIRECT"; // resolvable in internal dual-stack DNS } return "PROXY proxy.corp.com:8080";
IPv6-aware version of isInNet(). Instead of a dotted subnet mask it takes CIDR prefix notation, and it accepts both IPv4 and IPv6 addresses. ip may be a single address or a semicolon-separated list (as returned by dnsResolveEx); the match succeeds if any address falls inside the prefix.
| Param | Type | Description |
|---|---|---|
| ip | string | Address (or semicolon-separated list) to test. |
| ipPrefix | string | CIDR range, e.g. "10.0.0.0/8" or "3ffe:8311:ffff::/48". |
isInNetEx("10.1.2.3", "10.0.0.0/8") // true isInNetEx("2001:db8::1", "2001:db8::/32") // true isInNetEx("192.0.2.1", "10.0.0.0/8") // false
IPv6-aware version of myIpAddress(). Returns all of the client machine's addresses โ IPv6 and IPv4 โ as a semicolon-separated list, e.g. "fe80::1;10.1.2.3". Pair with isInNetEx(), which accepts the list directly.
var myAddrs = myIpAddressEx(); // "fe80::1;10.1.2.3" if (isInNetEx(myAddrs, "10.1.0.0/16")) { return "PROXY eu-proxy.corp.com:8080"; // EU office subnet } return "PROXY us-proxy.corp.com:8080";
Sorts a semicolon-separated list of IP addresses into preferred connection order (IPv6 addresses first, following the OS destination-address selection rules). Useful for picking the "best" address out of a dnsResolveEx() result. Returns an empty string if the list is invalid.
sortIpAddressList("10.1.2.3;2001:db8::1") // โ "2001:db8::1;10.1.2.3" โ IPv6 preferred var best = sortIpAddressList(dnsResolveEx(host)).split(";")[0];
Returns the version of the WPAD engine evaluating the PAC file โ "1.0" in every released Windows implementation. Intended to let a PAC file branch on engine capabilities if the format is ever revised.
if (getClientVersion() === "1.0") { // current WinHTTP WPAD engine }