Trying to set WebView2 User Data the same as installed Edge #4819
-
|
I have an application hosting a WebView2 instance (on Windows) where I want the behavior of the WebView2 to be identical to Edge (cache, cookies, extensions, etc). I have set the user data folder like this: var options = new CoreWebView2EnvironmentOptions(null, null);
var userDataFolder = @"C:\Users\deantric\AppData\Local\Microsoft\Edge\User Data";
CoreWebView2Environment.CreateAsync(null, userDataFolder, options);However, navigating to different sites on WebView2 that I have logged into on Edge doesn't show me as already logged in. And Am I setting the wrong User Data path? Or is there some other way to align these two? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
After a couple years, AI has gotten quite good and Claude was able to find the right solution: string userDataFolder;
if (UseEdgeCookies)
{
// Point to Edge's default profile to share cookies/auth sessions.
// This lets WebView2 access sites that the user is
// already signed into in Edge without an extra auth prompt.
userDataFolder = System.IO.Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"Microsoft", "Edge", "User Data");
}
else
{
userDataFolder = System.IO.Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"MyApp", "WebView2");
}
var options = new CoreWebView2EnvironmentOptions
{
// Enable SSO using the OS primary account (Azure AD/Entra).
// This lets WebView2 authenticate to corporate sites
// without a manual login prompt, just like Edge does.
AllowSingleSignOnUsingOSPrimaryAccount = true
};
_environment = await CoreWebView2Environment.CreateAsync(
browserExecutableFolder: null,
userDataFolder: userDataFolder,
options: options); |
Beta Was this translation helpful? Give feedback.
After a couple years, AI has gotten quite good and Claude was able to find the right solution:
string userDataFolder; if (UseEdgeCookies) { // Point to Edge's default profile to share cookies/auth sessions. // This lets WebView2 access sites that the user is // already signed into in Edge without an extra auth prompt. userDataFolder = System.IO.Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Microsoft", "Edge", "User Data"); } else …