Unset Google Chrome as default browser on Ubuntu

Update: After further investigation, I found is the problem is in google-chrome application not in Chromium-browser. My Mistake!

Dietrich Ayala brought this problem to my attention. For some reason google-chrome browser constantly makes itself the default browser on Ubuntu 10.10 and later versions. This is annoying when you are testing Firefox Nightly Ubuntu builds. You can choose to remove the google-chrome, but that is not a solution.

First, I tried to reproduce this problem on multiple Ubuntu machines. To reproduce this problem, installed Firefox nightly using Firefox Nightly PPA. Remove any other browsers expect google-chrome.


It took very long time to find the solution to this problem. The chromium-browser package adds /usr/local/share/applications/mimeinfo.cache which supersedes the default system application settings. The solution is edit this file and make it read-only using chattr command.


$ sudo nano /usr/local/share/applications/mimeinfo.cache 
[MIME Cache]
application/earthviewer=google-earth.desktop;
application/keyhole=google-earth.desktop;
application/vnd.google-earth.kml+xml=google-earth.desktop;
application/vnd.google-earth.kmz=google-earth.desktop;
application/xhtml_xml=google-chrome.desktop;
text/html=google-chrome.desktop;
text/xml=google-chrome.desktop;
x-scheme-handler/ftp=google-chrome.desktop;
x-scheme-handler/http=google-chrome.desktop;
x-scheme-handler/https=google-chrome.desktop;

#Remove all the google-chrome entries, like this.
[MIME Cache]
application/earthviewer=google-earth.desktop;
application/keyhole=google-earth.desktop;
application/vnd.google-earth.kml+xml=google-earth.desktop;
application/vnd.google-earth.kmz=google-earth.desktop;

# Make it read-only even for super-user
sudo chattr +i /usr/local/share/applications/mimeinfo.cache





After making these changes. Open Firefox Nightly and make it the default browser. Now this system setting will remain unchanged.


7 comments:

  1. Where do you get your chromium-browser package? Because the one from Ubuntu doesn't contain that file in /usr/local/ you mention:
    http://packages.ubuntu.com/precise/amd64/chromium-browser/filelist

    ReplyDelete
  2. On my machine this file is located at /usr/share/applications

    ReplyDelete
  3. My best guess: this might be xdg utilities bug.

    ReplyDelete
  4. Et voila! We now have the first example of a 3rd-party package abusing the access granted to it in order to try to bring about Windows-style fights over file associations.

    I suppose this is one reason to like Gentoo Linux. (All ebuilds are set up in a sandbox and the sandbox aborts the process if something other than Portage's "copy build to live filesystem" phase tries to write outside the build prefix. It does occasionally cause unintended failures, like when a Python ebuild tries to update cached bytecode for other packages, but. in general, it works well if you can stand waiting for your entire system to be built from source.)

    Any idea why you had to mark /usr/local/share/applications/mimeinfo.cache immutable? The XDG spec says that it should be overridden by the per-user config stored at ~/.local/share/applications/mimeinfo.cache

    ReplyDelete
    Replies
    1. Beats me! That why I wrote this blog post so that someone out there will figure this out.

      Delete
  5. An application making itself the default without asking sounds quite a bit like malware to me, what malicious purpose has this "google-chrome" thingy? :p

    ReplyDelete
    Replies
    1. Looks more like a bug to me:

      Can you spot the problem?

      # We include some xdg utilities next to the binary, and we want to prefer them
      # over the system versions when we know the system versions are very old. We
      # detect whether the system xdg utilities are sufficiently new to be likely to
      # work for us by looking for xdg-settings. If we find it, we leave $PATH alone,
      # so that the system xdg utilities (including any distro patches) will be used.
      if ! which xdg-settings &> /dev/null; then
      # Old xdg utilities. Prepend $HERE to $PATH to use ours instead.
      export PATH="$HERE:$PATH"
      else
      # Use system xdg utilities. But first create mimeapps.list if it doesn't
      # exist; some systems have bugs in xdg-mime that make it fail without it.
      xdg_app_dir="${XDG_DATA_HOME:-$HOME/.local/share/applications}"
      mkdir -p "$xdg_app_dir"
      [ -f "$xdg_app_dir/mimeapps.list" ] || touch "$xdg_app_dir/mimeapps.list"
      fi

      Source: http://src.chromium.org/svn/trunk/deps/reference_builds/chrome_linux/chrome-wrapper

      Delete

You can leave a comment here using your Google account, OpenID or as an anonymous user.