43

I use multiple Google Chrome profiles, each logged in with a different account.

What I would like to be able to do is if I open a URL in an external app (such as Mail), it would open the correct profile based on the domain.

https://personal.com would be opened in profile "Personal" https://company.com would be opened in profile "Business"

By default, Chrome uses the last opened profile.

vvondra
  • 656

10 Answers10

9

I found it! months of search and I finally found something useful.

https://chromium.googlesource.com/chromium/src/+/refs/heads/main/chrome/common/chrome_switches.cc

The flag I was looking for is:

// Like kProfileDirectory, but selects the profile by email address. If the
// email is not found in any existing profile, this switch has no effect. If
// both kProfileDirectory and kProfileUserName are specified, kProfileDirectory
// takes priority.
const char kProfileEmail[] = "profile-email";

google-chrome --profile-email=user@domain.com
stimur
  • 211
6

Google provides what you need. However, this is a part of Enterprise. You can setup what the link and how it does work in GPE. The link: Configure which browsers to open with LBS . I recommend use something like google.exe --app=http://example.com --user-data-dir:/home/example/.config/chrome/ for a policy.

red
  • 61
3

I achieved something similar with the chrome extension I built, CopyTabs (https://chrome.google.com/webstore/detail/copytabs/obkbjogekcjalnaebheboejhfkamadkg). It is able to open current tabs, selected tabs or windows, in the current chrome user profile, another chrome user profile or another browser entirely.

It doesn't do exactly what's asked as in having https://personal.com open in profile "Personal" and https://company.com open in profile "Business", but if https://personal.com opens in profile "Business" it allows you to move it to profile "Personal".

I made use of chrome.exe --profile-directory="profileName" to open URLs in a selected profile from a handler that runs on the user's machine. The command makes use of the internal names of the profiles, for example --profile-directory="Profile1" instead of --profile-directory="My Name As Profile".

Hope it's useful.

Mokubai
  • 95,412
Keisha W
  • 141
3

On Windows 11 I was able to accomplish this by opening regedit and finding the following key: Computer\HKEY_CLASSES_ROOT\ChromeHTML\shell\open\command.

Default was set to this: "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --single-argument %1

I changed it to include the --profile-directory switch similar to this to open the default profile:

"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --profile-directory="Default" --single-argument %1
Toto
  • 19,304
jrh2004
  • 31
  • 1
2

I believe that Account Surfer that I've made should be able to do the things that you're looking for. Here's an overview from Windows store:

Quickly switch between accounts and browsers with Account Surfer.

Decide what account or browser to use when opening the link. Read more: https://dospolov.com/posts/handle-chrome-profiles-with-account-surfer https://trello.com/b/QOLCmlg3/account-surfer-roadmap

enter image description here

msdos
  • 121
1

Do NOT use an extension for this if you know how to use a cli or create a shortcut in windows. Chrome / Chromium has already 2 options:

Option 1

google-chrome --profile-directory="Profile 1"

Option 2

google-chrome --profile-email="mail@example.com"

I prefer the first option, since this also works with local profiles. It is a bit tricky to find the correct profile name. Chances are high that you first created profile is called Default and the following Profile 1, Profile 2 and so on. It is stored in the chrome user config directory, which depends on the OS you are using. For Linux it is ~/.config/chrome/Profile 1 for example. If the profile directory does not exist yet, it will just create a new profile which is kinda awesome.

1

You didn't specify your operating system or version of Chrome, but for macOS you can use Finiky at https://github.com/johnste/finicky. It works by running as the default browser, and it will open links in the browser / profile combination that you specify in it's configuration.

majorgear
  • 131
0

Another approach is to manipulate Chrome's Local State file.

DISCLAIMER - This may not be safe while Chrome is running, make a backup of the file first, etc.

If you read and JSON-parse this file:

%LOCALAPPDATA%\Google\Chrome\User Data\Local State

Then manipulate the value of

$jsonData.profile.last_used

then dump that back to disk at the same location, it alters this behavior. That is, this appears to be where Chrome stores data on the last profile used.

That said, I prefer @jrh2004's answer, just thought this info might be useful to share.

0

I see answers for some of the MacOS solutions, for Windows I use https://github.com/mortenn/BrowserPicker as an installed app - it is set to the default browser so it works from all apps.

The UI is a little clunky but what I like about it is that it can use a prefix (such as the domain name) or regex to 'catch' a partial URL. If your company uses mail filters such as mimecast which redirects all email links to a mimecast URL then the regex allows it to pick up the part of the URL that references that domain.

An example rule set up using regex which opens all github links (which mimecast has redirected) from my email client in a specific chrome profile:

|regex|https:\/\/protect-us.mimecast.com\/s\/[^\/]+?domain=github.com

Example browserPicker defaults using prefixes and regex

0

I lack the reputation to comment on jrh2004's existing answer, but wanted to add that a recent update to Chrome added a ChromePDF class (in addition to the ChromeHTML class mentioned in that post), so that solution would need to be applied there for opening PDFs.