MicrosoftEdge / MicrosoftEdge/WebView2Feedback
[Problem/Bug]: App hard-crashes if the requesting webview is disposed around the time we assign the new webview to NewWindow
@vickiez is already working on this.
Since Dec 13, 2024.
- Dominant language
- PowerShell
- Stars
- 526
- Forks
- 67
- PR merge metrics
- No merged PRs in 30d
Description
What happened?
We intercept the NewWindowRequested event and show a window with tabs. If you open a new tab (by middle-clicking a link in the first tab, say), and then quickly close the tab you're on, the app hardcrashes.
It seems that assigning e.NewWindow = newWebView.CoreWebView2 when the requesting tab/webview2 is disposed of leads to this crash
If I dispose of the first webview2 immediately in the NewWindowRequestedHandler, I get this crash:
If I dispose of it in a Task (which is more like what's happening in my app), I get this crash:
Generally, in my app (though didn't repro in the minimal example yet), I'd get this crash:
(oh I think that's the same issue as above just hitting in WebView2 code this time)
It would be nice if WebView2 handled this case for us.
What I'm having to do is grab the sender passed to NewWindowRequestedHandler and right before assigning the new WebView2 that I created to NewWindow, I check if the sender webview2 is disposed. (and also having to close the new tab that was opened to avoid a blank new tab)
Importance
Important. My app's user experience is significantly compromised.
Runtime Channel
Stable release (WebView2 Runtime)
Runtime Version
131.0.2903.70
SDK Version
1.0.2783-prerelease and 1.0.2535.41
Framework
Winforms
Operating System
Windows 11
OS Version
23H@ 22631.4460
Repro steps
- download WinForms sample app from webview2
- In
WebView2Control_CoreWebView2InitializationCompleted, addthis.webView2Control.CoreWebView2.NewWindowRequested += (sender, e) => CoreWebView2_NewWindowRequested(sender, e, false);
and below:
WebView2 _primaryWebView = null;
private async void CoreWebView2_NewWindowRequested(object sender, CoreWebView2NewWindowRequestedEventArgs e, bool fromOtherWebView)
{
e.Handled = true;
using (e.GetDeferral())
{
Form form = new Form();
form.Size = new Size(800, 600);
WebView2 webView = new WebView2();
await webView.EnsureCoreWebView2Async();
webView.CoreWebView2.NewWindowRequested += (sender, e) => CoreWebView2_NewWindowRequested(sender, e, true);
form.Controls.Add(webView);
form.Visible = true;
webView.Dock = DockStyle.Fill;
if (fromOtherWebView)
{
await Task.Run(() =>
{
_primaryWebView.Dispose(); // dispose requesting window
});
}
else
{
// save off the first webview
_primaryWebView = webView;
}
e.NewWindow = webView.CoreWebView2;
}
}
then
- start app
- open devtools and run
window.open("https://google.com") - in the Google window, middle click the About link to trigger a new window
- observe crash
Repros in Edge Browser
No, issue does not reproduce in the corresponding Edge version
Regression
No, this never worked
Last working version (if regression)
No response
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.