Browser or Node.js objects used in the PAC
high
A PAC file runs neither in a web page nor in Node.js. window, document, navigator, fetch, setTimeout, process, require and similar objects are not defined, so using them throws an error and the browser treats the file as broken.
Why it matters
PAC code runs in a small JavaScript context that has the ECMAScript built-ins (String, Array,
Math and so on) and the PAC helper functions, nothing else. Objects from a web page, such as
window, document, navigator, localStorage, XMLHttpRequest, fetch, setTimeout and
setInterval, do not exist there. The same holds for the Node.js objects process, require,
module, exports, global and Buffer: a file that reads environment variables through
process or calls require() fails before it returns anything.
Using one of these names throws a ReferenceError (“x is not defined”), which has the same effect
as any other exception (PAC-E006): the request is handled as a script failure. In the lab,
Chrome 145 and pactester 1.4.6 and 1.5.3 had no window, setTimeout or fetch, and Windows
(WinHTTP, Windows 11) had no window or navigator.
console is a special case: some engines define it and some do not. PAC-K022 covers it.
How to fix
Remove window, document, navigator, fetch, setTimeout, process and require references. Decide on url and host only, and test the file with a separate test tool.
Examples
Bad
function FindProxyForURL(url, host) {
if (navigator.userAgent.indexOf("Firefox") >= 0) {
return "DIRECT";
}
return "PROXY proxy.corp.example:8080";
}
Open bad example in checkerGood
function FindProxyForURL(url, host) {
return "PROXY proxy.corp.example:8080";
}
Open good example in checkerEngine behaviour
| Engine | Behaviour | Source |
|---|---|---|
| chromium | window, setTimeout and fetch are undefined in the PAC context; using them throws. | lab, verified 2026-10-04 |
| pacparser | window, setTimeout and fetch are undefined in 1.4.6 and 1.5.3; using them throws. | lab, verified 2026-10-04 |
| winhttp | window and navigator are undefined; using them throws. | lab, verified 2026-10-11 |
Related rules
- console used in the PAC PAC-K022
- Call to a function that is not defined PAC-E005
- Evaluation throws an exception PAC-E006
- alert() used in the PAC PAC-K002