Throwaway Chrome Profile

TL;DR:

  • Create temporary Chrome instances at will.
  • Have separate Chrome browsers for home and work.
  • Separate your banking browser from everything else.
  • Isolate untrusted sites from your other online accounts.

This technique will allow you to have a fresh Chrome instance whenever you want. This allows you to troubleshoot without deleting cookies on your primary browser. It also lets you log into a site with multiple different accounts at the same time – for testing or so you can easily keep track of which single sign-on account you’re using.

For example, you may be signed into your personal and work Gmail accounts, and when you access sites like Google Calendar or the GCP Console, it may default to the wrong one. Or tech support tells you to delete all your cookies to troubleshoot your issue, but you don’t want to be logged out of your e-mail and everything else because of it.

Here’s the basis for this entire article:

--user-data-dir

Adding this single argument to the command line when opening Chrome specifies which profile to use.

For example:

linux

google-chrome --user-data-dir=/tmp/foo

This will use the /tmp/foo directory, and create it if it doesn’t already exist. By placing the directory in the /tmp folder, it will be deleted upon the next reboot.

For Mac users, the path to run Chrome is different:

OS X

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --user-data-dir=/tmp/foo

To avoid having to come up with a different directory name each time, you can generate a unique random value automatically each time.

bash

google-chrome --user-data-dir=$(mktemp -d)

This makes use of mktemp, which generates a random file in the /tmp directory. Adding the -d flag tells it to create a directory instead of a file. Wrapping the call in $() causes it to be executed first, and the generated directory name is passed to the google-chrome command.

Using a directory that’s not in your /tmp folder allows you to maintain multiple different Chrome instances. For example, use one just for your banking, and never visit social media or other untrusted sites on it. Have one for personal use, and one for work. The possibilities are endless.