console used in the PAC
medium
console.log works in Chrome and in current pactester builds, but Firefox, Windows (WinHTTP) and older pactester builds do not define console. There the call throws an error and the request is handled as a script failure.
Why it matters
console.log(host) is often left over from testing a PAC file in a browser’s developer
console. Whether it works depends on the engine that runs the file:
- Chrome (and other browsers built on Chromium) defines a
consoleobject in the PAC context; the call does not fail (lab, Chrome 145). - pactester (pacparser) 1.5.3 defines
console; pactester 1.4.6 does not (lab). - Windows (WinHTTP, Windows 11) does not define
console(lab). The call throws a ReferenceError, which has the same effect as any other exception (PAC-E006): the request is handled as a script failure. - Firefox does not define
consoleeither (lab, Firefox 157). There, too, the call throws and the request is handled as a script failure.
The output is never shown to the user anyway, so the call does nothing useful in a deployed
file. The only debugging function the PAC format itself defines is alert(), which has its own
differences (PAC-K002).
How to fix
Remove console.log and other console calls before you deploy the file; test the file with a separate test tool.
Examples
Bad
function FindProxyForURL(url, host) {
console.log("PAC called for " + host);
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 | console is defined (an object); calls do not throw. | lab, verified 2026-10-04 |
| firefox | console is undefined; a call throws and the request is handled as a script failure. | lab, verified 2026-10-12 |
| pacparser | console is defined in 1.5.3 and undefined in 1.4.6, where a call throws. | lab, verified 2026-10-04 |
| winhttp | console is undefined; a call throws and the request is handled as a script failure. | lab, verified 2026-10-11 |
Related rules
- Browser or Node.js objects used in the PAC PAC-E018
- Evaluation throws an exception PAC-E006
- alert() used in the PAC PAC-K002