Skip to content

NullReferenceException throws on Windows when setting Cookies on .NET MAUI WebView#24846

Merged
jfversluis merged 18 commits intodotnet:mainfrom
NanthiniMahalingam:issue-18452
Nov 26, 2024
Merged

NullReferenceException throws on Windows when setting Cookies on .NET MAUI WebView#24846
jfversluis merged 18 commits intodotnet:mainfrom
NanthiniMahalingam:issue-18452

Conversation

@NanthiniMahalingam
Copy link
Copy Markdown
Contributor

@NanthiniMahalingam NanthiniMahalingam commented Sep 20, 2024

Root Cause

While setting a cookie in MAUI WebView, CoreWebView2 is null before the CoreWebView2Initialized event triggered.

Description of Change

Added the null condition for CoreWebView2 property while sync platform cookie method.

Issues Fixed

Fixes #18452

Validated the behaviour in the following platforms

  • Android
  • Windows
  • iOS
  • Mac

Output images
Before changes
image

After changes
image

@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Sep 20, 2024
@jfversluis
Copy link
Copy Markdown
Member

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 3 pipeline(s).

@NanthiniMahalingam NanthiniMahalingam marked this pull request as ready for review September 23, 2024 05:03
@NanthiniMahalingam NanthiniMahalingam requested a review from a team as a code owner September 23, 2024 05:03
@rmarinho
Copy link
Copy Markdown
Member

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 3 pipeline(s).

@rmarinho
Copy link
Copy Markdown
Member

/rebase

@rmarinho
Copy link
Copy Markdown
Member

rmarinho commented Sep 27, 2024

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 3 pipeline(s).

@rmarinho rmarinho modified the milestones: .NET 9 Planning, .NET 8 SR9 Sep 27, 2024
@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 3 pipeline(s).

1 similar comment
@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 3 pipeline(s).

@PureWeen PureWeen modified the milestones: .NET 8 SR9, .NET 9 SR1 Oct 1, 2024
@rmarinho
Copy link
Copy Markdown
Member

rmarinho commented Oct 3, 2024

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 3 pipeline(s).

Copy link
Copy Markdown
Member

@PureWeen PureWeen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies

By under I just meant switch the place of the call here

image

So change the code to be

UpdateUserAgent
webViewHandler.SyncPlatformCookies(platformWebView.CoreWebView2.Source).FireAndForget();

vs

webViewHandler.SyncPlatformCookies(platformWebView.CoreWebView2.Source).FireAndForget();
UpdateUserAgent

if (Handler is WebViewHandler handler && handler.VirtualView is not null)
{
sender.UpdateUserAgent(handler.VirtualView);
handler.SyncPlatformCookies(sender.CoreWebView2.Source).FireAndForget();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the source will be set to the right value at this point

image

For the UItest can you add a part that validates the cookie was set?

like maybe after navigated has fired you can read from the cookies to see if the cookie you added is present?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've added cookie validation to the UI test as per your suggestion. Could you please verify once?

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 3 pipeline(s).

@PureWeen
Copy link
Copy Markdown
Member

/azp run

@NanthiniMahalingam
Copy link
Copy Markdown
Contributor Author

/rebase

@jsuarezruiz
Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 3 pipeline(s).

@jfversluis jfversluis merged commit f115e57 into dotnet:main Nov 26, 2024
@sheiksyedm sheiksyedm added the partner/syncfusion Issues / PR's with Syncfusion collaboration label Dec 6, 2024
@samhouts samhouts added fixed-in-9.0.21 fixed-in-net8.0-nightly This may be available in a nightly release! labels Dec 16, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Jan 17, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

community ✨ Community Contribution fixed-in-9.0.21 fixed-in-net8.0-nightly This may be available in a nightly release! partner/syncfusion Issues / PR's with Syncfusion collaboration platform/windows

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[regression/8.0.0-rc.2.9373] Setting Cookies on .NET MAUI WebView on Windows throws NullReferenceException

8 participants