[🐛 Bug]: profile-directory keeps being erased and initialized when switch between native launch and selenium launch
What happened?
Open chrome from application center, login some websites, say google.com. Quit. And then use selenium to load the same profile. From the visit history I can see they are the same profile, but all of the login cookies have been cleared.
Vice versa. If open with selenium first, login, close browser. And then open chrome from application center. Same thing happened.
I tried the same code in windows. No such issue.
How can we reproduce the issue?
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--user-data-dir=/Users/<username>/Library/Application Support/Google/Chrome")
chrome_options.add_argument('--profile-directory=Profile 2')
driver = Chrome(options=chrome_options)
Relevant log output
No logs. Code runs smooth.
Operating System
macOS Version 12.0.1 (Build 21A559)
Selenium version
4.1.0
What are the browser(s) and version(s) where you see this issue?
chrome 97.0.4692.99 (Official Build) (arm64)
What are the browser driver(s) and version(s) where you see this issue?
Chrome Driver 97.0.4692.71
Are you using Selenium Grid?
No response
@whhsw, thank you for creating this issue. We will troubleshoot it as soon as we can.
Info for maintainers
Triage this issue by using labels.
If information is missing, add a helpful comment and then I-issue-template label.
If the issue is a question, add the I-question label.
If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.
If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, W3C),
add the applicable G-* label, and it will provide the correct link and auto-close the
issue.
After troubleshooting the issue, please add the R-awaiting answer label.
Thank you!
Hi, @whhsw. This issue has been determined to require fixes in ChromeDriver.
You can see if the feature is passing in the Web Platform Tests.
If it is something new, please create an issue with the ChromeDriver team. Feel free to comment the issues that you raise back in this issue. Thank you.
According to chromedriver documentation, you should only need to set
user-data-dir — https://chromedriver.chromium.org/capabilities#h.p_ID_64
and it looks like it should include the Profile directory:
Library/Application Support/Google/Chrome/Default
https://chromium.googlesource.com/chromium/src/+/HEAD/docs/user_data_dir.md#user-cache-directory
If you still aren't seeing the behavior you expect, you will need to file a bug with chromedriver team.
Sorry to jump in here. I was reading several issues without any luck to find a solution for it, On a local machine, it's working without any problem, However. When using a remote/docker/container environment (webdriver.Remote). It's not overriding the Profile path for some reason, here is a snapshot of the Chrome: version.

Yes, it only works when the profile path is on the same machine as the driver.
According to chromedriver documentation, you should only need to set
user-data-dir— https://chromedriver.chromium.org/capabilities#h.p_ID_64 and it looks like it should include the Profile directory:Library/Application Support/Google/Chrome/Defaulthttps://chromium.googlesource.com/chromium/src/+/HEAD/docs/user_data_dir.md#user-cache-directoryIf you still aren't seeing the behavior you expect, you will need to file a bug with chromedriver team.
user-data-dir arg will only initiate the default profile. But not other profiles. profile-directory is the arg for multi profiles.
I'm literally just repeating what the chromedriver documentation says. Did you read it?
yes, and also for reference at the start of the documentation it says.
the user data directory contains profile data such as history, bookmarks, and cookies, as well as other per-installation local state. Each profile is a subdirectory (often Default) within the user data directory.
so My understanding is parent folder(user data dir): Library/Application Support/Google/Chrome/ subfolder (profile folders): starting from Default, then Profile 1, profile 2 etc...
Also checked code in chromium, looks like profile-directory is action as what the doc says? https://github.com/chromium/chromium/blob/59045b8f8ed3f7e3c2ba575508fcc56a488eb7fb/chrome/common/chrome_switches.cc#L432
Hi @titusfortner , Thank you for the clarification, I had thought it should be a similar used case as Geckodriver with Firefox.
I did review the ChromeDriver reference: ( this one stood up for me)
Common use cases Use custom profile (also called user data directory)
By default, ChromeDriver will create a new temporary profile for each session. At times you may want to set special preferences or just use a custom profile altogether. If the former, you can use the 'chrome.prefs' capability (described later below) to specify preferences that will be applied after Chrome starts. If the latter, you can use the user-data-dir Chrome command-line switch to tell Chrome which profiles to use:
ChromeOptions options = new ChromeOptions();
options.addArguments("user-data-dir=/path/to/your/custom/profile");
You can create your own custom profile by just running Chrome (on the command-line or through ChromeDriver) with the user-data-dir switch set to some new directory. If the path doesn't exist, Chrome will create a new profile in the specified location. You can then modify the profile settings as desired, and ChromeDriver can use the profile in the future. Open chrome://version in the browser to see what profile Chrome is using.
Summarizing it:
When chromedriver starts Chrome, if the ChromeOptions it receives from selenium-server (which were passed as ChromeOptions to RemoteWebDriver) do not contain a value for --user-data-dir, then chromedriver generates a random chrome profile directory in /tmp and starts chrome with that value in --user-data-dir. i.e. something like --user-data-dir=/tmp/.com.google.Chrome.ex4vLx/
Is there a way to configure selenium-server to start a Chrome node with a given --user-data-dir value?
Sorry about highjacking this thread here. If it's not relevant, I'll create another one.
Looking forward to hearing for you
seems to have found how to fix this in Mac os but not sure about the root cause. it's something related to the space in profile name.
- create profile by selenium first with non-whitespace, everything works fine.
- create profile by selenium or chrome, with whitespace in profile name, they keep erasing each other.
I will mark this as fixed for my case. @Anticope12 feel free to use the thread if it's relevant.
Good To hear that @whhsw.
I'll keep the thread open if it's okay with @titusfortner , Let me know if I should create a new request if you think it's diffrent.
I've more info here maybe it could help :
Just adding some extra content here, I was playing around with the argument. "--user-data-dir" actually created a new path/directory Here is the screenshot,

Here a snapshot if the code options1 = webdriver.ChromeOptions()
options1.add_argument('--user-data-dir=/tmp/chrome:')
options1.add_argument('--profile-directory=Profile 1')
self.driver = webdriver.Remote( command_executor="http://134.2000000.129:4444/wd/hub", desired_capabilities=capabilities, options=options1)
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.