A little story about brew, Firefox 47, Selenium and Capybara

I am quite a big fan of brew and brew cask. I switched from Linux to OSX less than a year ago and both of them gave me immediately the feel of being at home with a “standardized” way to handle the installation of applications on my system.

Yes, I know there are different conflicting opinions regarding how brew works under the hood like where it puts the installed applications, how it symlinks them and how it handles different app versions. Sincerely I never paid much attention to these discussions (my bad). For me it works quite well as it gives me the feel to have an organized and clean system.

Personally I also like to have my system steadily up-to-date and to achieve this goal I constantly use a brew update everything command that I built (or found?…sorry, I don’t remember XD) which automatically updates all the applications, “CLI and GUI based”, I’ve installed:

brew update && brew upgrade && brew cask list | xargs brew cask install --force && brew cleanup --force && brew cask cleanup --force

What it does is to update both brew and brew cask repositories, upgrade the installed applications (again, “CLI and GUI based”) and then do a cleanup by removing the old version of the applications.

Launching this command is quite disruptive considering that it forces the removal of the old version of the apps. So I do not feel like recommend it unless you’re able to handle some occasional problems.

A few days ago I ran indeed in one of these problems.

After launching the brew update everything command and monitoring its output inside the terminal I gladly noticed that among the GUI applications there was a major update of Firefox, i.e. 47.0 release.

Once the command finished I jumped back to a project of mine and launched a Capybara spec I was working on and…well…Firefox crashed pretty badly…

I knew that it was something related to Selenium and after a little bit of googling I ended up here. Yes I know, the issue doesn’t completely align with my setup (i.e. Windows 7 vs. OSX) but the problem was practically the same.

Among the issue comments this one caught my attention. Considering the Note in the comment I decided to briefly give Marionette a try but I wasn’t successful and so I rapidly jumped on downgrading Firefox.

I searched around for a tap that would allow me to handle different versions of Firefox but I was once again unsuccessful.

The next thing I did was to search a way to manually downgrade Firefox through brew cask. The first option I found was to manually modify the Firefox cask itself. By launching brew cask edit firefox I successfully opened the cask

cask 'firefox' do
  version '47.0'
  sha256 'e8e068a8f87126d1e252a51bbd0d4b20314fef8dc015c70c21468deaab9c4d9d'

  url "https://ftp.mozilla.org/pub/firefox/releases/#{version}/mac/en-US/Firefox%20#{version}.dmg"
  appcast "https://aus5.mozilla.org/update/3/Firefox/#{version}/0/Darwin_x86_64-gcc3-u-i386-x86_64/en-US/release/Darwin%2015.3.0/default/default/update.xml?force=1",
          checkpoint: '9cce3ec6844e54c07b7870461fdad111af0c4ce9161dd24c8425885b4f62d372'
  name 'Mozilla Firefox'
  homepage 'https://www.mozilla.org/en-US/firefox/'
  license :mpl

  auto_updates true

  app 'Firefox.app'

  zap delete: [
                '~/Library/Application Support/Firefox',

and then I modified the version

cask 'firefox' do
  version '46.0'

After that I tried to re-install Firefox with brew cask install --force firefox but I ended up with the following expected error:

==> Downloading https://ftp.mozilla.org/pub/firefox/releases/46.0/mac/en-US/Firefox%2046.0.dmg
######################################################################## 100.0%
==> Verifying checksum for Cask firefox
==> Note: running "brew update" may fix sha256 checksum errors
Error: sha256 mismatch
Expected: e8e068a8f87126d1e252a51bbd0d4b20314fef8dc015c70c21468deaab9c4d9d
Actual: f54b7e3e6bb330754ef4df7f96516fd7279a9fb01aad3db7fd2eadd25d8a279f
File: /Users/user/Library/Caches/Homebrew/firefox-46.0.dmg
To retry an incomplete download, remove the file above.

The problem was indeed related to the mismatched sha256.

After substituting the sha256 of the opened cask (i.e. the sha256 of the version 47.0 of Firefox) with the one reported by the error and launching brew cask install --force firefox I was finally able to get the old version of Firefox (i.e. 46.0) installed.

cask 'firefox' do
  version '46.0'
  sha256 'f54b7e3e6bb330754ef4df7f96516fd7279a9fb01aad3db7fd2eadd25d8a279f'

After that I removed the new version of Firefox (i.e. 47.0) from /usr/local/Caskroom/firefox/ and launched the problematic Capybara spec to check that the issue was really resolved and so it was! 😉

This quick and dirty fix needs however one last action: completely disable Firefox automatic updates!

By default (and this is ok if you’re using Firefox as your primary browser) the automatic updates are enabled and as soon as Firefox runs it tries to update to the latestes release. In my case it’s not needed. 😛

One last note. The modification of the local cask will be lost after the next brew update && brew upgrade but, once again, this is not a big deal in my case. ;P

All I need to do after the successive launches of the brew update everything command is to manually remove the new version of Firefox in /usr/local/Caskroom/firefox/.

I hope that this little adventure of mine can be useful to people that are encountering the same problem I’ve described in this brief post.

To the next time,

Leave a Reply