If you’re building Angular.JS apps, you’ll probably be using the excellent Karma test runner. I’ve been running into some troubles getting Google Chrome to work when using tmux on OSX. Here’s how to fix it.

 

The problem
I’m a fossil, I don’t use fancy new IDEs. My tools of trade, which have served me well for years now are tmux and vim. Tmux is like screen, but more powerful. It allows me to split my terminal into panes and have bash next to vim. Awesome.

Screen Shot 2013-07-04 at 12.00.23

Things go wrong when you start using the Karma test runner with Google Chrome.

You’ll be greeted by this guy:

Screen Shot 2013-07-04 at 11.58.35

 

The solution
Chrome crashes on any page, so this really doesn’t have anything to do with Karma (it just manifests itself there, because it launches a completely new Chrome instance). Turns out the daemon model of tmux is the problem here: tmux runs detached from the GUI, which means Chrome can’t find a screen to paint on.

 

There’s an easy fix!

  1. Get Homebrew, if you don’t already have it.
  2. brew install reattach-to-user-namespace
  3. Add the following line to your .tmux.conf file: set-option -g default-command "reattach-to-user-namespace -l bash"

 

Start a new tmux server and everything should work again.

 

Credit to http://robots.thoughtbot.com/post/19398560514/how-to-copy-and-paste-with-tmux-on-mac-os-x.

  • http://github.com/pascalprecht Pascal Precht

    Could you please update your blogpost title, since it is not a karma related problem that the browser crashes on copy and paste.

    • http://www.savanne.be/ Ruben

      What’s wrong with the title?

      You are correct: this is not a Karma bug, but the issue does manifest itself there (and pretty much nowhere else). My goal is not to lay blame: it’s to make sure that other people that get bitten by this problem find a solution quickly.

  • http://www.soulcutter.com Soulcutter

    Thanks! This was really useful to me. I share my tmux conf between OSX and linux, so I had to tweak your solution slightly to allow for systems that did not have a `reattach-to-user-namespace` command.
    https://github.com/soulcutter/dotfiles/commit/e0e7683c7d8727baf116943ab559d76d2f057b9d

  • http://marjoripomarole.me Marjori Pomarole

    You are awesome thank you :)

  • http://jbinto.ca/ Jesse Buchanan

    Thanks, found this searching “karma chrome ah snap”.