EdgeWebDriver icon indicating copy to clipboard operation
EdgeWebDriver copied to clipboard

probably user data directory is already in use, please specify a unique value for --user-data-dir argument, or don't use --user-data-dir (SessionNotCreated)

Open maurod83 opened this issue 10 months ago • 13 comments

I have an application using Selenium to automate Edge browser that throws this error message: probably user data directory is already in use, please specify a unique value for --user-data-dir argument, or don't use --user-data-dir (SessionNotCreated) This error happens using a new profile directory too.

Windows Version: Windows 10 Version 22H2 (build 19045.5487) Selenium Version: 4.29.0 Edge and Edgedriver version: 133.0.3065.82

This is the code:

service = EdgeDriverService.CreateDefaultService();

var options = new EdgeOptions();
var driver = new EdgeDriver((EdgeDriverService)service, (EdgeOptions)options);

When I run this app manually for the first time it throws this exception:

session not created: probably user data directory is already in use, please specify a unique value for --user-data-dir argument, or don't use --user-data-dir (SessionNotCreated)

StackTrace: at OpenQA.Selenium.WebDriver.UnpackAndThrowOnError(Response errorResponse, String commandToExecute) at OpenQA.Selenium.WebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters) at OpenQA.Selenium.WebDriver.StartSession(ICapabilities desiredCapabilities) at OpenQA.Selenium.WebDriver..ctor(ICommandExecutor executor, ICapabilities capabilities) at OpenQA.Selenium.Chromium.ChromiumDriver..ctor(ChromiumDriverService service, ChromiumOptions options, TimeSpan commandTimeout) at OpenQA.Selenium.Edge.EdgeDriver..ctor(EdgeDriverService service, EdgeOptions options, TimeSpan commandTimeout) at OpenQA.Selenium.Edge.EdgeDriver..ctor(EdgeDriverService service, EdgeOptions options) at AppWeb.frmAppWeb.EjecutarConexion()

And creates automatically an entry in Windows Registry key "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Compatibility Assistant\Store". When I run the application again it works as expected. If I remove this entry, error shows up again.

On the first try (with error) msedge.exe commandline is:

"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" --allow-pre-commit-input --disable-background-networking --disable-backgrounding-occluded-windows --disable-client-side-phishing-detection --disable-default-apps --disable-hang-monitor --disable-popup-blocking --disable-prompt-on-repost --disable-sync --enable-automation --enable-logging --log-level=0 --no-first-run --no-service-autorun --password-store=basic --remote-debugging-port=0 --test-type=webdriver --use-mock-keychain --user-data-dir="C:\Users\MAUROD~1\AppData\Local\Temp\scoped_dir8168_1802574373" --edge-skip-compat-layer-relaunch data:,

On the second try (without error) msedge.exe commandline is:

"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" --allow-pre-commit-input --disable-background-networking --disable-backgrounding-occluded-windows --disable-client-side-phishing-detection --disable-default-apps --disable-hang-monitor --disable-popup-blocking --disable-prompt-on-repost --disable-sync --enable-automation --enable-logging --log-level=0 --no-first-run --no-service-autorun --password-store=basic --remote-debugging-port=0 --test-type=webdriver --use-mock-keychain --user-data-dir="C:\Users\MAUROD~1\AppData\Local\Temp\scoped_dir18024_701312417" data:,

The problem is that when I start my app from another process that was called from an browser extension using Native Host Messaging, it always throws that exception. And even if I start my app manually using "Run As Administrator" always throws that exception too.

Selenium Log:

2025-02-24 23:18:18.999 TRACE SeleniumManager: DEBUG msedgedriver not found in PATH 2025-02-24 23:18:19.001 TRACE SeleniumManager: DEBUG MicrosoftEdge detected at C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe 2025-02-24 23:18:19.001 TRACE SeleniumManager: DEBUG Running command: wmic datafile where name='C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe' get Version /value 2025-02-24 23:18:19.001 TRACE SeleniumManager: DEBUG Output: "\r\r\n\r\r\nVersion=133.0.3065.82\r\r\n\r\r\n\r\r\n\r" 2025-02-24 23:18:19.001 TRACE SeleniumManager: DEBUG Detected browser: MicrosoftEdge 133.0.3065.82 2025-02-24 23:18:19.001 TRACE SeleniumManager: DEBUG Required driver: msedgedriver 133.0.3065.82 2025-02-24 23:18:19.002 TRACE SeleniumManager: DEBUG msedgedriver 133.0.3065.82 already in the cache 2025-02-24 23:18:19.002 TRACE SeleniumManager: INFO Driver path: C:\Users\Mauro Dimare.cache\selenium\msedgedriver\win64\133.0.3065.82\msedgedriver.exe 2025-02-24 23:18:19.002 TRACE SeleniumManager: INFO Browser path: C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe 2025-02-24 23:18:19.002 TRACE SeleniumManager: Driver path: C:\Users\Mauro Dimare.cache\selenium\msedgedriver\win64\133.0.3065.82\msedgedriver.exe 2025-02-24 23:18:19.002 TRACE SeleniumManager: Browser path: C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe 2025-02-24 23:18:19.592 DEBUG HttpCommandExecutor: Executing command: []: newSession 2025-02-24 23:18:19.634 TRACE HttpCommandExecutor: >> POST RequestUri: http://localhost:45960/session, Content: System.Net.Http.ByteArrayContent, Headers: 2 {"capabilities":{"firstMatch":[{"browserName":"MicrosoftEdge","ms:edgeOptions":{"binary":"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"}}]}} 2025-02-24 23:18:19.715 TRACE HttpCommandExecutor: << StatusCode: 500, ReasonPhrase: Internal Server Error, Content: System.Net.Http.StreamContent, Headers: 1 {"value":{"error":"session not created","message":"session not created: probably user data directory is already in use, please specify a unique value for --user-data-dir argument, or don't use --user-data-dir","stacktrace":"\tGetHandleVerifier [0x00007FF68182E735+13397]\n\tMicrosoft::Applications::Events::EventProperty::empty [0x00007FF681ABB1B4+2060276]\n\tMicrosoft::Applications::Events::EventProperty::empty [0x00007FF681A12338+1368440]\n\t(No symbol) [0x00007FF6815F0382]\n\t(No symbol) [0x00007FF6815EA827]\n\t(No symbol) [0x00007FF68162FD84]\n\t(No symbol) [0x00007FF681623FC3]\n\t(No symbol) [0x00007FF6815F8B96]\n\t(No symbol) [0x00007FF6815F7E50]\n\t(No symbol) [0x00007FF6815F89C3]\n\t(No symbol) [0x00007FF681680214]\n\t(No symbol) [0x00007FF6817106CF]\n\t(No symbol) [0x00007FF681683A53]\n\tMicrosoft::Applications::Events::EventProperty::to_string [0x00007FF681B745BD+279981]\n\tsimdutf::get_active_implementation [0x00007FF6817B78C1+409457]\n\tsimdutf::get_active_implementation [0x00007FF6817B2BA4+389716]\n\tsimdutf::get_active_implementation [0x00007FF6817B2CE9+390041]\n\tsimdutf::get_active_implementation [0x00007FF6817A62E6+338326]\n\tBaseThreadInitThunk [0x00007FFE4DF37374+20]\n\tRtlUserThreadStart [0x00007FFE4FDDCC91+33]\n"}} 2025-02-24 23:18:19.724 DEBUG HttpCommandExecutor: Response: ( SessionNotCreated: System.Collections.Generic.Dictionary`2[System.String,System.Object])

maurod83 avatar Feb 25 '25 18:02 maurod83

Hi maurod83,

Thanks for reporting this bug. We are working on this issue and will get it fixed as soon as possible.

As a workaround, you may use an earlier version of MsEdgeDriver 133.0.2978.0 in this link: https://msedgewebdriverstorage.z22.web.core.windows.net/?prefix=133.0.2978.0/

Thanks.

guangyuexu avatar Feb 25 '25 23:02 guangyuexu

If any additional information is required for this, I am happy to help. I work for a software vendor using this component to drive web automation. We automatically update the drivers in the product and are getting hit by this.

leeej84 avatar Feb 27 '25 16:02 leeej84

A further note, the workaround on using this driver did not work for me.

https://msedgewebdriverstorage.z22.web.core.windows.net/?prefix=133.0.2978.0/

leeej84 avatar Feb 27 '25 17:02 leeej84

Hi @leeej84 and @maurod83 , do you have a small test case to repro the crash?

guangyuexu avatar Feb 27 '25 19:02 guangyuexu

adding the argument "--edge-skip-compat-layer-relaunch" to options seems to work for me.

otherwise, the path to the program (or the parent if there's one) that calls the webdriver needs to be in "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Compatibility Assistant\Store" but this will only happen after the program has been opened at least once.

seems like a bug but at least there's a workaround.

cheers

kkingdara-at-loginvsi avatar Feb 27 '25 23:02 kkingdara-at-loginvsi

Hi @leeej84 and @maurod83 , do you have a small test case to repro the crash?

Hi @guangyuexu,

I've attached a simple test case comparing the results using Selenium or using webdriver directly. If you start this app for the first time and use Selenium test it fails (if there is no record in HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Compatibility Assistant\Store for this app). It should fail if you start this app with "Run As Administrator" too.

But this error is not consistent as it happens randomly.

AppWeb.zip

maurod83 avatar Feb 28 '25 14:02 maurod83

adding the argument "--edge-skip-compat-layer-relaunch" to options seems to work for me.

otherwise, the path to the program (or the parent if there's one) that calls the webdriver needs to be in "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Compatibility Assistant\Store" but this will only happen after the program has been opened at least once.

seems like a bug but at least there's a workaround.

cheers

Thanks @kkingdara-at-loginvsi it works with that option!

Is there any documentation about this option or something similar in Chrome as it happens there too?

maurod83 avatar Feb 28 '25 14:02 maurod83

adding the argument "--edge-skip-compat-layer-relaunch" to options seems to work for me. otherwise, the path to the program (or the parent if there's one) that calls the webdriver needs to be in "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Compatibility Assistant\Store" but this will only happen after the program has been opened at least once. seems like a bug but at least there's a workaround. cheers

Thanks @kkingdara-at-loginvsi it works with that option!

Is there any documentation about this option or something similar in Chrome as it happens there too?

yes,it can really solve!!

Daisyyijun avatar Mar 04 '25 06:03 Daisyyijun

Hi @guangyuexu

Thank you for looking into this issue. I’m hoping to see it resolved. Is there any plan to fix this in an upcoming release of the browser or the driver?

I’m running a Java program on Windows with administrator privileges to launch the Edge browser, and I consistently encounter this error. If I roll back the browser to version 132, the issue no longer occurs, which suggests it was introduced in version 133. The EdgeDriver version does not appear to make a difference.

Workarounds

Here are the workarounds I’ve identified:

  1. Specify the --edge-skip-compat-layer-relaunch option as commented above.
  2. Specify a port number not in use by other applications for the --remote-debugging-port option, as in this comment.
  3. Disable the Program Compatibility Assistant Service (although this does not work in all environments).

Notes on the workarounds

  • There is no official documentation about --edge-skip-compat-layer-relaunch. Oddly, when running under administrator privileges, this option is already included by default, but explicitly adding it changes the option order and resolves the error. This behavior is quite strange.
  • For the --remote-debugging-port, there is no documentation explaining why --remote-debugging-port=0 fails, which may indicate another underlying issue.
  • Disabling the Program Compatibility Assistant Service works only on certain environments and is not a universal solution.

I would really appreciate an official fix if possible.

More Details

You can reproduce this behavior as follows:

  1. Download and extract sample.zip file.
  2. Place msedgedriver.exe in the same directory as HelloWorld.exe and then run HelloWorld.exe with administrator privileges.
  3. If the browser launches correctly, you will be redirected to a webpage. However, if the issue occurs, it will remain at the data:, URL and log a SessionNotCreatedException in the console.

You can also control the following settings in config.properties:

  • edgedriver.path=[path\\to\\msedgedriver.exe]
  • debug.port=[debugging port number]
  • skip.compat.layer=[true to specify --edge-skip-compat-layer-relaunch]

Thank you again for your attention to this issue and any help in resolving it!

mmasaop avatar Mar 26 '25 17:03 mmasaop

Hi there—when you have a moment, could you let me know if there are any updates on this issue? Thank you!

mmasaop avatar Apr 15 '25 08:04 mmasaop

In which version will the problem be resolved? Currently, I have the same issue with Microsoft Edge version 135.0.3179.73 (official version) (64 bit) and WebMriver version 135.0.3179.73

TotheAnts avatar Apr 17 '25 05:04 TotheAnts

Are there any updates on this issue? Thank you!

philbo87 avatar May 06 '25 22:05 philbo87

Hi folks. Thanks for your patience while the Edge team has been investigating this issue. As was discovered in this thread, the issue is due to some recent changes in how the Edge browser process handles launching in an environment with compat flags. The issue has been fixed in Edge and Edge WebDriver 138.0.3305.0 and above.

While waiting for the fix to reach Edge Stable, the workaround off adding the --edge-skip-compat-layer-relaunch command line flag should continue to work.

bwalderman avatar May 07 '25 19:05 bwalderman