-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NullReferenceException throws on Windows when setting Cookies on .NET MAUI WebView #24846
base: main
Are you sure you want to change the base?
Conversation
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
/rebase |
7fa653b
to
e767611
Compare
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
Azure Pipelines successfully started running 3 pipeline(s). |
Azure Pipelines successfully started running 3 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
Hi @PureWeen , |
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
Azure Pipelines successfully started running 3 pipeline(s). |
@@ -366,6 +371,10 @@ void OnCoreWebView2Initialized(WebView2 sender, CoreWebView2InitializedEventArgs | |||
if (Handler is WebViewHandler handler) | |||
{ | |||
sender.UpdateUserAgent(handler.VirtualView); | |||
if (handler.PlatformView.Source is not null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could simplify the code using directly sender
instead handler.PlatformView
.
For example:
if(sender.Source is not null)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could simplify the code using directly
sender
insteadhandler.PlatformView
. For example:
if(sender.Source is not null)
Hi @jsuarezruiz,
We have simplified the source null condition based on your suggestion.
Label label = new Label(); | ||
label.AutomationId = "Label"; | ||
|
||
const string url = "https://httpbin.org/#/Cookies/get_cookies"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use a msft or dotnet url here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use a msft or dotnet url here?
Hi @PureWeen ,
We have used the Microsoft Learn documentation URL: https://learn.microsoft.com/en-us/dotnet/.
Azure Pipelines successfully started running 3 pipeline(s). |
@@ -366,6 +371,10 @@ void OnCoreWebView2Initialized(WebView2 sender, CoreWebView2InitializedEventArgs | |||
if (Handler is WebViewHandler handler) | |||
{ | |||
sender.UpdateUserAgent(handler.VirtualView); | |||
if (sender.Source is not null) | |||
{ | |||
handler.SyncPlatformCookies(handler.PlatformView.Source.ToString()).FireAndForget(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would expect here
handler.SyncPlatformCookies(handler.PlatformView.Source.ToString()).FireAndForget(); | |
handler.SyncPlatformCookies(sender.Source.ToString()).FireAndForget(); |
or not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would expect here
or not?
Hi @MartyIX ,
We have also updated the method for retrieving the SyncPlatformCookies source url.
…er platform view.
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
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
Output images
Before changes
After changes