Drawing a Blank
by Mike Fulcher

BrowserStack tunnel from the command line
Friday, September 20, 2013

I use BrowserStack a lot. Mostly I use it for in-development projects which are served through a local web server, so I frequently find myself going through the steps to create a web tunnel. This can be achieved through BrowserStack’s web interface but for convenience the tunnel can also be set up from the command line using java and BrowserStack’s special BrowserStackTunnel.jar file. Unfortunately, the command is quite verbose:

java -jar BrowserStackTunnel.jar <key> <host>,<port>,<ssl flag>

So to make my life a little easier, I started using this simple bash function:

function browserstack() {
  local port
  if [ $1 ]; then port=$1; else port=4000; fi
  java -jar ~/.BrowserStackTunnel.jar <key> localhost,$port,0
}

Now I can simply run browserstack in bash to set up a tunnel which defaults to localhost:4000. If my local server is running on a different port, I can pass it as an argument, eg browserstack 3000. Note that I’ve moved the BrowserStackTunnel.jar file to my home directory and renamed it with a leading . to make it hidden from Finder. Wherever you’ve placed your own jar file, just make sure to update the function to point to the correct location.