Debug PAC File

As of September 2015 the JavaScript alert() function no longer generates alerts/logging messages in any of the major web browsers. As such this page exists for historical purposes only and will be removed shortly.

During the creation and subsequent testing of PAC file rules it can sometimes be unclear what value a function or variable is returning, particularly if a rule appears correct but is non-functional.

Firefox and Internet Explorer both support the use of the JavaScript alert() function, a function often used to present a prompt to an end-user visiting a website. It’s possible to leverage this function to return the value of the default PAC variables and functions.

With a PAC file configured and containing the below code, visit a website with which you wish to review the returned variable/function values. In Internet Explorer, a JavaScript alert prompt will appear for each resource requested, while Firefox will store the results in the browser Error Console (see below for further details).

See the screenshots at the bottom of this page as an example of the output in both browsers.

Debug PAC File

function FindProxyForURL(url, host) {

	debugPAC ="PAC Debug Information\n";
	debugPAC +="-----------------------------------\n";
	debugPAC +="Machine IP: " + myIpAddress() + "\n";
	debugPAC +="Hostname: " + host + "\n";
	if (isResolvable(host)) {resolvableHost = "True"} else {resolvableHost = "False"};
	debugPAC +="Host Resolvable: " + resolvableHost + "\n";
	debugPAC +="Hostname IP: " + dnsResolve(host) + "\n";
	if (isPlainHostName(host)) {plainHost = "True"} else {plainHost = "False"};
	debugPAC +="Plain Hostname: " + plainHost + "\n";
	debugPAC +="Domain Levels: " + dnsDomainLevels(host) + "\n";
	debugPAC +="URL: " + url + "\n";

	// Protocol can only be determined by reading the entire URL.
	if (url.substring(0,5)=="http:") {protocol="HTTP";} else
		if (url.substring(0,6)=="https:") {protocol="HTTPS";} else
			if (url.substring(0,4)=="ftp:") {protocol="FTP";}
				else {protocol="Unknown";}
	debugPAC +="Protocol: " + protocol + "\n";

	// Reduce volume of alerts to a useable level, e.g. only alert on static text pages.
	if (!shExpMatch(url,"*.(js|xml|ico|gif|png|jpg|jpeg|css|swf)*")) {alert(debugPAC);}

	return "DIRECT";

The PAC file will attempt to only return information for web pages (e.g. HTML, PHP, ASP) which are requested. If you wish to return the values for content such as images remove the relevant file extension from line 23.

Accessing the Firefox (4.0+) Error Console

Windows Mac OS X
1. Open Firefox, open the Web Developer menu.
2. Select Error Console.
3. Select the Messages filter.
1. Open Firefox, open the Tools menu.
2. Select Error Console.
3. Select the Messages filter.