FindProxyForURL(url, host)
FindProxyForURL(url, host) is the one function every proxy.pac or wpad.dat file must define. The browser calls it for each request and follows the string it returns, either DIRECT or a list of proxies to try in order.
Signature
function FindProxyForURL(url, host) {
// ...
return "PROXY proxy.corp.example:8080";
}
url: the URL of the request, for examplehttp://www.example.com/path?q=1. What the script really sees depends on the engine (see below).host: the host name taken from that URL, without the port, for examplewww.example.com.
The names url and host are a convention. The engine passes the arguments by position
(PAC-B002).
Return values
| Return value | Meaning |
|---|---|
DIRECT | connect without a proxy |
PROXY host:port | use an HTTP proxy |
SOCKS host:port | use a SOCKS proxy; the version differs between engines (PAC-K005) |
HTTPS host:port | TLS to the proxy itself. Chromium and Firefox use it. Windows passes the entry on to the program, but some Windows programs cannot use it (lab, Windows 11, 2026-10-11). Add a PROXY fallback (PAC-K006) |
Separate several entries with semicolons. The browser tries them in order and moves to the next one
when a proxy cannot be reached: "PROXY p1.corp.example:8080; PROXY p2.corp.example:8080". Ending the
list with DIRECT means a dead proxy silently becomes direct internet access. Make that a decision,
not a default. Always write a port (PAC-X013), and keep the port between
1 and 65535 (PAC-E012).
Whole example files are on other pages
A short example of a whole file is on the page what a PAC file is,
and a complete production file is the annotated reference proxy.pac. The helper
functions that FindProxyForURL can call (isPlainHostName, dnsDomainIs, shExpMatch, isInNet and
others) are listed in the PAC function reference.
How engines differ
Browsers cut the URL before the function sees it
The browser does not always pass the whole address as url. We measured this in our lab with a
PAC file that sends the url it receives back in its answer, for addresses with a path, a query,
a #fragment, and a user name and password written before the host (user:pw@host).
| Part of the address | Chrome, Edge (Chromium 145, Edge 155) | Firefox (157, 140 ESR, 156) | Windows (WinHTTP, Windows 11 25H2) | pactester (pacparser 1.5.3) |
|---|---|---|---|---|
path and query of https:// | removed | removed | removed | kept |
path and query of http:// | kept | removed | kept | kept |
#fragment | removed | removed | removed for https, kept for http | kept |
| user name and password | removed | kept, also for https | removed | kept |
| Measured | lab, 2026-10-12 | lab, 2026-10-12 | lab, 2026-10-11 and 2026-10-12 | lab, 2026-10-12 |
Edge and Firefox on Windows gave exactly the same results as Chrome and Firefox on Linux, so the operating system makes no difference for the browsers. Windows programs that use the Windows proxy settings (WinHTTP) differ from both, as the table shows.
Two examples of what the script sees:
https://www.example.com:x@other.example/a?b=1arrives in Chrome, Edge and Windows ashttps://other.example/, in Firefox ashttps://www.example.com:x@other.example/, and in pactester unchanged.http://other.example/x.www.example.comarrives in Chrome and Windows unchanged and in Firefox ashttp://other.example/.
So a wildcard test over url, such as shExpMatch(url, "*www.example.com*"), can be made true
for any destination in every major engine, just by different means: through the query or path
of an http address in Chrome, Edge and Windows, and through a fake user name in Firefox
(PAC-X009). Chrome 51 and older passed the path and query of https
addresses too (source: code). Earlier versions of Firefox were not measured.
Error handling, Ex functions and host case differ too
The rows for Chromium, Firefox and pacparser come from reading each engine’s source code at the commit given on its engine page. The Windows column was measured in the lab on Windows 11 25H2. The host case row was also measured in Edge 155, Chromium 145 and Firefox 157.
| Behaviour | Chromium (Chrome, Edge) | Firefox | Windows (WinHTTP, WinINet) | pacparser (pactester) | Source, date |
|---|---|---|---|---|---|
| No return / non-string result | connects directly | connects directly | the result is read as text; with no usable entry the connection goes direct | returns the string undefined | code, 2026-10-04; Windows: lab, 2026-10-11 |
| Script throws an exception | connects directly | connects directly | the program that asked gets an error, no proxy | error, no result | code, 2026-10-04; Windows: lab, 2026-10-11 |
Calls FindProxyForURLEx if defined | no | no | yes | yes | code, 2026-10-04; Windows: lab, 2026-10-11 |
host lower-cased by the engine | yes, and the host part of url too; the path keeps its case | yes, and the host part of url too | WinHTTP: no, host and url keep the case; WinINet: yes, but an IPv6 address keeps its letters | no | Chromium, Firefox: lab, 2026-10-15; pacparser: code, 2026-10-04; Windows: lab, 2026-10-11 and 2026-10-15 |
Consequences:
- A PAC that tests the path, the query or a user name in
urlbehaves differently in Chrome, Firefox, Windows andpactester. Decide onhost(PAC-C001). - A missing default
returnsends traffic around the proxy in every browser, without an error (PAC-X001). - A file that only defines
FindProxyForURLExdoes nothing in browsers, but works on Windows (PAC-K004). - Chrome, Edge and Firefox hand the script
Intranet.Corp.Exampleasintranet.corp.example, but Windows services that use WinHTTP hand it over unchanged. Lower-casehostyourself (host = host.toLowerCase();) so every engine compares the same string (PAC-K009).
A final dot stays in the host, and international names arrive in punycode
We also measured two less common forms of address in Chrome 155, Edge 155, Firefox 157, Windows 11 (WinHTTP and WinINet) and pactester (lab, 2026-10-15). The source code of Chromium and Firefox gives the same answer.
- A final dot after the host name, as in
http://intranet.corp.example./, is kept. The script getsintranet.corp.example.inhost, and the dot is also inurl. ThendnsDomainIs(host, ".corp.example")andshExpMatch(host, "*.corp.example")are both false, so such an address takes the default route of the file. If that matters, remove the dot first:if (host.charAt(host.length - 1) == ".") host = host.slice(0, -1);(PAC-C011). - An international host name (one with letters outside A–Z) reaches the script in its
ASCII form, called punycode, which starts with
xn--.bücher.exampleandBÜCHER.exampleboth arrive asxn--bcher-kva.example, in lower case, in all browsers and also in Windows (WinHTTP and WinINet), although WinHTTP keeps the case of ordinary names. The other parts of such a name are lower-cased with it:BÜCHER.Corp.Examplearrives asxn--bcher-kva.corp.example, in WinHTTP too. SoshExpMatch(host, "*bücher*")never matches; writeshExpMatch(host, "*xn--bcher-kva*")ordnsDomainIs(host, ".xn--bcher-kva.example"). Only pactester passes the name as you type it, so a test there can match where no browser does (PAC-E014).
The same holds for the browser’s own proxy bypass list, the list of hosts that a fixed proxy setting sends
direct. In Chrome, Edge and Firefox, an entry .corp.example or *.corp.example does not match
intranet.corp.example. with a final dot, and an international name matches only when the entry is
written in its xn-- form. This is the same whether the list comes from the command line, from a browser
policy (ProxyBypassList in Chrome and Edge, Passthrough in Firefox) or from the Windows proxy settings,
with one exception: Firefox cannot match an international name from the Windows list at all (see below).
In Chrome and Edge, a single non-ASCII character in --proxy-bypass-list on the command line makes the
browser ignore the whole list, while the same list set by the policy keeps its other entries. A bare entry
corp.example also matches its subdomains in Firefox’s own setting and policy, but in Chrome and Edge it
matches only corp.example itself (lab, 2026-10-15).
The exception list in the Windows proxy settings follows its own rules:
- When the list is set through the documented Windows programming interface, Windows refuses an entry
that starts with a dot, such as
.corp.example; write*.corp.example. An international name set that way is stored in itsxn--form, so it then works in Chrome and Edge. Written straight into the registry, the entry stays as typed and never matches. - The proxy dialog of Internet Options (Connections, LAN settings, Advanced) does the same, and it does not
say so: with
.corp.exampleanywhere in the exception box it closes without a message and keeps the list that was there before, so the change is lost. It storesbücher.exampleasxn--bcher-kva.exampleand shows it in Unicode again, and it turnsa.example, b.exampleintoa.example;b.example(lab, Windows 11, 2026-10-15). - The proxy page of the Windows Settings app (Network & internet, Proxy, “Use a proxy server”) stores the
list by the same rules, and it does not say so either: when an entry starts with a dot, Save closes the
dialog without a message and the earlier list stays. Until the Settings app is closed, its dialog keeps
showing the list as it was typed, so the change looks saved; after a restart of the app it shows the list
that Windows kept. It stores
*.bücher.exampleas*.xn--bcher-kva.exampleand shows it in Unicode again, turns commas and spaces between entries into;, and an entry<local>typed into the box ticks the check box for local addresses instead (lab, Windows 11 25H2, 2026-10-15). - Firefox with “Use system proxy settings” reads the Windows list with stricter rules than its own
setting: an entry has to match the whole host name, so
corp.exampleand.corp.examplematch no subdomain, and only*.corp.exampledoes. - Firefox with “Use system proxy settings” cannot send an international host direct by naming it in the
Windows list. Firefox looks for the host in its
xn--form, but when it reads the list, Windows hands back every part between dots that starts withxn--converted to Unicode, wherever that part stands and whether it is writtenxn--orXN--:xn--bcher-kva.examplearrives asbücher.example, and*.xn--bcher-kva.exampleandshop.xn--bcher-kva.examplearrive as*.bücher.exampleandshop.bücher.example, also with a*or a port added at the end. The two strings never match, and an entry typed in Unicode does not help either. What worked in the lab are patterns in which no part between dots starts withxn--, because Windows leaves those as they are:*.example, which also covers every other name in that domain, or*xn--bcher-kva.examplewith the star directly in front ofxn--, which also coversshop.xn--bcher-kva.example. Chrome and Edge get the list unchanged and match thexn--entries. Firefox’s Windows code (MatchOverridein nsWindowsSystemProxySettings.cpp) compares thexn--host with the entries as Windows returns them and converts neither side. Firefox’s own setting and its policyPassthroughare not affected (lab, Firefox 157, Windows 11, 2026-10-15; source: code). - One entry that starts with
xn--but is not a validxn--name, for examplexn--a.example, stops Windows from handing the proxy settings to Firefox at all. Firefox with “Use system proxy settings” then connects directly for every address, as if no proxy were set, because its Windows code answersDIRECTwhen it cannot read the settings (GetProxyForURIin the same file). Chrome and Edge keep using the proxy and the other entries. The same entry also takes away a setup script (PAC URL) set in the same Windows settings: Firefox then loads no PAC file and connects directly, because it reads the script address in the same request to Windows (GetPACURIin the same file). Programs that use WinINet, the network library behind Internet Options, with the Windows settings keep using the script, the proxy and the other entries. The Windows Settings app shows the manual proxy as switched off and empty while such an entry is stored, although the proxy stays on. Check a Windows exception list for such entries before it is rolled out (lab, Firefox 157, Chrome 155 and WinINet, Windows 11, 2026-10-15; source: code). - The Windows entry
<local>sends every name without a dot, such asintranet, direct. It works in all three browsers and from every source, but not for a name with a final dot such asintranet..
Test it
Paste your file into the online PAC file tester. It runs FindProxyForURL for your URL
in the engine profile you choose, shows the path to the line that decided and rates the file against the
rule catalogue.
References
- MDN: Proxy Auto-Configuration (PAC) file
- Engine pages: Chromium, Firefox, pacparser, Windows WinHTTP
Frequently asked questions
What does FindProxyForURL return?
A string. "DIRECT" means connect without a proxy, "PROXY host:port" means use that HTTP proxy, and "SOCKS host:port" means a SOCKS proxy. Several entries separated by semicolons are tried in order, for example "PROXY p1.example:8080; PROXY p2.example:8080".
What happens if FindProxyForURL returns nothing or throws an error?
Chromium and Firefox treat it as a script failure and connect directly, so traffic silently bypasses the proxy. Windows also connects directly when the function returns nothing, and when it throws, the program that asked gets an error instead of a proxy. pacparser (pactester) returns the string "undefined" or reports an error. Always end the function with an unconditional return.
Should I test url or host?
Test host for domain decisions. What url contains depends on the browser, and parts of it can be chosen by whoever writes the link. Chrome removes the path and query of https URLs before calling the function, Firefox removes them for every URL but keeps a user name and password written before the host.
Does a fake user name such as https://www.example.com:x@other.example/ still get past a url check?
It depends on the browser. Chrome, Edge and Windows programs remove the user name and password before calling the function, so the script sees https://other.example/ and the trick fails. Firefox keeps them, so shExpMatch(url, "*www.example.com*") is true there, for http and https, on Windows too (lab, Chrome 145, Edge 155, Firefox 157 and 156, Windows 11, 2026-10-12). Test host instead of url and the trick has nothing to match.
How do I test a FindProxyForURL function?
Paste the file into the online PAC file tester at findproxyforurl.net/check/. It runs the function for your URL and client IP in the engine profile you choose (Chromium, Firefox, pacparser, or one of the two Windows profiles, WinHTTP and WinINet) and shows which rule decided.