How to create a Chrome profile programmatically?

20.3k views Asked by At

Development, testing, staging environments are controlled via different proxy servers in my setup. I want to script creation of multiple Chrome profiles (sometimes called "user" or "person") and connect to a different proxy server for each of them. Finally I want to share this script with colleagues so that they have access to the exactly same setup.

The latter can be done via scripted installation of extensions such as Falcon Proxy or Proxy Helper to the Chrome profile. I would like to know how to script creation of the different profiles.

A profile is a folder inside ~/.config/google-chrome (Linux, ~/Library/Application Support/Google/Chrome (Mac OS X) and %USERPROFILE%\AppData\Local\Google\Chrome\User Data (Windows). But how to create and initialize one? Where do I register the new profile?

3

There are 3 answers

3
turbo On BEST ANSWER

Creating a user

The following example applies to Windows, but the basic procedure should be the same.

First, change to the UserData folder in your Chrome installation:

cd "%APPDATA%\..\Local\Google\Chrome\User Data"

This method will copy the current user as a template for the new user. If the new user should be blank, you need to delete (CTRL + SHIFT + DEL the current browser data).

Now create a new user:

mkdir NewUser && copy Default NewUser

Change your directory to the chrome installation:

cd "C:\Program Files (x86)\Google\Chrome\Application"

Factory-Reset all user parameters:

chrome.exe --user-data-dir="..\User Data\NewUser" -first-run

where --user-data-dir is the path (full or relative) to the previously created NewUser directory.

Running as NewUser

To run chrome again using this profile, simply run chrome without the -first-run flag.

0
Alan Tam On

From this documentation, I finally found a way to create a user/person, rather than a separate profile. The difference is especially important in Mac OS X since different profiles can be opened concurrently using the same Chrome process.

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --args --profile-directory="StagingEnv" --first-run

The only unfortunate fact is that this new person doesn't inherit the name from the profile directory. Instead, it is always called Person X where X is an increment number.

I need to go to the Local State file to change it.

grep -o '"StagingEnv":{[^}]*}' ~/Library/Application\ Support/Google/Chrome/Local\ State

"StagingEnv":{"active_time":1437709453.172762,"avatar_icon":"chrome://theme/IDR_PROFILE_AVATAR_6","background_apps":false,"is_ephemeral":false,"is_omitted_from_profile_list":false,"is_using_default_avatar":true,"is_using_default_name":true,"managed_user_id":"","name":"<b>Person 3</b>","user_name":""}

This file is overridden when Chrome quits, so I need to kill Chrome, change the file and run Chrome again.

1
Mjachowdhury On

I think the easiest way to create multiple chrome profile is

  • On your computer, open Chrome.
  • At the top right, click Profile.
  • Click Manage people.
  • Click Add person.
  • Choose a name and a photo/picture.
  • Select Create a short cut on the desktop.
  • Click Save. A new window will open and ask you to turn on sync which is optional.

By this, each chrome profile will be created and you can check on C:\Users\youname\AppData\Local\Google\Chrome\User Data.