PAC-K022 · console-in-pac

console used in the PAC

medium · Compatibility across engines

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 console object 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 console either (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 checker

Good

function FindProxyForURL(url, host) {
  return "PROXY proxy.corp.example:8080";
}
Open good example in checker

Engine behaviour

EngineBehaviourSource
chromiumconsole is defined (an object); calls do not throw.lab, verified 2026-10-04
firefoxconsole is undefined; a call throws and the request is handled as a script failure.lab, verified 2026-10-12
pacparserconsole is defined in 1.5.3 and undefined in 1.4.6, where a call throws.lab, verified 2026-10-04
winhttpconsole is undefined; a call throws and the request is handled as a script failure.lab, verified 2026-10-11

Source: code = read in the engine's source, doc = vendor documentation, lab = observed in a lab run, expert = practitioner knowledge, not yet verified.

Related rules

References

Last updated: