How to create a Chrome profile programmatically? - google-chrome

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?

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.

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.

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.

Related

View/export localstorage locally in Chrome for a domain that has been 301 redirected?

A site I use has suddenly moved to a new domain. The old site 301 redirects to the new site. All my settings for the site have been lost, because they are stored in localstorage on the old domain.
Normally, if I need to view everything in localstorage, I go to the site and open developer tools, and there it is.
However, if I try that now, I can only see the new empty localstorage on the new origin, which does not help me at all.
How do I view the localstorage of a site that I cannot load?
I tried interrupting the redirect by:
Disabling redirects in Chrome settings for this domain (no effect)
Hitting ESC while it loads (failed after repeated attempts)
Writing a Tampermonkey script (never runs)
window.addEventListener("beforeunload", function() { debugger; }, false) (stops, but devtools localstorage never shows old domain, even if I step through)
At no point am I stopped on the previous domain, allowing me to view the associated localstorage.
But I can see that it still exists if I go to Chrome's settings | All cookies and site data, and filter for the domain. But, unlike cookies (whose contents are viewable from this settings page), the only things localstorage tells me here are the origin, the size on disk, and the last modified date. Not the contents. But this IS something stored on my computer somehow, and I should be able to access it, right?
How do I browse the contents of localstorage locally, on my local machine?
Is there a way to redirect dev tools to a specific domain?
Is there a way of "tricking" the browser into thinking I'm on a specific domain, so that I can then open dev tools and view the localstorage like normal?
Or is there an obvious way to browse localstorage that I'm just overlooking?
Expanding on wOxxOm's solution:
For context, I'm on Ubuntu 22.04 with Python3 and mkcert already installed.
Edit the hosts file
sudo gedit /etc/hosts
I add a new line at the bottom: 127.0.0.1 (the domain I'm trying to recover)
Now, I don't have anything running on port 80, so for a regular website I could have run:
sudo python3 -m http.server 80
(sudo because Ubuntu will complain that I don't have permissions to use that port otherwise)
But here's the twist: Nothing showed up in localstorage when I did that. Why? Because the original site wasn't on http, it was on https.
Move to a folder you can leave files in.
I moved to my development folder
Generate local certificate
mkcert (target domain)
mkcert -install
This makes a couple files in this folder, whateverdomain.pem and whateverdomain-key.pem.
Write a small python wrapper (from this StackOverflow)
import http.server, ssl
server_address = ('localhost', 443)
httpd = http.server.HTTPServer(server_address, http.server.SimpleHTTPRequestHandler)
httpd.socket = ssl.wrap_socket(httpd.socket,
server_side=True,
certfile='whatever.pem',
keyfile='whatever-key.pem',
ssl_version=ssl.PROTOCOL_TLS)
httpd.serve_forever()
Server address is 443 for https, keyfile is included with certfile.
Run the new script
sudo python3 simpleserver.py
Sudo again, because of using a main port.
Open the target domain in the browser.
Open dev tools. Right-click on the page and choose "Inspect" or use the keyboard shortcut ctrl-shift-i
Go to the Application tab.
Success! My localstorage is finally viewable. From here I was able to copy out the values I needed.
We're done, so clean up:
Stop python script.
Finally, re-edit /etc/hosts and remove or comment out the redirect line.
Was there a simpler way I could have run https? Maybe. But this wasn't difficult to set up, and I did recover my inaccessible localstorage, and that's the important thing.

SSLKEYLOGFILE environment variable doesn't populate any text file

My operating system is Windows 10 64 bits. I use the latest versions of Firefox and Chrome.
I want to save the pre-master keys in order to use them with WireShark.
For this, I have found many tutorials that all recommend using the SSLKEYLOGFILE environment variable.
However, no matter the path I put in this variable, no file is being created by Firefox (normal and developer editions) or Chrome. This is true even when I restart those browsers or the operating system. This is also true when I clear the cache on the browsers.
I found an alternative way of setting the SSLKEYLOGFILE variable with Chrome by launching the browser with the following argument:
--ssl-key-log-file=PATH
And while this argument does create a log file, it is never populated. It remains completely empty.
What makes this problem even more annoying is that I don't know if there's any debug log that would at least let me know what's happening.
Anyone have ideas on how to solve this issue?
Verified in both Chrome and Firefox
Windows 10 64bit [Version 10.0.17763.379]
I would not use the --ssl-key-log-file flag with Chrome. In my testing, it does not have an effect.
Steps to get SSL keylog file
Change your directory to one that you or your programs have access to. I am using the Desktop folder.
C:\> cd $HOME\Desktop
Set the SSLKEYLOGFILE variable. This sets it for the user (HKCU). To set it for the machine (HKLM), add the /m flag to the end of the command.
PS C:\Users\rj\Desktop> SetX SSLKEYLOGFILE "$(get-location)\ssl.log"
Verify that the variable has been set in a separate powershell window (SetX does not apply to the current window).
PS C:\Users\rj\Desktop> Get-ChildItem ENV: | findstr SSLKEYLOGFILE
SSLKEYLOGFILE C:\Users\rj\Desktop\ssl.log
You can also verify that SSLKEYLOGFILE is a user variable by going to the Control Panel > System and Security > System > Advanced System Settings > Advanced tab > Environment Variables > User Variables. You should see a listing like the powershell example where the value is a directory.
Open Chrome/Firefox and go to an https website like https://stackoverflow.com.
You should see an ssl.log show up on your desktop.
Image of end result
Further Reading
2018-12-07, F5, Decrypting SSL traffic: Great article on doing the above, but cross-platform
2019-03-18, Mozilla, NSS Key Log Format
: The SSLKEYLOGFILE format
2018-08-17, Wireshark Bugzilla, Add TLS 1.3 support: Has good test pcap/SSLKEYLOGFILE contents for TLS1.3 (See Comment 83)
You mentioned that you are using Wireshark. If you using it to export a file from a TLS-encrypted stream in a capture, this article may help you.
One thing I ran into is: Chrome doesn't always fully close when you close the window. Sometimes it stays open in the background. Use the Windows Process Explorer to list all the processes and make cure Chrome is closed. Also, after restarting Chrome, you can double click on it in Process Explorer and select the Environment tab to list all the variables set in it's environment. Make sure SSLKEYLOGFILE is shown in that list. Then Chrome will be sending keys to the specified file.
First off all the problem is that the browsers are protected better and that flaw is patched, thats why you cant capture no ssl. I dont know the details. But chrome with --no-sandbox(linux) option on ,when running will enable you to capture ssl/tls key without any issues from the first try, so you can play with decription of packets. Never tried on windows btw..
This worked for me...
set the SSKEYLOG env: variable as normal in Linux.
just point it to your pefererd save location of the sslkey.log
windows system/advance/env vars/user variables.
add SSLKEYLOGfile with the path to your preferred save location C:/user/sslkey.log
close and your done here.
NSS_ALLOW_SSLKEYLOG=1 is what's missing from the Booleans in Firefox's advanced options.
its been also removed from the general release but is still in the dev ops version. just not listed.
download and install the dev ops version of Firefox
open a terminal start it from its exe if on Linux.
windows just open it from the icon.
go to the about:config
create a new Boolean with NSS_ALLOW_SSLKEYLOG=1 and set it to true.
quit
now create a new symbolic/icon link to the new dev version fire fox version
when you run Firefox from the terminal in Linux the sskeylog should be created and start populating.
run it from the task bar icon in Linux and it doesn't make or update the keylog (just in case you dont want it populating every time you open the browser).
in windows, you will have to disable the env var or it will keep populating every time you open any browser that supports sslkey logging.
on that note opera and vivaldi should work with no changes to the advanced option.
lastly.. open wireshark go to
edit/preferences/protocols/tls
and put the path to the sslkey.log in the pre master secret log box.
click ok.
close everything..
start Wireshark
start your browser (from terminal in linux).
you should start seeing sslkeylog start populating and see extra options for decryption in the tabs of Wireshark.
have fun :)
1st solution:
Restart Chrome
2nd solution:
Use Firefox

Can't access internet through Google chrome

I can't access internet through my chrome browser,but can access net through all other browsers in the same system. Tried uninstalling and installing chrome but of no use...Is there any solution for this ?
this is the issue....
Since you have already uninstalled it let's start here:
Step 1: Enable the Hidden Files View.
To do that go to:
Start > Control Panel > Folder Options.
Click the View tab.
Click/Check the Show hidden files, folders, and drives option.
Uncheck the Hide protected operating system files option.
Press OK.
Step 2: Delete any Chrome or Google folders from your computer.
Navigate to the following locations and delete the Chrome folder(s). You can also choose to rename them. I would also search you computer for any google or chrome folder to make sure.
C:\Users\<YourUserName>\AppData\Local\Google\Chrome
C:\Program Files\Google\Chrome
Step 3: Schedule a check disk
To do this use:
chkdsk c: /r
where 'c' is the drive with chrome installed. You can add other drives as well just in case you had multiple installations. To do this basically replace c with the drive letter.
Step 5: Reboot PC and reinstall chrome.
Optional Step: if the above still fails. Download CCleaner. Restart in safe mode with networking. Repeat the above steps but run CCleaner as the final step.
What you need to do is check if there is a proxy turned on system-wide or even in chrome, turn it off. type that "chrome://settings" in your URL bar of chrome: and search for proxy

How to disable Google Chrome extension autoupdate

How do I disable Google Chrome extension autoupdate?
Solutions I've found for this:
1. Disabling a concrete extension update
That's what I wanted!
You can do this by editing the extension's manifest.json file:
On Windows: C:\Users\<USERNAME>\AppData\Local\Google\Chrome\User Data\Default\Extensions\<EXTENSION-ID>\<VERSION>\manifest.json (find out the extension's ID by enabling Developer Mode in the extension settings page)
On MacOS: Open /Users/USERNAME/Library/Application Support/Google/Chrome/Default/Extensions/EXTENSION-ID/VERSION/manifest.json in a text editor.
On Ubuntu for Chromium: ${HOME}/.config/chromium/Default/Preferences
In this file, set the "update_url" property to something invalid like "https://localhost" for example. For the given url, it makes auto-updating that extension as simply impossible.
Source: https://productforums.google.com/d/msg/chrome/l3zOZeO-5-M/Y7VaR0KCWNIJ
2. Disabling all Google Chrome extension updates
For any OS: Just type chrome://plugins/ at address bar and turn Google Update plugin off. Source: How to disable Google Chrome auto update?
For Windows OS: Set Registry values:
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google\Update]
"AutoUpdateCheckPeriodMinutes"=dword:00000000
"UpdateDefault"=dword:00000000
Source: Making Google Chrome leave itself alone
If the chrome extension is on Github (which many if not most of them are), you can simply:
(1.) clone the Github repo,
(2.) reset the head to the version that you want, and
(3.) enable Developer Mode at chrome://extensions/
(4.) select the "Load unpacked" option from chrome://extensions/, and then select the folder enclosing the source code for the extension.
I recently used this technique to downgrade my version of Reddit Link Opener, which no longer supports users who have opted out of using that site's redesign. This worked for me on MacOS, but should work on all platforms.
If the extension is loaded as an unpacked extension (in the manner described above), it will NOT auto-update to a newer version.
Disabling update for a specific extension:
This can be achieved with the system policies, (more details here)
For Linux :
Get the installed extensions list (IDs), this can be found with ls -l ~/.config/google-chrome/Default/Extensions or chrome://extensions
Create the necessary directory if not present mkdir -p /etc/opt/chrome/policies/managed (with root)
Create the needed file policies file touch /etc/opt/chrome/policies/managed/google-chrome.json
Edit that file with the code bellow
open the page chrome://policy/ and reload the policies
{
"ExtensionSettings": {
"ghijklmnopabcdefghijklmnopabcdef": {
"update_url": "https://127.0.0.1/update_url",
"override_update_url": true
},
"YOUR-EXTENSION-ID-LIKE-THE-PREVIOUS-EXAMPLE": {
"update_url": "https://127.0.0.1/update_url",
"override_update_url": true
}
}
}
Note: this can not be applied widely to all extensions in a single rule and also for each newly installed extension the file need to be updated
Hi all those solitions for me have one disadvantage is that all extensions have no updates, I needed to stop only for one extension in this case and wanted al the other to keep making updates.
I think I found the solutuion for windows
Go to
C:\Users\YOUR_NAME_HERE\AppData\Local\Google\Chrome\User Data\Default\Extensions\YOUR_FOLDER APP HERE\
In that folder app click in properties and select read only an aplly that to all subfolders and files... for now for me solved the problem !!!
Regards xichas
this is a complementary answer to the accepted one https://stackoverflow.com/a/27657703/1422630 , allowing disable all at once on chromium
this is also only for linux (may be run on windows thru cygwin tho, not tested..)
this script will
backup the prefs file,
modify it,
if didnt succeed will output "FAILED"
show the differences using meld if installed
#!/bin/bash
set -ue
strPref="$HOME/.config/chromium/Default/Preferences"
cat "$strPref" |egrep "\"update_url[^,]*," -o |sort -u
read -p "existing unique urls above..." -n 1
strBkp="${strPref}.`date +"%Y%m%d%H%M%S"`.bkp"
if cp -v "$strPref" "$strBkp";then
strUpdUrl="clients2.google.com/service/update2/crx" #change this if needed #TODO should match any URL...
sed -i -r "s#(update_url\":\"https{,1}://)(${strUpdUrl})#\1127.0.0.1#g" "$strPref"
if grep "$strUpdUrl" "$strPref";then echo FAILED >&2;exit 1;fi
cmdDiff=colordiff
if which meld;then cmdDiff=meld;fi
#$cmdDiff <(cat "$strPref" |egrep "\"update_url[^,]*," -o) <(cat "$strBkp" |egrep "\"update_url[^,]*," -o)
$cmdDiff <(cat "$strPref" |sed -r 's#","#",\n"#g') <(cat "$strBkp" |sed -r 's#","#",\n"#g')
fi
tested on chromium: Version 63.0.3239.84 (Official Build) Built on Ubuntu , running on Ubuntu 16.04 (64-bit)
obs.: that script also works for google-chrome, just change the preferences file path
After updating Google Chrome to v60, no solution found on the Internet has helped me
So i just blocked IP addresses, used for updating, by doing following steps:
Opened Chrome with blank browser tab
Waited, until extension
autoupdate begins, by looking on to network tab in Resource
Monitor
Wrote out all the IP addresses with high download rate. My IP address list was:
64.233.161.94
64.233.161.102
64.233.163.95
74.125.238.132
108.177.14.138
173.194.73.132
173.194.222.102
216.58.209.110
216.58.209.97
173.194.222.99
173.194.32.227
173.194.113.172
173.194.32.224
195.216.237.77
74.125.232.170
143.215.130.61
74.125.238.147
173.194.122.137
173.194.44.66
173.194.44.67
173.194.44.95
173.194.122.136
74.125.232.183
74.125.232.171
Created outbound rule for chrome.exe in Windows Firewall and added listed IP addresses to blocklist
After I enabled this rule, chrome was unable to update my extensions.
Just (re)install the extension via Load unpacked.
Let's suppose "Roboform Password Manager" extension version 8.6.5.5 dropped some important functionality, so you want to keep version 8.6.2.2 installed.
Go to chrome://extensions/
Enable Developer mode
Get the required version of the plugin:
If Chrome still got the version you need:
Utilize Pack extension button on the plugin details page.
Just copy the extension folder, e.g. C:\Users\%USERNAME%\AppData\Local\Google\Chrome\User Data\Default\Extensions\pnlccmojcmeohlpggmfnbbiapkmbliob. The extension id is visible in the url bar, on the plugin details page, e.g. chrome://extensions/?id=pnlccmojcmeohlpggmfnbbiapkmbliob.
If the version you need was overwritten already:
Get appropriate ".crx" from some extensions archive
Look for ".crx" in "C:\Program Files\..." (applications/installers sometimes bundle original ".crx" versions, unaffected by any updates)
Unzip (e.g. with 7-zip) your ".crx" (or paste the extension folder contents) to a non-temporary folder - you would have to keep those files in place until you uninstall the extension.
Click Load unpacked, select that folder.
If you just drag&drop the ".crx" file, Chrome extension details would show Source=Chrome Web Store, and it would get updated as soon as you click Update extensions now. But for an unpacked extension, you get a special "Unpacked extension" overlay icon, Source=Unpacked extension and it won't get updated.
Just tested on Chrome 79.0.3945.88 (64-bit), Windows.
Now, Chrome shows "Disable developer mode extensions" popup on each startup. Personally, I just manually dismiss them each time. I do not re-start Chrome too often.

Prompted by "Google Chrome didn't shut down correctly.... "

Using Google Chrome 38.0.2125.111 m in a Windows 7 environment. It is launched by a batch file & set to go to a specific (internal) URL. The Windows environment is going to be locked down, permitting only a handful of options available to the user.
Chrome is being used because IE will be accessing a different site. Without going into boring detail, using both sites on a single browser allowed a user to access an account that wasn't theirs. Both browsers will be launched using one of two batch files. The Chrome batch file supplies the username & password to bypass a login screen on that application.
To keep from opening multiple windows in Chrome, the following batch file is used:
taskkill /f /t /im chrome.exe > NUL
ping -n 3 127.0.0.1 > NUL
START /max chrome "http://myinternalwebsite?uid=x&pwd=y"
Taskkill is used to close chrome (/f = force /t = terminates process & any child ones /im = image name).
If the Chrome session is closed (using the X at the upper right corner of the screen), the batch file works fine. However, if there is already a chrome instance running, we get the yellow bar with the frowning folder & a message saying:
Google Chrome didn't shut down correctly. To reopen the pages you had
open, click Restore.
I have tried several command line options when launching Google Chrome, but none will keep the message from displaying. Ones I have tried are:
--disable-restore-session-state
--disable-session-crashed-bubble
--incognito
among others. I've experimented with some of the settings in Chrome, but none have (yet) worked. The --incognito option works - sort of. It keeps blocking plugins, one of which is Silverlight - one of the chief components for the website to function. Even though it does get rid of the message, it leaves the site not functioning properly.
The intent on using Taskkill to flush any existing Chrome sessions was to prevent the user opening up a dozen different Chrome instances of the same thing.
Is there any way to keep a user from opening multiple instances of Chrome that won't leave Chrome thinking it didn't close properly? Given the user restrictions, I'm not sure that a script/batch file to edit the Preferences file in the Chrome folder will work. An extension may be an option, but a third party application will not be.
Would appreciate any thoughts or assistance.
Thanks!
Chromium writes exit status into Preferences file. When it starts it writes Preferences file with:
"exited_cleanly": false
and upon clean exit writes Preferences file with:
"exited_cleanly": true
To prevent message about unclean shut down make sure that you have "exited_cleanly": true written in your Preferences file
On my Linux kiosk running on Raspberry Pi this sed command line added to /etc/rc.local fixes issue permanently:
sed -i 's/exited_cleanly\":\ false/exited_cleanly\":\ true/g' /home/pi/.config/chromium/Default/Preferences