Wednesday, June 3, 2020

Select Browser when link is clicked


I use multiple browsers.  Chrome for Google stuff.  Edge for Microsoft Stuff etc. One browser is sandboxed using Sandboxie.

I want to be prompted every time I click a link in an external app, e.g. email so I can select which browser I want to use to view the website.

The key to this is a great piece of freeware called BrowserSelect by Borhan Hafez.  This works out what the available browsers are and allows you to choose one when a link is clicked.  It is a 64-bit program that installs to the user profile but can also be installed to C:\Program Files\BrowserSelect

BrowserSelect becomes the default "browser" for Windows.  Instead of opening a webpage it allows you to select the installed browser you want.  BrowserSelect determines what the available browsers are from registry keys that browsers use to identify themselves as such.

Portable browsers are browser versions that enable themselves to exist, self-contained, under one folder.  You should be able to run it from a USB key for example.  Some browser installation programs provide an option to install in portable mode.  Portable mode though, will not register the browser as a web browser option under Apps_Default Apps_ Web browser.  BrowserSelect will also not present the portable mode browser as an option because it refers to the same registry keys as windows to determine browser options.

Configuring a portable mode browser as an available web browser application option requires a set of additional registry keys to be created.  Christoph Kolbicz describes how to do that here  Note that any application you wanted to pass URLs to could be set up as a web browser using the additional keys.  Indeed this is what BrowserSelect is doing to take over the URL launch handling.

When a browser is configured as a web browser option, one important registry key defines what exe is actually the target of the call to the web browser.  In the case of Google Chrome it is
[HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\Google Chrome\shell\open\command]
@="\"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe\""

The HKCU\SOFTWARE\Clients\StartMenuInternet is also in use here so be aware that that is probably where you want the configuration to apply of a particular user.

The default key that points to the browser exe can only be a single string containing the path to the target browser exe.  Any variations will not work.  If you have a shortcut to launch a sandboxed browser, it is calling something like
"C:\Program Files\Sandboxie\Start.exe" /box:DefaultBox "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"

This command could NOT be used in the open command registry key.

A special exe would be required to execute the actual command we require.  It is possible to write a short python program and compile it into an exe.  The exe simply calls the above command and allows a URL argument to be included.

import os;
import sys;
# if a URL is supplied then use it as a parameter else launch without.
if len(sys.argv) > 1:
    # set variable for the argument
    URL = sys.argv[1]
    os.system(r'C:\Program" "Files\Sandboxie\Start.exe /box:DefaultBox C:\Program Files (x86)\Google\Chrome\Application\chrome.exe ' + URL)
else:
    os.system(r'C:\Program" "Files\Sandboxie\Start.exe /box:DefaultBox C:\Program Files (x86)\Google\Chrome\Application\chrome.exe')


Once the python code is compiled into an exe file, the path to this exe can be entered into the registry key enabling a sandboxed browser to be a launch option from within BrowserSelect.