Skip to content
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

[Windows] Fix crash in WebView updating the Source two times in a row #10456

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/Core/src/Platform/Windows/MauiWebView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ public async void LoadHtml(string? html, string? baseUrl)
// calling EnsureCoreWebView2Async().
await _internalWebView.EnsureCoreWebView2Async();

// When the 'navigation' to the original HTML string is done, we can modify it to include our <base> tag
// When the 'navigation' to the original HTML string is done,
// we can modify it to include our <base> tag
_internalWebView.NavigationCompleted += async (sender, args) =>
{
// Generate a version of the <base> script with the correct <base> tag
Expand Down Expand Up @@ -99,11 +100,19 @@ public async void LoadHtml(string? html, string? baseUrl)
NavigateToString(!string.IsNullOrEmpty(htmlWithBaseTag) ? htmlWithBaseTag : html);

// Free up memory after we're done with _internalWebView
_internalWebView = null;

if (_internalWebView != null && _internalWebView.CoreWebView2 != null)
{
_internalWebView.Close();
_internalWebView = null;
}
};

// Kick off the initial navigation
_internalWebView.NavigateToString(html);
_internalWebView.CoreWebView2Initialized += (sender, args) =>
Copy link
Member

Choose a reason for hiding this comment

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

Don't we need to unsubscribe this ?

{
// Kick off the initial navigation
_internalWebView.NavigateToString(html);
};
}

public async void LoadUrl(string? url)
Expand Down