Proxy autoconfiguration

2008/04/15 by Lassi A. Liikkanen

Custom proxy.pac - creating and debugging

This page provides a simple guide and an example of a customized proxy autoconfiguration file.

Proxy autoconfiguration is almost an ancient feature first introduced to Netscape Navigator in late 90's. Proxy autoconfiguration file, or proxy.pac, is a file that the browser users to determine how a URL is retrieved, directly or through a proxy server. The PAC is basically a script written in JavaScript and run by the browser at every request for a URL. However, there are few differences to other kinds of JavaScript you normally use, which affect how use and debug the file:

  • Special set of functions are available for the execution of the proxy.pac
  • Execution of proxy.pac does not support all features of Javascript
  • Different browsers have different implementations of proxy.pac execution

The consequence is that proxy.pac is bit difficult to debug. I myself use Firefox's error console for testing.


Example of my proxy.pac customized for mobile use across networks and two different proxy servers, each of which can be alternatively accessed by a SSH tunnel connection.

function FindProxyForURL(url, host) {
	This script determines the proxy based on following conditions:

	a) Few common exception URL which can't be accessed without proxy
	b) The network currently connected to
	c) The address being visited

	because the PAC syntax is not strict javascript, ELSEIF and ELSE structures are not used here

	// Exception URL::s
if (
	isPlainHostName(host) ||
	shExpMatch(url, '*')
	{ return 'DIRECT'; }

// at home
if (isInNet(myIpAddress(), '', ''))
	if (dnsDomainIs(host, '') || dnsDomainIs(host, ''))
		{ return 'PROXY localhost:89; DIRECT'; }

	else if (shExpMatch(url, '*'))
		{ return 'PROXY localhost:89; DIRECT';}

	return 'PROXY localhost:88; DIRECT';

// at working place, three c level networks
if (
isInNet(myIpAddress(), '', '') ||
isInNet(myIpAddress(), '', '') ||
isInNet(myIpAddress(), '', '') )

	if (dnsDomainIs(host, '') || dnsDomainIs(host, '')
	|| shExpMatch(url, '*'))
		{ return 'PROXY; DIRECT'; }

	return 'PROXY; DIRECT';

// We're somewhere else, 3g, wifi, etc.
if (
	dnsDomainIs(host, '') || dnsDomainIs(host, '')
	|| shExpMatch(url, '*')
		{ return 'PROXY localhost:89; DIRECT'; }

return 'PROXY localhost:88; DIRECT';

Resilion proxy.pac syntax

Keywords: [computers] , [www-techniques] Document's status: Ok (Document dates explained)

This document created: 2008/04/15
Modified: 2008/04/15
Published: 2008/04/15

This document's permanent URI (linking):

© Lassi A. Liikkanen 2008 - 2021. All rights reserved.
^Top of the Page^

*Change layout:
Printable printable
Large text


@lassial Twitter feed: