How to clear WinRT web browsing cookies?

Does anyone know how to clear cookies from WinRT WebView ? If there is no built-in method, can anyone have a solution in JavaScript, so I can run it using the InvokeScript WebView method. Android and iOS have a simple 1-5 line encoding for clearing cookies, why not in WinRT?

+4
source share
2 answers

In Windows 8, do the following:

 Array<String^>^ arguments = ref new Array<String^>(1); arguments->set(0, "var cookies = document.cookie.split(';');" + "for (var i = 0; i < cookies.length; i++) {" + " var cookie = cookies[i];" + " var eqPos = cookie.indexOf('=');" + " var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;" + " document.cookie = name + '=1;expires=Thu, 01 Jan 1970 00:00:00 GMT';" + "};"); String^ result = myWebView->InvokeScript("eval", arguments); 

In Windows 8.1 Preview, you can use the HttpCookieManager class.

+3
source

I do not think that you can delete everything in Javascript, but I will answer another part of your question about the possibility of doing this in WinRT. For standard cookies you can:

  public void clearCookiesForUri(String uri) { Windows.Web.Http.Filters.HttpBaseProtocolFilter baseFilter = new Windows.Web.Http.Filters.HttpBaseProtocolFilter(); HttpCookieCollection cookieCollection = baseFilter.CookieManager.GetCookies(new Uri(uri)); Debug.WriteLine("Deleting cookies for " + uri); foreach (HttpCookie cookie in cookieCollection) { Debug.WriteLine(cookie.Name + ": " + cookie.Value); baseFilter.CookieManager.DeleteCookie(cookie); } } 

And the only way I found deleting HttpOnly files is to clear all WebView data through WebView.ClearTemporaryWebDataAsync() . This is pretty messy, but it works.

+1
source

Source: https://habr.com/ru/post/1497323/


All Articles