For a long time, in the olden days, I ran Xubuntu – mainly because I loved the simplicity of the desktop (and also because it was a lot lighter on my machine, a Thinkpad T40, than GNOME. And I just have no love for KDE). Then some changes were made to the menu system (or the way to edit it) which annoyed the hell out of me – that combined with a new, more powerful machine, I decided to switch to GNOME, which I’ve been running for a couple of years.

geek-miousik-portal-still-alive-L-1-300x206.jpg

Recently two things have happened

  • Ubuntu decided to switch to Unity as the default graphical environment
  • GNOME released 3.0 and announced that GNOME 2.x will no longer be actively developed (bug fixes only)

While both Unity and gnome-shell look nice and definitely have their place (I’m guessing they will both appeal much more to new users than GNOME2 ever did as well as work a lot better on netbooks and tablets) they both felt like they were hindering me in actually using my computer. Enter Xubuntu. Xfce felt like home :)

Now that I’m done rambling, let’ get down to business.

Google Chrome does not support Xfce, in the sense that it normally uses the proxy settings from GNOME or KDE; when running neither the proxy settings are simply not available. There are some hacks available to utilize the GNOME preferences infrastructure, but it seems cumbersome.

Chrome also support configuring proxy settings on the command line, in a rather neat way actually

  • –proxy-server=”foopy:99″
    Use the HTTP proxy “foopy:99” to load all URLs.
  • –proxy-server=”https=proxy1:80;http=socks4://baz:1080″
    Load https://* URLs using the HTTP proxy “proxy1:80″. And load http://* URLs using the SOCKS v4 proxy baz:1080”.

neat indeed, but not very efficient if you have a lot of rules – Normally one could use Proxy Switchy! but since it relies on the proxy configuration in Chrome it does not work in Xfce.

Proxy Auto Config to the rescue.

A PAC file, in essence, is a Javascript which returns what proxy to use for a given URL or IP (if any).

An example

function FindProxyForURL(url,host)
{

        var resolved_ip = dnsResolve(host);

        if (isPlainHostName(host))
        return "DIRECT";
        else if (host == "server1.my.corp" ||
                host == "server2.my.corp")
        return "PROXY proxy.my.corp:8080";
        else if (isInNet(resolved_ip, "192.168.1.0", "255.255.255.0") ||
                        isInNet(resolved_ip, "192.168.4.0", "255.255.255.0")
                        )
        return "DIRECT";
        else
        return "PROXY localhost:18080";
}

I use Dropbox to keep the proxy config in sync between machines.

To use the proxy pac, I created a copy of the Chrome launcher

$ cp /usr/share/applications/google-chrome.desktop ~/.local/share/applications

Now, locate all lines containing

Exec=/opt/google/chrome/google-chrome

and change it to

Exec=/opt/google/chrome/google-chrome --proxy-pac-url=file:///path/to/proxy.pac %U

or

Exec=/opt/google/chrome/google-chrome --proxy-server="https=proxy1:80;http=socks4://baz:1080 %U

That’s it. The next time you launch Google Chrome, it will use the proxy settings configured in the application shortcut.