xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.64k stars 1.88k forks source link

Xamarin Forms iOS WkWebViewRenderer cookies not passed to webview in release build when Link Framework SDKs Only selected #15795

Closed todorsp closed 11 months ago

todorsp commented 11 months ago

Description

Cookies stopped being passed from our Xamarin forms iOS code (WkWebViewRenderer) to webview. This happens only in release builds where linker behaviour is set to "Link Framework SDKs Only". When linker behaviour is set to "Don't link" everything works fine. This has happened upon updating Visual Studio for Mac to the latest version (17.6.3 (build 421)).

Steps to Reproduce

Here is a snippet from our iOS WkWebViewRenderer:

                                   WKHttpCookieStore cookie_store = WKWebsiteDataStore.DefaultDataStore.HttpCookieStore;

                                    string token_cookie_domain = ((InteractiveWebView)e.NewElement).GetTokenCookieDomain();
                                    string token_cookie_path   = ((InteractiveWebView)e.NewElement).GetTokenCookiePath();

                                    // token cookie
                                    string token_cookie_name = ((InteractiveWebView)e.NewElement).GetTokenCookieName();
                                    string token_cookie_val  = ((InteractiveWebView)e.NewElement).GetTokenCookieValue();

                                    ApiDeviceInfo device_info = new ApiDeviceInfo();
                                    string device_info_s = StringUtils.ObjToJsonB64(device_info);
                                    NSHttpCookie device_cookie = new NSHttpCookie(new Cookie()
                                    {
                                            Name    = InteractiveWebView.DeviceInfoCookieName ,
                                            Value   = device_info_s ,
                                            Path    = token_cookie_path ,
                                            Domain  = token_cookie_domain ,
                                            Expires = DateTime.Now.AddYears(1)                                              
                                    });

                                   cookie_store.SetCookie (device_cookie , () =>
                                    {
                                            //Logger.Log (Logger.LogSeverity.DEBUG, TAG, "OnElementChanged", "Device info cookie set");
                                    });

Expected Behavior

Cookie should be accessible from web page.

Actual Behavior

Cookie is null in web page.

Environment

Show/Hide Visual Studio info Visual Studio Community 2022 for Mac Version 17.6.3 (build 421) Installation UUID: 7b1b508b-3b9e-4c95-bfa5-1085b109086e Runtime .NET 7.0.3 (64-bit) Architecture: Arm64 Microsoft.macOS.Sdk 13.1.1007; git-rev-head:8afca776a0a96613dfb7200e0917bb57f9ed5583; git-branch:release/7.0.1xx-xcode14.2 Roslyn (Language Service) 4.6.0-3.23180.6+99e956e42697a6dd886d1e12478ea2b27cceacfa NuGet Version: 6.4.0.117 .NET SDK (Arm64) SDK: /usr/local/share/dotnet/sdk/7.0.307/Sdks SDK Versions: 7.0.307 7.0.306 7.0.304 7.0.302 7.0.203 7.0.202 7.0.201 7.0.200 7.0.103 7.0.102 6.0.413 6.0.412 6.0.410 6.0.408 6.0.407 6.0.406 6.0.405 MSBuild SDKs: /Applications/Visual Studio.app/Contents/MonoBundle/MSBuild/Current/bin/Sdks .NET SDK (x64) SDK Versions: 6.0.413 6.0.412 6.0.410 6.0.408 6.0.407 6.0.406 6.0.106 5.0.408 3.1.426 3.1.420 .NET Runtime (Arm64) Runtime: /usr/local/share/dotnet/dotnet Runtime Versions: 7.0.10 7.0.9 7.0.7 7.0.5 7.0.4 7.0.3 7.0.2 6.0.21 6.0.20 6.0.18 6.0.16 6.0.15 6.0.14 6.0.13 .NET Runtime (x64) Runtime: /usr/local/share/dotnet/x64/dotnet Runtime Versions: 6.0.21 6.0.20 6.0.18 6.0.16 6.0.15 6.0.14 6.0.6 5.0.17 3.1.32 3.1.26 Xamarin.Profiler Version: 1.8.0.49 Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler Updater Version: 11 Apple Developer Tools Xcode: 14.3 21812 Build: 14E222b Xamarin.Mac Not Installed Xamarin.iOS Version: 16.4.0.6 Visual Studio Community Hash: 97731c92c Branch: xcode14.3 Build date: 2023-04-11 22:38:36-0400 Xamarin.Android Version: 13.2.1.2 (Visual Studio Community) Commit: xamarin-android/d17-5/a8a26c7 Android SDK: /Users/todor/bin/sdks Supported Android versions: 12.0 (API level 31) 11.0 (API level 30) 13.0 (API level 33) SDK Command-line Tools Version: 7.0 SDK Platform Tools Version: 34.0.4 SDK Build Tools Version: 33.0.2 Build Information: Mono: d9a6e87 Java.Interop: xamarin/java.interop/d17-5@149d70fe SQLite: xamarin/sqlite/3.40.1@68c69d8 Xamarin.Android Tools: xamarin/xamarin-android-tools/d17-5@ca1552d Microsoft Build of OpenJDK Java SDK: /Library/Java/JavaVirtualMachines/microsoft-11.jdk 11.0.16.1 Android Designer EPL code available here: https://github.com/xamarin/AndroidDesigner.EPL Eclipse Temurin JDK Java SDK: /Library/Java/JavaVirtualMachines/temurin-8.jdk 1.8.0.302 Android Designer EPL code available here: https://github.com/xamarin/AndroidDesigner.EPL Android SDK Manager Version: 17.6.0.50 Hash: a715dca Branch: HEAD Build date: 2023-08-02 19:06:47 UTC Android Device Manager Version: 0.0.0.1309 Hash: 06e3e77 Branch: HEAD Build date: 2023-08-02 19:06:47 UTC Xamarin Designer Version: 17.6.3.9 Hash: 2648399ae8 Branch: remotes/origin/d17-6 Build date: 2023-08-02 19:06:42 UTC Build Information Release ID: 1706030421 Git revision: c90350679f1b9295edc584519320b13d06489853 Build date: 2023-08-02 19:05:00+00 Build branch: release-17.6 Build lane: release-17.6 Operating System Mac OS X 13.5.0 Darwin 22.6.0 Darwin Kernel Version 22.6.0 Wed Jul 5 22:22:05 PDT 2023 root:xnu-8796.141.3~6/RELEASE_ARM64_T6000 arm64
todorsp commented 11 months ago

The problem was in our code: we were clearing the web view caches in an async/await prior to setting cookies and the code was bypassing the set cookies because of an exception.