-
Notifications
You must be signed in to change notification settings - Fork 51
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
Improve cookie behavior on .NET control #611
Comments
Totally agree with all points made in this feature request. Thanks for the detailed write up, @Symbai |
Hey @Symbai, thanks for the feedback. These seem like the come from a C++ world because they do come from a C++ world. However, we already have some .NET cookie improvements done that will be available in the next SDK release, including returning the cookies as a List, and support for easier conversion between CoreWebView2Cookie and System.Net.Cookie. I believe this should cover all of your points, but I'll keep this open until that support lands and you can try it out! Also, be sure to keep an eye on our Announcements repo and our incoming API reviews (for example, the Cookie API review) - this is great feedback to get, and the earlier we get it usually makes it easier to incorporate into our designs. Thanks! |
I also would like to see better cookie handling so I can open one instance of the browser, take the cookies it has collected via login, then when when opening a new instance of the browser, pass those cookies to it so it can already be "logged in". My preferable implementation is to just assign the cookie manager to the new instance, but copying cookies will also work... Edit: it seems that I got it to work by copying the cookies from one browser to the other... When can we expect this API to make into production? |
Piling on: I concur with @Symbai (good write up!). I just went through the same pain points you documented while writing some C#/.NET code to interact with the CookieManager . Your for loop: |
FWIW - I am pretty sure that there is a loss of fidelity if one converts from |
@ShaunLoganOracle Since the cookie properties are all value types, I think storing cookie values somewhere else (as i did in a Here's the code:
|
With 1.0.707-prerelease everything have been addressed, so I'm closing this issue. Thanks to the outstanding devs ❤👍 I love the feedback reaction so far. |
I really wanted this feature too and it seems to be not available in the latest release. |
@Symbai , can you plz advise on how to create a session cookie? with the IsSession being readonly?, thanks |
I'm not using WebView2 anymore and this has been nearly 2 years ago, I cannot give you an answer I'm sorry. You can try asking your question in discussions: https://github.com/MicrosoftEdge/WebView2Feedback/discussions |
@Symbai no worries and thanks for your reply |
The current design choice of the WebView2 cookie in .NET (Core) 1.0.674-prerelease control is terrible. It acts like this comes from C++ world. There are several things that will frustrate .NET developers:
CookieList
1.
GetCookiesAsync
returns aCookieList
class. Why not taking an existing C# collection type such as List? And even if there was a good reason to introduce an own collection class, why is there no enumerator on this collection? Without we cannot do things like this:2.
The next extremely unexpected design choice is that
Count
property returns anuint
. This makes sense because it cannot be negative. However all collections in .NET return anint
on their Count property. Because it returns anuint
, a very commonfor loop
will throw an exception in Visual Studio:At least this one can easily be fixed on our end by changing the int to uint on our
for
counter. But it rather should follow other long existing collections and use anint
. And throw an OutOfIndexException onGetValueAtIndex
when people do stupid things like GetValueAtIndex(-1). As of now, this doesn't really fit into .NET, again.3.
Why is there no Indexer? (If you would have chosen
List<T>
you would have get all of this for free). It would make things a lot easier for us:var cookie = cookieList[0];
CoreWebView2Cookie
The next thing is that instead of returning a collection of System.Net.Cookie you decided to make your own Cookie class. This forces us to generate a System.Net.Cookie based on your Cookie class every time we want to use that cookie outside of your control. For example to pass it to a WebClient or HttpWebRequest
Well again, there MIGHT be a reason why you wanted to do that. However, when we would want to create a System.Net.Cookie from it we run into another issue:
DateTime
Your choice for for example Expires property is to make it type
double
. The System.Net.Cookie however wants it to be DateTime instead. AndDateTime
is also a lot easier to handle in .NET because we have littler helper properties on this struct such as Day / Month etc without doing all the calculation from adouble
ourselves.Examples
Current behavior (using cookie for web request)
Expected behavior
Current behavior (retrieving all cookies which expire this month)
Expected behavior (retrieving all cookies which expire this month)
The text was updated successfully, but these errors were encountered: