maui icon indicating copy to clipboard operation
maui copied to clipboard

WebView with an attached CookieContainer not storing cookies on IOS device

Open dwe-alan opened this issue 1 year ago • 4 comments

Description

In a MainPage, I have a WebView with an attached CookieContainer, with a typical public website URL as a source:

<WebView HorizontalOptions="Fill"
             VerticalOptions="Fill"
             Source="https://www.amazon.co.uk/"
             Cookies="{Binding CookieContainer}"
             Navigated="WebView_OnNavigated"/>

The Navigated event handler looks like this:

        private void WebView_OnNavigated(object sender, WebNavigatedEventArgs e)
        {
            Console.WriteLine("---------------------------Navigated to: " + e.Url);

            var mainViewModel = (MainViewModel)BindingContext;

            foreach (Cookie cookie in mainViewModel.CookieContainer.GetAllCookies())
            {
                Console.WriteLine("----Cookie: " + cookie.Name);
            }
        }

Typical console output from Android device:

16:37:13:092	[DOTNET] ---------------------------Navigated to: https://www.amazon.co.uk/
16:37:13:092	[DOTNET] ----Cookie: session-id
16:37:13:092	[DOTNET] ----Cookie: session-id-time
16:37:13:093	[DOTNET] ----Cookie: i18n-prefs
16:37:13:093	[DOTNET] ----Cookie: ubid-acbuk
16:37:13:093	[DOTNET] ----Cookie: session-token
16:37:13:093	[DOTNET] ----Cookie: av-timezone
16:37:13:093	[DOTNET] ----Cookie: csm-hit
16:37:13:093	[chromium] [WARNING:spdy_session.cc(3264)] Received HEADERS for invalid stream 11
16:37:13:160	[chromium] [WARNING:spdy_session.cc(3264)] Received HEADERS for invalid stream 25
16:37:13:787	[DecorView[]] getWindowModeFromSystem  windowmode is 1
16:37:13:787	[DecorView[]] updateDecorCaptionStatus displayWindowDecor is false
16:37:14:726	[DOTNET] ---------------------------Navigated to: https://www.amazon.co.uk/s?rh=p_78%3AB08F681PH6%7CB099HL86MQ%7CB09BG9FTXP%7CB0B2SDTSJ8&hidden-keywords=B099HL86MQ%7CB09BG9FTXP%7CB08F681PH6%7CB0B2SDTSJ8&content-id=amzn1.sym.fca2a48e-cee5-4b90-9775-87f840797732&painterId=billboard-card&pd_rd_r=b493d205-cb8c-4780-8656-79e86f3ac356&pd_rd_w=uQhMk&pd_rd_wg=aRnIh&pf_rd_p=fca2a48e-cee5-4b90-9775-87f840797732&pf_rd_r=1WV48DEM28KVGCFKEMJY&ref=pd_gwm_unk
16:37:14:789	[DOTNET] ----Cookie: session-id
16:37:14:789	[DOTNET] ----Cookie: session-id-time
16:37:14:789	[DOTNET] ----Cookie: i18n-prefs
16:37:14:789	[DOTNET] ----Cookie: ubid-acbuk
16:37:14:789	[DOTNET] ----Cookie: session-token
16:37:14:789	[DOTNET] ----Cookie: av-timezone
16:37:14:789	[DOTNET] ----Cookie: csm-hit

Typical console output from IOS device:

16:50:10:971	2023-08-03 16:50:07.694 MauiApp1[565:954521] ---------------------------Navigated to: https://www.amazon.co.uk/
16:50:10:971	
16:50:13:064	Thread started: <Thread Pool> #7
16:50:13:127	Thread started: .NET ThreadPool Gate #8
16:50:13:127	Thread started: <Thread Pool> #9
16:50:14:421	Thread started: <Thread Pool> #10
16:50:17:401	2023-08-03 16:50:14.196 MauiApp1[565:954521] ---------------------------Navigated to: https://www.amazon.co.uk/b/?ie=UTF8&node=14100223031&ref_=gw_uk_mob_dc_aucc_fc&pf_rd_p=b7e42e21-9878-4f32-b7fb-1b1beb7f2037&pd_rd_wg=yBwqQ&pf_rd_r=23C33SR2A6DVYGQF8SC7&content-id=amzn1.sym.b7e42e21-9878-4f32-b7fb-1b1beb7f2037&pd_rd_w=oLzO6&painterId=image-tile&pd_rd_r=dd0ee41f-6f4b-4d68-a5a4-26b5af3cdc96
16:50:17:401	
16:50:23:450	2023-08-03 16:50:20.179 MauiApp1[565:954521] ---------------------------Navigated to: https://www.amazon.co.uk/dp/B09B8YWXDF/ref=mh_s9_acsd_al_c2_x_1_i?pf_rd_m=A3P5ROKL5A1OLE&pf_rd_s=mobile-hybrid-4&pf_rd_r=NWQV6R2NXC4GRRV4D1G5&pf_rd_t=30901&pf_rd_p=1589be94-3f21-4958-a7ce-4ae5f6784d16&pf_rd_i=14100223031
16:50:23:450	

Unfortunately - no cookies

Cookies are often required for authenticating/authorizing back-channel communications, and so it would be really helpful if cookies were stored consistently between platforms. IOS cookies were being stored until the last dotnet workload updates, then stopped. I have no idea whether they stopped because of a decision by Apple or something in .NET MAUI.

Steps to Reproduce

  1. Create brand-new .NET MAUI project in Visual Studio 17.6.5
  2. Create a MainViewModel:
namespace MauiApp1
{
    using System.Net;

    public class MainViewModel
    {
        public CookieContainer CookieContainer { get; } = new CookieContainer();
    }
}
  1. Add WebView component to MainPage, using the MainViewModel view model
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:mauiApp1="clr-namespace:MauiApp1"
             x:Class="MauiApp1.MainPage"
             Shell.NavBarIsVisible="false"
             x:DataType="mauiApp1:MainViewModel">

    <WebView HorizontalOptions="Fill"
             VerticalOptions="Fill"
             Source="https://www.amazon.co.uk/"
             Cookies="{Binding CookieContainer}"
             Navigated="WebView_OnNavigated"/>

</ContentPage>
  1. Create code behind file:
namespace MauiApp1
{
    using System.Net;

    public partial class MainPage : ContentPage
    {
        public MainPage()
        {
            BindingContext = new MainViewModel();

            InitializeComponent();
        }

        private void WebView_OnNavigated(object sender, WebNavigatedEventArgs e)
        {
            Console.WriteLine("---------------------------Navigated to: " + e.Url);

            var mainViewModel = (MainViewModel)BindingContext;

            foreach (Cookie cookie in mainViewModel.CookieContainer.GetAllCookies())
            {
                Console.WriteLine("----Cookie: " + cookie.Name);
            }
        }
    }
}
  1. Build for Android device
  2. Navigate around Amazon site: lots of cookies picked up
  3. Build for IOS device
  4. Navigate around Amazon site: no cookies picked up

Link to public reproduction project repository

No response

Version with bug

7.0.92

Last version that worked well

7.0.86

Affected platforms

iOS

Affected platform versions

No response

Did you find any workaround?

No

Relevant log output

No response

dwe-alan avatar Aug 03 '23 16:08 dwe-alan

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.

ghost avatar Aug 11 '23 15:08 ghost

Are there any updates to this problem?

Ganit20 avatar Dec 28 '23 13:12 Ganit20

Having the same issue. This is a show stopper for us ATM. Cookies are empty on iOS and CookieContainer for WebView is null for any platform.

MichaelPuckett2G3 avatar Jan 03 '24 21:01 MichaelPuckett2G3

This issue is affecting my MAUI Blazor applications.

FelipeCostaGualberto avatar Jan 04 '24 11:01 FelipeCostaGualberto

This issue was verified using Visual Studio Enterprise 17.10.0 Preview 1. This error is reproduced on both iOS and Android platforms, and cookies cannot be picked up.

jaosnz-rep avatar Feb 19 '24 09:02 jaosnz-rep