Automatic proxy configuration via a PAC file is a way to teach your browser and system to decide on their own which traffic to send through a proxy server and which to let go direct. In this guide, you'll understand how it works and build your own working file.

Introduction: What You'll Get and Who This Guide Is For

By the end of this guide, you'll have a fully working PAC file that you can copy, plug in your own domains, and enable in any operating system or browser. You'll understand not just where to tick boxes, but the logic behind traffic routing decisions.

Here's what you'll get:

  • A ready-to-use PAC file for three real-world routing scenarios.
  • An understanding of PAC's built-in functions and the ability to write your own rules.
  • The skill to enable auto-configuration in Windows, macOS, Linux, Chrome, and Firefox.
  • Knowledge of what WPAD is and why it's better to keep it off in public networks.
  • The ability to debug issues and spot syntax errors.

Who this guide is for: system administrators, developers, testers, and power users who need flexible control over traffic routing—for example, sending some requests through a corporate proxy and others directly.

What you should know upfront: basic concepts of what a proxy server, IP address, and domain are. JavaScript knowledge is a plus but not required—we'll cover PAC syntax from scratch. Knowing how to open a text editor and system settings is enough.

How long it will take: about 60 minutes for a full walkthrough. Writing a basic PAC file takes 10-15 minutes, enabling it in your system another 10, and debugging depends on the situation.

Tip: Read the guide in order, even if you only need one section. Understanding the logic of PAC saves hours of debugging later.

Preliminary Preparation: Tools and Access

Before you start, make sure you have everything you need. Proper preparation will prevent interruptions mid-process.

Required Tools

  • Text editor. Any code editor works: Notepad++, VS Code, Sublime Text, or even the standard Windows Notepad. The key is to save the file without a BOM.
  • Your proxy server details. You need the address (IP or domain) and port of the proxy. For example, 192.168.1.100 and port 3128. Check with your administrator or your proxy provider's dashboard.
  • Access to a web server or a local folder. The PAC file needs to be placed somewhere the system can read it. This could be a local file on disk or a file served over HTTP.
  • Administrator rights. You'll need admin rights to change system proxy settings in Windows, macOS, and Linux.

System Requirements

PAC files are supported by all modern operating systems and browsers. No special software needs to be installed. The PAC mechanism is built into the network libraries of Windows, macOS, Linux, and all popular browsers.

Backing Up Current Settings

Before changing network settings, be sure to record your current configuration.

  1. Open the current proxy settings in your system.
  2. Take a screenshot or write down all the parameters: address, port, mode.
  3. Save this record in a separate file on your desktop.

Caution: Incorrect proxy settings can completely cut off your internet access. If this is a work computer on a corporate network, coordinate changes with your system administrator.

Tip: Create a separate copy of the original PAC file if one already exists in your organization. That way you can always roll back to a working version.

Basic Concepts: Key Terms in Plain Language

Before we write any code, let's clarify the terms. This is the foundation without which the next steps won't make sense.

What Is a PAC File

PAC stands for Proxy Auto-Configuration. Essentially, it's a plain text file with a .pac extension containing a small JavaScript program. For each requested address, this program returns a decision: go direct or use a proxy.

Imagine a traffic officer at an intersection. For each car, they decide which direction it should take. A PAC file is that officer for your network traffic.

Why PAC When You Have System Settings

Standard system proxy settings work on an all-or-nothing basis. You either send all traffic through a proxy or you don't. The most you can do with checkboxes is specify an exclusion list.

A PAC file solves a more complex problem. Consider a typical scenario: some traffic must go through a proxy, while the rest goes direct. For example, requests to internal corporate resources go directly over the local network, while requests to external sites go through the company's filtering proxy.

Setting up such a split with simple checkboxes is extremely awkward—the exclusion list can be huge and constantly changing. A PAC file lets you describe the logic once and change it flexibly. Plus, the same file can be distributed to hundreds of computers.

How It Works: Core Principles

When a browser is about to open an address, it calls a function from the PAC file and passes it two parameters: the full URL and the hostname. The function processes this data and returns a string with an instruction. The browser reads that string and acts accordingly.

Key point: The PAC file runs on the client side—your computer—not on a server. This means your device makes the routing decisions.

WPAD in a Nutshell

WPAD stands for Web Proxy Auto-Discovery. It's a mechanism that lets a device find the PAC file on the network by itself, without manual configuration. The device asks the network: where is the configuration file? And the network answers with an address. We'll cover WPAD in detail in a separate section.

Tip: Keep the distinction in mind: PAC is the file with rules, and WPAD is a way to automatically find it. These are two different, though related, concepts.

Step 1: Dissecting the Anatomy of a PAC File

Goal of this step: understand the internal structure of a PAC file and learn to read its layout. After this step, you'll be able to read anyone else's PAC file like an open book.

The Main Function: FindProxyForURL

The heart of any PAC file is a function named FindProxyForURL. This name is strictly fixed—you can't change it. The browser looks for this specific function and calls it.

The function takes two arguments:

  1. url — the full request address, e.g., http://example.com/page.html with all the details.
  2. host — only the hostname extracted from the address, e.g., example.com without the protocol and path.

The simplest form of the function looks like this. It always returns the decision to send traffic direct:

function FindProxyForURL(url, host) { return "DIRECT"; }

Here we see the function declaration, and inside it a return statement that returns the string DIRECT. That string is the command for the browser.

Return Values: DIRECT, PROXY, SOCKS

The function must return a string with one of the following values or a combination of them.

  • DIRECT — connect directly, without a proxy. This is the simplest option.
  • PROXY host:port — use an HTTP proxy at the specified address and port. For example, PROXY 192.168.1.100:3128.
  • SOCKS host:port — use a SOCKS proxy. For newer browsers, there are more specific variants like SOCKS4 and SOCKS5.
  • SOCKS5 host:port — use a version 5 SOCKS proxy, the modern standard.
  • HTTPS host:port — connect to the proxy over an encrypted channel. Supported in modern browsers.

Combining Values with Semicolons

The most powerful part of return values is the ability to specify multiple options separated by semicolons. The browser will try the first option; if it's unavailable, it moves to the second.

Example string with fallback: return "PROXY 192.168.1.100:3128; PROXY 192.168.1.101:3128; DIRECT";

Here the browser will first try the first proxy. If it doesn't respond, it tries the second. If the second is also unavailable, it goes direct. This ensures fault tolerance.

Caution: There is exactly one space between the command and the address, and a semicolon between options. An error in these separators will cause the entire file to stop working.

Tip: Always add DIRECT at the end of the chain as a fallback if you want the internet to keep working even when all proxies fail. But remember—this can bypass the proxy, which is not always desirable.

✅ Check: You should understand that FindProxyForURL receives an address and returns an instruction string. If you can explain in your own words what the string PROXY 10.0.0.1:8080; DIRECT does, you've mastered this step.

Step 2: Mastering PAC's Built-in Functions

Goal of this step: learn the four main built-in functions that let you make routing decisions. Without them, a PAC file would be useless.

Inside FindProxyForURL, we need some way to analyze the address and host. For this, the PAC language has ready-made functions. We'll cover the four most important ones with examples for each.

The shExpMatch Function: Pattern Matching

The shExpMatch function checks whether a string matches a given pattern. The pattern uses wildcard characters, where an asterisk means any number of any characters.

Syntax: shExpMatch(string, pattern). The function returns true or false.

Example: checking whether a URL contains a certain path:

if (shExpMatch(url, "*/internal/*")) { return "DIRECT"; }

Here we check whether the address contains the fragment /internal/. If it does, we go direct. The asterisks on either side mean anything can appear before or after.

Example: checking a host against a mask:

if (shExpMatch(host, "*.example.com")) { return "PROXY 192.168.1.100:3128"; }

This line will match any subdomain of example.com: mail.example.com, shop.example.com, and so on.

The dnsDomainIs Function: Domain Membership Check

The dnsDomainIs function checks whether a host belongs to a specific domain. It's more precise and faster than shExpMatch for this task.

Syntax: dnsDomainIs(host, domain).

Example: if (dnsDomainIs(host, ".example.com")) { return "DIRECT"; }

Note the dot before the domain name. It ensures that only a subdomain of example.com matches, not something like notexample.com. This is an important security detail.

Tip: Use dnsDomainIs instead of shExpMatch when you need to check domain membership specifically. It's faster and more reliable because it doesn't involve pattern parsing.

The isInNet Function: Checking IP Within a Range

The isInNet function checks whether an IP address falls within a given subnet. It's the key function for separating the internal network from the external one.

Syntax: isInNet(host, network_address, mask). The function takes a host, the subnet's base address, and a mask.

Example: checking if a host belongs to the local network:

if (isInNet(host, "192.168.0.0", "255.255.0.0")) { return "DIRECT"; }

This line checks whether the host falls within the address range from 192.168.0.0 to 192.168.255.255. If so, we go direct—it's an internal resource.

Caution: The isInNet function may resolve a domain name to an IP address, which slows down processing. If the host is passed as a name rather than an IP, a DNS lookup will occur. We'll talk more about this in the optimization section.

The myIpAddress Function: Your Device's IP

The myIpAddress function returns the IP address of the computer executing the PAC file. It's useful when the decision depends on which network you're currently on.

Syntax: myIpAddress(). It takes no arguments.

Example: if you're on the office network, use a proxy; otherwise, go direct:

if (isInNet(myIpAddress(), "10.0.0.0", "255.0.0.0")) { return "PROXY 10.0.0.1:8080"; } else { return "DIRECT"; }

Here we check our own IP address. If it's in the office range 10.x.x.x, we're at the office and should use the office proxy.

Additional Useful Functions

  • dnsResolve(host) — resolves a domain name to an IP address. Useful when you need to make a decision based on the IP.
  • isPlainHostName(host) — checks whether the hostname has no dots, meaning a simple short name like intranet. Such names usually indicate internal resources.
  • localHostOrDomainIs(host, full_name) — checks for a match with the full hostname.

✅ Check: You should be able to explain the difference between shExpMatch and dnsDomainIs in words, and understand why isInNet is needed. Try to mentally write a condition that sends all traffic to the company.local domain direct.

Step 3: Writing a Ready PAC File for Three Scenarios

Goal of this step: create three working PAC files for specific real-life scenarios. You can copy and adapt each one to your needs.

Scenario 1: Only Specific Domains Through a Proxy

Scenario: you need to send only a few specific sites through a proxy, and everything else direct. This is a common case when you need a proxy for targeted use.

function FindProxyForURL(url, host) { if (dnsDomainIs(host, ".site-one.com") || dnsDomainIs(host, ".site-two.com")) { return "PROXY 192.168.1.100:3128"; } return "DIRECT"; }

Let's break down the logic. We check whether the host belongs to one of the two listed domains. Two vertical bars mean logical OR. If there's a match, we send through the proxy. In all other cases, the function reaches the last line and returns DIRECT.

Tip: To add a new domain to the list, simply append another condition with the OR operator. For example, before the closing brace, add: || dnsDomainIs(host, ".site-three.com").

Scenario 2: Everything Through a Proxy Except the Internal Network

Scenario: all traffic goes through the corporate proxy, but requests to internal company resources must go directly, bypassing the proxy. This is a standard corporate setup.

function FindProxyForURL(url, host) { if (isPlainHostName(host) || dnsDomainIs(host, ".company.local") || isInNet(host, "10.0.0.0", "255.0.0.0") || isInNet(host, "192.168.0.0", "255.255.0.0")) { return "DIRECT"; } if (shExpMatch(host, "localhost") || host == "127.0.0.1") { return "DIRECT"; } return "PROXY 192.168.1.100:3128; DIRECT"; }

Here we first describe all the cases that should go direct: simple names without dots, the internal domain, local subnets, and localhost. If none of the conditions match, the address is external—so we send it through the proxy with DIRECT as a fallback.

Scenario 3: Different Proxies for Different Subdomains

Scenario: you have several proxy servers, and different groups of sites need to go through different ones. For instance, media content through one proxy and work services through another.

function FindProxyForURL(url, host) { if (dnsDomainIs(host, ".media.example.com")) { return "PROXY 192.168.1.101:3128"; } if (dnsDomainIs(host, ".work.example.com")) { return "PROXY 192.168.1.102:3128"; } if (dnsDomainIs(host, ".example.com")) { return "PROXY 192.168.1.100:3128"; } return "DIRECT"; }

Caution: The order of conditions is critical here. More specific subdomains are checked first, and the general domain last. If you put the general .example.com condition first, it will catch all subdomains, and the specific rules will never trigger.

The Complete Universal PAC File to Copy

And now for the main event—a complete working PAC file that combines all the scenarios. Copy it, plug in your own domains and proxy addresses. Comments inside start with two slashes and tell you what to change.

function FindProxyForURL(url, host) { var PROXY_MAIN = "PROXY 192.168.1.100:3128"; var PROXY_BACKUP = "PROXY 192.168.1.101:3128"; host = host.toLowerCase(); if (isPlainHostName(host) || host == "localhost" || host == "127.0.0.1") { return "DIRECT"; } if (dnsDomainIs(host, ".company.local") || dnsDomainIs(host, ".intranet")) { return "DIRECT"; } if (isInNet(host, "10.0.0.0", "255.0.0.0") || isInNet(host, "172.16.0.0", "255.240.0.0") || isInNet(host, "192.168.0.0", "255.255.0.0")) { return "DIRECT"; } if (dnsDomainIs(host, ".special-service.com")) { return PROXY_BACKUP + "; " + PROXY_MAIN; } if (dnsDomainIs(host, ".site-one.com") || dnsDomainIs(host, ".site-two.com")) { return PROXY_MAIN + "; " + PROXY_BACKUP + "; DIRECT"; } return "DIRECT"; }

Let's break down what this file does step by step. At the beginning, we declare variables with proxy addresses so you can change them in one place. Then we convert the host to lowercase for reliable comparisons. Next come rule blocks in priority order: first local names, then internal domains, then internal subnets—all going direct. Then specific services and target domains go through the proxy. And at the very end, DIRECT for everything else.

Tip: Using variables at the top of the file is a best practice. When a proxy address changes, you fix one line instead of a dozen.

✅ Check: Save one of these files as proxy.pac. Open it in a browser as a local file—it shouldn't show JavaScript parsing errors. If the browser displays the content as text, the syntax is correct.

Step 4: Hosting the PAC File and Making It Accessible

Goal of this step: save the file correctly and host it so the system can read it. This is a critical step where errors are common.

Saving the File with the Correct Encoding

  1. Open your text editor.
  2. Paste the PAC file code.
  3. Save the file as proxy.pac.
  4. Make sure the encoding is UTF-8 without BOM.

Caution: A BOM character at the start of the file is a common reason PAC doesn't work. Standard Windows Notepad sometimes adds it invisibly. Use Notepad++ or VS Code, where you can explicitly choose UTF-8 without BOM.

Option A: Local File on Disk

The simplest way for a single computer is to place the file locally.

  1. Create a folder, e.g., C:\pac on Windows or a folder in your home directory on other systems.
  2. Copy proxy.pac into it.
  3. Note the full path to the file.
  4. When configuring the system, you'll specify the address using the file protocol.

Option B: Serving via a Web Server

For multiple devices, it's better to serve the file over HTTP. This allows you to update rules centrally.

  1. Place proxy.pac in the root or a folder of your web server.
  2. Set the correct MIME type. The server should serve the file with the type application/x-ns-proxy-autoconfig.
  3. Check accessibility by opening the file's address in a browser.
  4. Make sure the file downloads or displays, rather than returning a 404 error.

Caution: If the web server serves the PAC file with the wrong MIME type, some browsers will refuse to use it. This is one of the trickiest issues because the syntax may be perfectly valid.

Tip: After any change to the PAC file on the server, change something minor to bypass caching. For example, add a comment with the date. More on caching in the debugging section.

✅ Check: Open the PAC file's address directly in a browser. You should see the file's code or a prompt to download it. If you see an access error, the file isn't hosted correctly.

Step 5: Enabling PAC in Operating Systems and Browsers

Goal of this step: connect your ready PAC file in your system. Here we'll focus specifically on the auto-configuration URL field, not on manually entering a proxy address.

Windows

  1. Open System Settings from the Start menu.
  2. Go to Network & Internet.
  3. Select Proxy from the sidebar.
  4. Find the Automatic proxy setup section.
  5. Turn on the Use setup script toggle.
  6. In the Script address field, enter the address of your PAC file.
  7. For a local file, use the file protocol format with the full path.
  8. For a network file, use an HTTP address.
  9. Click Save.

macOS

  1. Open System Settings.
  2. Go to Network.
  3. Select your active connection, e.g., Wi-Fi.
  4. Click the Details or Advanced button.
  5. Go to the Proxies tab.
  6. Check the box next to Automatic Proxy Configuration.
  7. In the URL field, enter the PAC file address.
  8. Click OK, then Apply.

Linux with GNOME

  1. Open System Settings.
  2. Go to Network.
  3. Find the Network Proxy section and click the gear icon next to it.
  4. Select the Automatic mode.
  5. In the Configuration URL field, enter the PAC file address.
  6. Close the window; settings will apply automatically.

Linux with KDE

  1. Open System Settings.
  2. Go to Network, then Proxy Settings.
  3. Choose Use proxy auto-configuration URL.
  4. Enter the PAC file address in the field.
  5. Click Apply.

Google Chrome

It's important to understand: Chrome takes proxy settings from the system by default. There's no separate PAC field in Chrome itself—it uses system settings. However, when launched from the command line, you can specify a PAC file with a separate parameter.

  1. Close all Chrome windows.
  2. Launch Chrome with a command-line parameter pointing to the PAC server via the proxy-pac-url key.
  3. Chrome will use that file, ignoring system settings.

Mozilla Firefox

Firefox has its own proxy settings, independent of the system. This is convenient for testing.

  1. Open the Firefox menu and go to Settings.
  2. Scroll down to the Network Settings section and click Settings.
  3. Select Automatic proxy configuration URL.
  4. Enter the address of your PAC file in the field.
  5. Click OK.
  6. There's a reload button nearby—click it after every file change.

Tip: Firefox is ideal for PAC debugging because it has separate settings and a convenient reload button. Set up and test your PAC in Firefox first, then move it to the system.

✅ Check: After enabling, open any site from your proxy list. It should load. Then open an internal resource—it should also work. If both behave according to the logic, the PAC is applied correctly.

Step 6: Setting Up WPAD for Auto-Discovery

Goal of this step: understand how automatic proxy discovery via WPAD works and make an informed decision about whether to use it.

How WPAD Works

WPAD eliminates the need to manually enter the PAC file address on each device. The device finds the file on its own through two mechanisms.

Via DHCP. When a device receives network settings from a DHCP server, it requests a special option number 252. In that option, the server returns the PAC file address. This is the fastest and most reliable method.

Via DNS. If DHCP doesn't respond, the device tries to find the file over DNS. It sequentially queries names like wpad.your-domain and looks for the file at the standard path wpad.dat on that host.

Detection Order

  1. The device contacts the DHCP server for option 252.
  2. If there's no response, the device constructs the name wpad with its own domain appended.
  3. The device asks DNS for the address of this host.
  4. On success, the device downloads the wpad.dat file from the found server.
  5. wpad.dat is the same PAC file, just with a standard name.

Setting Up WPAD via DNS

  1. Place the PAC file on a web server as wpad.dat.
  2. Set the correct MIME type, the same as for a regular PAC file.
  3. Create a DNS A or CNAME record named wpad pointing to that web server.
  4. Make sure devices on the network have the automatic proxy detection option enabled.

Why You Shouldn't Enable WPAD on Public Networks

Caution: Automatic proxy detection on public networks—like in a café or airport—is a serious security risk. An attacker on the same network can set up a rogue WPAD server and feed your device a malicious PAC file. That file could route all your traffic through a proxy they control.

That's why you should keep the Automatically detect settings option off on unfamiliar networks. Only enable auto-discovery on a trusted corporate network where the infrastructure is under administrators' control.

Tip: On personal devices that you carry across different networks, it's best to disable auto-detection altogether and configure PAC manually only for trusted networks. This simple rule protects against a whole class of attacks.

✅ Check: On a corporate network with WPAD set up, a device with auto-detection enabled should automatically pick up the proxy settings without manually entering an address. Verify by opening a site that should go through the proxy.

Step 7: Debugging and Verifying PAC

Goal of this step: learn to tell whether PAC was applied at all, find syntax errors, and deal with caching.

How to Tell If PAC Was Applied

The most reliable way is to use browser developer tools or special status pages.

  1. In Chrome, open the network status page via net-internals with the proxy section.
  2. There you'll see the currently applied PAC file and its source.
  3. If the field is empty, the PAC wasn't picked up.
  4. In Firefox, use the Network tab in developer tools to see which proxy each request goes through.

Tip: Add a temporary marker rule to your PAC file: make a specific test domain always go through a deliberately nonexistent proxy. If you get a connection error when accessing it, the PAC is definitely being applied.

Common Syntax Errors

  • Missing semicolon at the end of a statement. JavaScript sometimes forgives this, but it's better to always include it.
  • Unclosed curly or round bracket. The whole file stops working. Count your opening and closing brackets.
  • Typo in the function name. For example, FindProxyForUrl with a lowercase letter instead of FindProxyForURL. The name is case-sensitive.
  • Incorrect quotes. Smart typographic quotes instead of plain straight quotes break the code. This often happens when copying from text documents.
  • An extra or missing space in the returned string between PROXY and the address.

Syntax Checking

  1. Open the PAC file in a browser as a local file.
  2. Open the developer console with the F12 key.
  3. Check the Console tab for JavaScript errors.
  4. Red error messages will point to the problematic line.

Dealing with Caching

Caution: Browsers and systems aggressively cache the PAC file. You can fix the file on the server, but the browser will keep using the old version. This is the number one reason for false conclusions that PAC isn't working.

Ways to clear the cache:

  • In Firefox, click the reload button for proxy settings in the network settings window.
  • Fully restart the browser, and sometimes the entire system.
  • On the server, set headers to prevent caching of the PAC file.
  • During debugging, add a random query parameter to the PAC address to force a reload.

Tip: During heavy debugging, configure the web server to serve the PAC file with a no-cache header. That way every change takes effect immediately, saving you a lot of time.

✅ Check: After making a change to the PAC and clearing the cache, the routing behavior should change according to the new rules. If the behavior is unchanged, the cache wasn't cleared.

Step 8: Understanding PAC File Limitations

Goal of this step: learn what a PAC file fundamentally cannot do, so you don't waste time on the impossible.

PAC Doesn't Handle Authentication

Inside a PAC file, you can't specify a username and password for the proxy server. The FindProxyForURL function returns only an address and port, not credentials. If your proxy requires authentication, that's handled separately by the browser or system, which prompts the user or pulls credentials from storage.

This is a deliberate security restriction—PAC files are often accessible over the network, and storing passwords in them would be dangerous.

PAC Doesn't Apply to All Applications

Caution: A PAC file works for browsers and applications that can read system proxy settings. But many command-line utilities, standalone programs, and system services ignore PAC entirely.

For example, command-line download tools often require their own proxy configuration via environment variables. They don't look at the system PAC. The same goes for many desktop applications with their own network settings.

Logic Limitations

  • PAC can't take into account the request content, only the address and host.
  • PAC doesn't see HTTP headers.
  • Complex computations in a PAC slow down the browser, as the function is called for every request.
  • DNS resolution functions inside PAC can cause delays.

Tip: Keep your PAC logic as simple and fast as possible. Avoid frequent calls to dnsResolve and isInNet with domain names—they trigger slow DNS lookups. Whenever possible, make decisions based on the hostname using dnsDomainIs.

✅ Check: You should understand that if a proxy requires a password, PAC won't provide it, and that command-line utilities need to be configured separately. This will save you from fruitless attempts.

Result Check: Successful Setup Checklist

Let's go through the final checklist. Mark each item to confirm everything works.

  • The PAC file is saved in UTF-8 without BOM.
  • The file is accessible at the specified address—it opens directly in a browser.
  • When hosted on a network, it's served with the correct MIME type.
  • The PAC file address is entered in the system or browser settings.
  • Sites from the proxy list load and go through the proxy.
  • Internal resources load directly, bypassing the proxy.
  • Backup proxies kick in when the primary one is unavailable.
  • The browser console shows no JavaScript errors in the PAC file.

How to Test Routing

  1. Open a site that should go through the proxy according to the logic.
  2. Check via an IP detection service that the proxy server's IP is visible.
  3. Open an internal resource and confirm it's reachable directly.
  4. Temporarily disable the primary proxy and verify the backup kicks in.

Success indicators: different categories of sites go different ways according to your logic, there are no console errors, and browser performance hasn't suffered.

Common Issues and Their Solutions

Let's go through common problems using a problem-cause-solution format.

Issue 1: The PAC file isn't being applied at all. Cause: incorrect file address or wrong MIME type on the server. Solution: open the PAC address directly in a browser, make sure the file is accessible, and set the MIME type to application/x-ns-proxy-autoconfig.

Issue 2: Changes to the PAC don't take effect. Cause: the file is being cached by the browser or system. Solution: restart the browser, reset proxy settings, and configure no-caching on the server.

Issue 3: The entire internet stopped working. Cause: a syntax error in the file or the proxy is down with no DIRECT fallback. Solution: check the console for errors and add DIRECT at the end of the returned string as a safety net.

Issue 4: Some subdomains go in the wrong direction. Cause: incorrect condition order where a general rule catches more specific ones. Solution: put more specific conditions above general ones.

Issue 5: The browser lags when opening pages. Cause: slow DNS lookups inside the PAC due to isInNet and dnsResolve with names. Solution: simplify the logic and use dnsDomainIs instead of resolving addresses.

Issue 6: The proxy requires a password, but there's nowhere to enter it. Cause: PAC doesn't support authentication. Solution: set up credential storage in the browser or system; PAC will only return the address.

Issue 7: The file breaks after copying from a document. Cause: typographic quotes instead of straight ones. Solution: replace all quotes with plain straight quotes in your code editor.

Issue 8: A local file path doesn't work in some browsers. Cause: modern browsers restrict loading PAC over the file protocol. Solution: host the file on a local web server and specify an HTTP address.

Additional Capabilities and Optimization

Once the basic setup works, you can improve your PAC file.

Speed Optimization

  • Put the most common conditions at the top of the function so the browser can decide faster.
  • Minimize calls to isInNet with domain names—they trigger DNS lookups.
  • Cache results in variables if the same value is used multiple times.
  • Convert the host to lowercase once at the start, not in every condition.

Load Balancing Between Proxies

You can distribute requests among multiple proxies based on hostname characters. It's a crude but functional balancing method without external tools. For example, domains starting with letters from the first half of the alphabet go to one proxy, and the rest to another.

Accounting for Device Location

Using myIpAddress and isInNet, you can create a single universal PAC file that behaves differently in the office and outside of it. On the office network, it uses a proxy; on other networks, it goes direct. This is handy for laptops.

Tip: One well-written universal PAC file is better than a dozen different ones. Build a network check using myIpAddress, and it will work correctly in any environment.

Commenting and Versioning

Add a comment at the top of the file with the date and version. Keep change history in a version control system. This saves you when you need to roll back to a working version.

FAQ: Frequently Asked Questions

Can I use one PAC file on all operating systems? Yes, PAC syntax is universal. The same file works on Windows, macOS, Linux, and all browsers. Only the ways to connect it differ.

Do I have to host the PAC file on a web server? No, a local file is enough for a single computer. But for multiple devices, network hosting is more convenient because it lets you update rules centrally.

Why does my PAC file open as text but doesn't get applied? Opening as text in a browser is normal for syntax checking. The application issue is usually caused by a wrong MIME type on the server or an error in the configuration address.

How often does the browser re-read the PAC file? Usually once at startup or when the network changes, then it caches it. That's why changes aren't visible immediately and you need to clear the cache or restart.

Can I specify a proxy with a login and password in a PAC file? No, PAC returns only an address and port. Authentication is handled separately by the browser or system, which prompts for credentials or pulls them from storage.

What does the function return if no conditions match? It depends on your code. Typically, you put return DIRECT or a return to the primary proxy at the end of the function. If the function doesn't return anything at all, behavior will be unpredictable.

Is it safe to enable automatic proxy detection in a café? No, on public networks auto-detection via WPAD is unsafe because someone could slip in a fake configuration file. Only enable it on trusted networks.

Does PAC work for programs other than browsers? Only for applications that read system proxy settings. Many command-line utilities and standalone programs ignore PAC and require their own configuration.

What if the proxy in PAC suddenly becomes unavailable? Add a backup proxy and DIRECT at the end of the returned string, separated by semicolons. The browser will then automatically switch to the fallback.

Can I combine WPAD and manual configuration? Technically yes, but it creates confusion. A manually configured PAC address usually takes priority over auto-detection. It's better to choose one method.

Conclusion: What's Next

Congratulations, you've completed the full journey of setting up automatic proxy configuration. Let's recap what you've accomplished.

You now understand the anatomy of a PAC file and the FindProxyForURL function. You explored the built-in functions shExpMatch, dnsDomainIs, isInNet, and myIpAddress with examples. You created three working PAC files for different scenarios and got a complete universal file to copy. You learned how to enable PAC across all major systems and browsers. You understood the WPAD mechanism and its risks on public networks. You mastered debugging and cache handling, and you learned the limitations of the technology.

What to do next. Start with a simple scenario and gradually add complexity as needed. Implement versioning for your PAC file so you can always roll back. If you manage a network, plan centralized distribution via a web server.

Where to go from here. Dive deeper into network protocols and how DNS works—this will deepen your understanding of routing. Master MIME types and cache headers on web servers. Get familiar with logging on your proxy server to see the real picture of passing traffic and fine-tune your rules.

Automatic proxy configuration via PAC is a powerful and flexible tool. Now you can use it with confidence and apply your knowledge in any situation. Happy configuring!