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"));