0

Trying to use a webview in Xamarin Forms project for iOS and Android.

In Android, upon navigating to a webpage that sets cookies, no cookies are set in the webview.

Due to this, cookies are not sent also along with the subsequent requests.

Do I need to do anything to enable the "normal" browser cookie behaviour for webview ?

Currently initializing as follows:

vw1.Cookies = New CookieContainer(), where vw1 is the instance of WebView

AbiSinghal
  • 30
  • 6
  • You following this setup ? https://forums.xamarin.com/discussion/41039/setting-cookies-in-a-webview – G.Mich May 30 '20 at 20:24
  • That thread is about 5 years old and uses customrenderers. Is that still required to accept cookies? – AbiSinghal May 31 '20 at 03:32
  • @AbiSinghal Xamarin.Forms 4.6.0.772 (4.6.0 Service Release 1) have fixed `"Make cookie handling consistent and non destructive (#10571) fixes #10318" (#10571)` Please see this thread: https://learn.microsoft.com/en-us/xamarin/xamarin-forms/release-notes/4.6/4.6.0-sr2#additional-fixes-included-in-this-release-1 – Leon Jun 01 '20 at 06:56
  • My full version is 4.6.0.800. Seems there is some regression. It was working fine in lower version but need to upgrade due to some other issue. – AbiSinghal Jun 01 '20 at 06:59
  • If you still have this issue in new version, you can open a thread in github page: https://github.com/xamarin/Xamarin.Forms/issues – Leon Jun 02 '20 at 01:27
  • Opened here https://github.com/xamarin/Xamarin.Auth/issues/444 – AbiSinghal Jun 05 '20 at 16:08

2 Answers2

0

Take a look at xamarin forms 4.6 https://github.com/xamarin/Xamarin.Forms/issues/3262

G.Mich
  • 1,607
  • 2
  • 24
  • 42
  • Yes am on Xamarin Forms 4.6 - It adds a Cookies property as well - which is what is initialized in the question description. Somehow it is not accepting cookies when navigated to a web page. – AbiSinghal May 31 '20 at 07:20
  • I think this may be the issue: https://github.com/xamarin/Xamarin.Forms/pull/10571 - By when is this expected to be released ? – AbiSinghal Jun 01 '20 at 06:37
  • In this release https://learn.microsoft.com/en-us/xamarin/xamarin-forms/release-notes/4.6/4.6.0-sr1 fixed the #10571 – G.Mich Jun 01 '20 at 07:44
  • My full version is 4.6.0.800. Seems there is some regression. It was working fine in 4.6.0.772 but need to upgrade due to some other issue – AbiSinghal Jun 01 '20 at 07:45
0

After so many days of trying various options, here are the conclusions:

  • WebView cookie accepting is an issue. Even after using CustomRenderers, some cookies get left out and are not seen in the CookieContainer. Looks like the forgetfulness has some relation to the Cookie Domain property.

  • HttpClient sets cookie nicely in the CookieContainer. And once set, those are sent by the WebView as expected.

Hence, we have implemented such that all required cookies are set by HttpClient operation before the webview requests the Url.

Hope this helps someone.

AbiSinghal
  • 30
  • 6
  • Do you have an implementation example for how to set the cookies using HttpClient? – juicebyjustin Sep 22 '22 at 15:24
  • I found this that worked for me: https://stackoverflow.com/a/13287224/814891. After setting the cookie to any value for the URL the cookie was then saved by the webview. – juicebyjustin Sep 22 '22 at 18:10