-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cookies are not saved when Webview2 is displayed using .show() method #2128
Comments
Hey @SandhyaArun - thanks for the bug report! The difference between Show and ShowDialog is that ShowDialog will not call Close on the children controls when it is closed, and instead stays alive but hidden. This is keeping the WebView2 control alive, and is why the cookies are still there the next time you show the dialog. On the contrary, Show will call Close on the children which shuts down the WebView2 control. I'm unable to access the url in the sample app your provided. Can you verify that the cookies are setup to be persisted, and aren't session cookies that would get cleaned up when the browser processes shut down? Thank! |
@champnic I tried to persist the cookies by calling CoreWebView2.CookieManager.AddOrUpdateCookie() and it is not working. Is it the right way to persist cookies window close? if not please advise me with right solution. Also I want to know is there a way to persist bowser state. not just the cookies? My requirement is to create an instance of the browser, take the cookies it has collected via login, then when opening a new instance of the browser, pass those cookies to it so it can already be "logged in". I can manually do this cookie handling. I just wanna know webview2 is providing an easy way to achieve this.
|
The WebView2 matches the cookie handling of the browser. Cookies that are marked with an expiration date (and not session cookies) will automatically be persisted. As long as you use the same User Data Folder when creating the new WebView2 instances, they will share cookies and browser state. |
I'm re-using my User Data Folder and Profile name, and the cookies are not persisting like they do with MS Edge. I'm using Azure Portal to test. My configuration looks like this: var userDataPath = Environment.ExpandEnvironmentVariables("%USERPROFILE%\\AppData\\Local\\Microsoft");
var envOptions = new CoreWebView2EnvironmentOptions(allowSingleSignOnUsingOSPrimaryAccount: true);
var environment = await CoreWebView2Environment.CreateAsync(userDataFolder: userDataPath, options: envOptions);
var options = environment.CreateCoreWebView2ControllerOptions();
options.ProfileName = "Default";
options.IsInPrivateModeEnabled = false;
await webView2Control.EnsureCoreWebView2Async(environment, options); The User Data and Profile is being created with lots of files and folders, so I don't think I'm running into a permission issue. |
Hello, is there any update about this issue ? |
My webview2 Control resides in a form and i am trying to show it from another form using ShowDialog() and Show().
The url I am displaying needs authentication and I want to skip the authentication when I load it second time. It wont ask for authentication during the second time, if I show the from using .ShowDialog() function. However if I use .Show() function , it is always ask for authentication. Cookies are not saved when it was displayed using .show() method. Can any one help me. Sample code is attached.
WebView2SampleApp.zip
The text was updated successfully, but these errors were encountered: