Hello,
==================Update=============
System.NullReferenceException: 'Object reference not set to an instance of an object.
Please change from using Microsoft.Web.WebView2.WinForms; to using Microsoft.UI.Xaml.Controls; in the Test's background code.
MAUI that targets Windows platform uses WinUI3, you can try getting the native platform view (WebView2) with WebViewHandler on Windows, then clean cookie by CoreWebView2CookieManager.DeleteAllCookies Method. Please refer to the following code:
XML
<StackLayout>
<Button Text="ClearCookie" Clicked="Button_Clicked"></Button>
<WebView x:Name="MyWebview" Source="XXXX" HeightRequest="400" WidthRequest="400" ></WebView>
</StackLayout>
Clicking button to clean cookies.
private void Button_Clicked(object sender, EventArgs e)
{
#if WINDOWS
var platformView = MyWebview.Handler.PlatformView as WebView2;
platformView.CoreWebView2.CookieManager.DeleteAllCookies();
#endif
}
Best Regards,
Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.