dnsResolve()
Resolves a host name to an IP address string, or null when the name does not resolve (false in Windows). The script waits for the answer; repeats for the same name come from a cache.
dnsResolve(host) → string or null (false in Windows)Only the first call for a name sends a DNS query. Later calls for the same name, in the same run or in later requests, are answered from a cache until the stored answer expires (see DNS in PAC files). Calling it once and keeping the result in a local variable is still right: Windows keeps nothing between the calls of one run, so with a DNS server that does not answer every call waits again, and pactester asks the DNS server for every call.
Comparing its result with a literal (dnsResolve(host) == "10.1.2.3") breaks as soon as the
record changes or resolves differently inside and outside the network. Use isInNet on a range
instead. Test a failed lookup with if (!ip), not with ip === null, because Windows returns
false.
The engines also differ in what they return for text that already looks like an address, in whether an IPv6 address can come back, and in how many lookups one evaluation may make.
Example
var ip = dnsResolve(host);
if (ip && isInNet(ip, "10.0.0.0", "255.0.0.0")) {
return "DIRECT";
}
dnsResolve answers differently in pactester, Chrome, Firefox and Windows
The engines differ in whether an IPv6 address can come back, in how they treat text that already looks like an address, in upper-case names, and in how many different names one run of the script may resolve: Chrome and Edge stop after a limit, pactester, Firefox and Windows do not. A file that resolves many names can therefore work in pactester and fail in Chrome. Resolve the host at most once and keep the result in a variable. Paste your file into the PAC file tester and switch between the Chromium, Firefox and pacparser profiles to see which answer each engine gives.Check how your own file behaves with the PAC file tester: switch the engine profile between Chromium, Firefox, pacparser and Windows and compare the trace. All engine differences are collected in pactester vs Chrome and Firefox.
Engine notes
| Engine | Behaviour | Source |
|---|---|---|
| chromium | IPv4 only; limits the number of different names per evaluation; upper-case names do not resolve. | lab, verified 2026-10-11 |
| chromium | Keeps the answers of one request in a table, failures included, so a repeat costs no lookup. The limit is 20 different names; after that every new lookup returns null at once and the script carries on. Each new name stops the script and runs it again once the answer is in. The browser's DNS cache keeps a successful answer at least 60 s. | code, verified 2026-10-14 |
| chromium | With the browser's own DNS client, an answer with a TTL of 0 or 10 s was kept 60 s and one with a TTL of 90 s was kept 90 s. When the DNS server did not answer, every request waited 12 s and asked again; 10 calls in one request cost one wait. With plain DNS the own client asked twice (at 0 and 1 s), gave up after 3 s and handed the name to Windows: 15 s per request when the DNS server stayed silent, and the DNS server's own failure time (3.6-4.5 s in the lab) when it answered with a failure. After many slow answers the own client waited up to 5 s before asking again and gave up only after 10 s, so a silent name then cost 22 s per request. | lab, verified 2026-10-16 |
| pacparser | IPv4 only (getaddrinfo with AF_INET), real system DNS. | code, verified 2026-10-04 |
| pacparser | No cache: every call is a new lookup. On a system without a caching DNS service, 150 calls for one name sent 150 queries. | lab, verified 2026-10-14 |
| firefox | May return IPv6 addresses as well. | lab, verified 2026-10-11 |
| firefox | No table in the PAC engine; every call asks the browser's DNS cache. It keeps an answer for as long as the DNS record allows on Windows and for 60 s on Linux and macOS, then up to 600 s more while it refreshes, and a failure for 60 s. | code, verified 2026-10-14 |
| winhttp | Returns false, not null, when a name does not resolve. Text that looks like an address comes back unchanged without a lookup, for example "010.001.002.003", "10.1.2", "[::1]" and "2001:db8::1". A name with IPv4 and IPv6 addresses gave the IPv4 address. Upper-case names resolve; a leading space makes the lookup fail. dnsResolve("") returned the machine's own address. 40 lookups in one run all succeeded. | lab, verified 2026-10-11 |
| winhttp | Keeps no table of names during one run. Successful answers come from the Windows DNS cache for as long as the DNS record allows, so 50 calls for one name sent one query. When the DNS server does not answer, every call waits about 12 s again: 10 calls in one run took 120 s. | lab, verified 2026-10-14 |
Availability
| Function | chromium | chromium | firefox | pacparser | pacparser | winhttp | wininet | reference |
|---|---|---|---|---|---|---|---|---|
dnsResolve | yes | yes | yes | yes | yes | yes | yes | yes |
Related rules
- dnsResolve result compared with a literal address PAC-X010
- DNS function on the path of every request PAC-P001
- dnsResolve called repeatedly for the same host PAC-P004
Frequently asked questions
Is there a limit on DNS lookups in a PAC file?
In Chrome and Edge, yes. One evaluation of FindProxyForURL can resolve 20 different names; after that every new lookup returns null without asking the DNS server. Repeats of a name already resolved do not count again. pactester, Firefox and Windows have no such limit, so a pactester test does not show the problem. Resolve few different names and keep each result in a variable.
Does calling dnsResolve twice for the same name cost two DNS lookups?
Not in Chrome, Edge, Firefox or Windows when the DNS server answers. The second call is answered from a cache. pactester has no cache and asks again. When the DNS server does not answer, Windows waits again on every call, about 12 seconds each, so resolve once into a variable.
Can dnsResolve return an IPv6 address?
In Firefox it can. In Windows (WinHTTP) a name with both IPv4 and IPv6 addresses gave the IPv4 address in the lab, and an IPv6 address written as text came back unchanged. In Chrome, Edge and pactester it returns IPv4 addresses only. Code that uses the result should allow for a failed lookup and for an IPv6 address.
What does dnsResolve return on Windows when a name does not resolve?
It returns false, not null. A test such as dnsResolve(host) == null is therefore never true on Windows. Test the result with if (ip) instead, which works in every engine.