1

According to the documentation at https://learn.microsoft.com/de-de/microsoft-edge/webview2/reference/win32/webview2-idl?view=webview2-1.0.818.41 the User Data Folder can be set using the following registry entry

[{Root}]\Software\Policies\Microsoft\Edge\WebView2\UserDataFolder
"{AppId}"=""

I don't understand what the AppId is meant to be in this case? Does this mean the setting is specific to a particular app or a different user data folder can be set per registered app?

There is no equivalent to this in the corresponding environment variable, which forces all WebView2 instances on a machine to use a single shared folder:

WEBVIEW2_USER_DATA_FOLDER

Our applications use specific user data folders set via CoreWebView2Environment.CreateAsync, but this gets overwritten if someone else sets the WEBVIEW2_USER_DATA_FOLDER environment variable. It forces all instances to use the shared folder defined in the environment variable.

As our applications depend on having individual folders, we detect if the environment variable is set and show a message or handle it. We would like to do the same if the user folder is set in the registry, but we don't understand how this is done.

bgx
  • 751
  • 10
  • 14
  • Dont mess with Registry for that, instead create each `WebView2`with its own environment like this: https://stackoverflow.com/questions/62470733/set-cache-directory-for-webview2/62479693#62479693. That will be individual to each application. – Poul Bak Jun 02 '21 at 08:21
  • Thanks @PoulBak, but the question is specifically about how to set this in the registry. I edited the question to include that we want to detect if someone has set that registry value, potentially overriding the locations we set in the way you suggested. – bgx Jun 02 '21 at 08:51

1 Answers1

1

The global documentation describes the loader override registry key path:

[{Root}]\Software\Policies\Microsoft\Edge\WebView2\UserDataFolder "{AppId}"=""

And then slightly lower down what Root and AppId are:

First verify with Root as HKLM and then HKCU. AppId is first set to the Application User Model ID of the process, then if no corresponding registry key, the AppId is set to the compiled code name of the process, or if that is not a registry key then *.

This means:

  • If you're app has an Application User Model ID set, then WebView2 looks for registry keys using that as the AppId.
  • If that isn't found or the app doesn't have an Application User Model ID then the executable file name is used. So if you're app executable is named ExampleApp.exe then WebView2 will look for registry keys with AppId set to ExampleApp.exe.
  • If that registry path isn't found, then WebView2 will try again with AppId set to *. This is useful for applying loader overrides to all applications.

The goal of the override registry keys and environment variables is to make it easier for developers to debug and develop apps that use WebView2 and for system administrators to force the use of particular WebView2 Runtime versions. It is not intended for users although that is possible. If a user or system administrator does set the user data folder via a loader override and applies it to all applications on their system, they are likely to break apps using WebView2 not just yours and I wouldn't expect this is a problem you should have to solve.

Sharing user data folders is possible, but only works well if the host apps are written with sharing in mind. Chromium is designed such that there can be only one browser process per user data folder. If more than one app tries to use the same user data folder they would need to share the same browser process. If the apps have different WebView2 Runtime version requirements or specify different command line arguments for the browser process then they will be unable to share the browser process and whichever app starts its WebView2 first wins and the rest will fail to create their WebView2.

David Risney
  • 3,886
  • 15
  • 16
  • Thanks David, that explains it well and I could verify it in a test. The reference to group policies in the documentation had us concerned that this is essentially targeted at System Administrators to control the WV2 environments. E.g. set a single shared folder to avoid a proliferation of individual ones... – bgx Jun 03 '21 at 08:16
  • That's true I left that out - Its also for system administrators. Although we didn't imagine for it to be used to force apps to use one user data folder. This would be a bad idea and potentially break apps that weren't designed to share a user data folder with one another. I'll update my answer with that info. Thanks! – David Risney Jun 03 '21 at 18:45