How to force browsers to use proxy server for specific domains such as google.com or facebook.com

A generic solution to this problem is to use a custom proxy auto-configuration (PAC) file. In this file you can have arbitrary logic to select the proxy - including a white list of domains.

Here is how to do it:

  • Create a text file anywhere in your local file system, e.g. C:\ProxyAutoConfiguration.js
  • Paste the following content into that file

    function FindProxyForURL(url, host) {
    
        // use proxy for specific domains
        if (shExpMatch(host, "*.google.com|*.facebook.com"))
            return "PROXY yourproxy:8080";
    
        // by default use no proxy
        return "DIRECT";
    }
    
  • Configure the file URL of this file (e.g. file:///C:/ProxyAutoConfiguration.js) as proxy auto-configuration script in your system or browser. In IE, this configuration is here: Internet Options > Connections > LAN settings > Use automatic configuration script.

For more information on the proxy auto-configuration file format, see for example this web page: https://findproxyforurl.com/example-pac-file/