HowTo: Test a Proxy PAC File Syntax With Syntax Checker

How can I test a Proxy PAC file syntax under Apple OS X / Linux / *BSD or Unix like operating systems using command line options?

You can use a tool called pactester written in Perl. This tool test Proxy Auto Configuration (PAC) files. From the project home page:
Tutorial details
Difficulty level Intermediate
Root privileges Yes/No
Requirements Perl
Est. reading time N/A

PAC files are used by browsers to determine the ‘right’ proxy for a URL. Since the PAC file evaluation mechanism is generated inside the browser and cannot be accessed from outside, the only way to tell which proxy your browser will use for a specific URL is manual inspection of the PAC file. But manual inspection doesn’t really scale very well. Pactester resolves this problem. It makes use of JavaScript interpreter and Netscape/Mozilla APIs to evaluate the PAC files and automates the whole process. Pactester reads a PAC file, evaluates it in a JavaScript context and uses this PAC file’s logic to determine the proxy for a specific URL.


Debian and Ubuntu Linux user type the following command to install this tool:
$ sudo apt-get install libpacparser1
Sample outputs:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
0 upgraded, 1 newly installed, 0 to remove and 11 not upgraded.
Need to get 395 kB of archives.
After this operation, 1,339 kB of additional disk space will be used.
Get:1 squeeze/main libpacparser1 amd64 1.2.6-2 [395 kB]
Fetched 395 kB in 2s (153 kB/s)                       
Selecting previously deselected package libpacparser1.
(Reading database ... 281091 files and directories currently installed.)
Unpacking libpacparser1 (from .../libpacparser1_1.2.6-2_amd64.deb) ...
Processing triggers for man-db ...
Setting up libpacparser1 (1.2.6-2) ...

A note about source code installation

Type the following wget command to download the source code:
$ cd /tmp/
$ wget

Sample outputs:

--2012-11-20 21:34:17--
Resolving, 2404:6800:4005:c00::52
Connecting to||:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1214308 (1.2M) [application/x-gzip]
Saving to: `pactester-1.0.8.tar.gz'
100%[=============================>] 12,14,308    352K/s   in 3.4s    
2012-11-20 21:34:21 (352 KB/s) - `pactester-1.0.8.tar.gz' saved [1214308/1214308]

Untar the tarball with tar command:
$ tar xvf pactester-1.0.8.tar.gz
Sample outputs:


Install pactester in ~/pactester directory, enter:
$ mkdir $HOME/pactester
$ cd pactester-1.0.8/build/
$ ./ $HOME/pactester

Sample outputs:

Installing /home/vivek/pactester/lib/perl/5.10.1/auto/JavaScript/SpiderMonkey/
Installing /home/vivek/pactester/lib/perl/5.10.1/JavaScript/
Installing /home/vivek/pactester/man/man3/JavaScript::SpiderMonkey.3pm
Appending installation info to /home/vivek/pactester/lib/perl/5.10.1/perllocal.pod
-e ###########################################
>>PERLLIB=-e /home/vivek/pactester/share/perl/5.10.1:/home/vivek/pactester/lib/perl/5.10.1
-e I have set up PERLLIB path in pactester script, so you won't have to
-e set it as an environment variable :)

How do I use pactester command to test proxy auto-config (pac) files?

The syntax is:

pactester -p /path/to/proxy.pac.file -u url
pactester -p /path/to/proxy.pac.file -u url -c

Sample proxy.pac file:

function FindProxyForURL(url, host) {
    // Your proxy server name and port
    var proxyserver = '';
    //  Here's a list of hosts to connect via the PROXY server
    var proxylist = new Array(
    // Return our proxy name for matched domains/hosts
    for(var i=0; i<proxylist.length; i++) {
        var value = proxylist[i];
        if ( localHostOrDomainIs(host, value) ) {
            return "PROXY "+proxyserver;
    return "DIRECT";

To find out proxy string as returned by pac file proxy.pac for the URL
$ pactester -p proxy.pac -u
Sample outputs:


To find out proxy string as returned by pac file proxy.pac for the URL
$ pactester -p proxy.pac -u
Sample outputs:


Test setting for a client with IP address
$ pactester -p wpad.dat -c -u
Create a list of urls/hosts in /tmp/proxy.url.test file:

Now, find out proxy settings for a list of urls specified in /tmp/proxy.url.test file
$ pactester -p /var/www/html/proxy.pac -f /tmp/proxy.url.test
Sample outputs: : PROXY : DIRECT : PROXY : PROXY
http://nas03 : DIRECT
http://router1 : DIRECT : PROXY

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 1 comment so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
1 comment… add one
  • I Pay Attention Dec 22, 2014 @ 14:58

    From the project home page:

    Important: I have stopped maintaining this version of pactester. Please use the version that comes with ‘pacparser’. -Manu Garg

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum