Reference

PAC function reference

Every built-in PAC helper function โ€” full signatures, parameters, and worked examples.

isPlainHostName(host)
โ†’ boolean

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?"

ParamTypeDescription
hoststringThe hostname portion of the URL (no port).
example
isPlainHostName("www")            // true  โ€” no dots
isPlainHostName("www.google.com") // false โ€” has dots

if (isPlainHostName(host)) {
  return "DIRECT"; // bypass proxy for intranet names
}
dnsDomainIs(host, domain)
โ†’ boolean

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.

ParamTypeDescription
hoststringHostname to test.
domainstringDomain to match โ€” must start with a dot, e.g. ".example.com".
example
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";
}
localHostOrDomainIs(host, hostdom)
โ†’ boolean

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.

example
localHostOrDomainIs("www.mozilla.org", "www.mozilla.org") // true
localHostOrDomainIs("www",             "www.mozilla.org") // true  (short name)
localHostOrDomainIs("www.google.com",  "www.mozilla.org") // false
isResolvable(host)
โ†’ boolean

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.

DNS queries block the browser during PAC evaluation. See the Compute-intensive functions section for strategies to minimise DNS calls.
example
// Go direct if hostname resolves in internal DNS
if (isResolvable(host)) {
  return "DIRECT";
}
return "PROXY proxy.corp.com:8080";
isInNet(host, pattern, mask)
โ†’ boolean

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.

Always use dotted-decimal IP addresses in pattern โ€” never hostnames. Passing a hostname to pattern can fail silently in some implementations.
ParamTypeDescription
hoststringIP address or hostname to test. Prefer passing a pre-resolved IP.
patternstringNetwork address, e.g. "10.0.0.0".
maskstringSubnet mask, e.g. "255.255.0.0".
example โ€” resolve once, test multiple subnets
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";
}
dnsResolve(host)
โ†’ string

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.

example
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";
}
myIpAddress()
โ†’ string

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.

example
// 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";
dnsDomainLevels(host)
โ†’ number

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.

example
dnsDomainLevels("www")             // 0
dnsDomainLevels("mozilla.org")     // 1
dnsDomainLevels("www.mozilla.org") // 2

if (dnsDomainLevels(host) < 2) {
  return "DIRECT"; // treat short names as internal
}
shExpMatch(str, shexp)
โ†’ boolean

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.

example
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";
}
weekdayRange(wd1, wd2[opt], gmt[opt])
โ†’ boolean

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.

example
if ( weekdayRange("MON", "FRI")
  && timeRange(8, 18)) {
  return "PROXY proxy.corp.com:8080"; // business hours
}
return "DIRECT"; // evenings and weekends go direct
dateRange(day1[opt], month1[opt], year1[opt], day2[opt], month2[opt], year2[opt])
โ†’ boolean

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.

example
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
timeRange(hour1, min1[opt], sec1[opt], hour2, min2[opt], sec2[opt])
โ†’ boolean

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.

example
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
alert(message)
โ†’ void

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.

Never ship alert() calls in a production PAC file. Remove all debug calls before deploying.
example
alert("PAC: evaluating host = " + host);
alert(isInNet(dnsResolve(host), "10.0.0.0", "255.0.0.0"));