Wednesday, October 24, 2012

tmpchrome

After my dissatisfaction with incognito mode in Chromium, I ended up writing this script, which I call 'tmpchrome' (despite it using Chromium).

My main issue is how all pages share a single incognito session; I'd rather have more control over how sessions are shared.

#!/usr/bin/env python2 from subprocess import Popen from sys import exit, argv from traceback import print_exc from os import rmdir from os.path import isdir from shutil import rmtree from tempfile import mkdtemp profile = mkdtemp() returncode = 1 p = None try: print 'Profile:', profile p = Popen(['chromium', '--user-data-dir=%s' % profile] + argv[1:]) p.wait() returncode = p.returncode except: if p is not None: p.kill() p.wait() returncode = p.returncode finally: try: rmtree(profile) if isdir(profile): rmdir(profile) except Exception: print_exc() finally: exit(returncode)

It isn't perfect, but is good enough for me.

No comments: