[Problem/Bug]: Prevent opening a window via CoreWebView2 NewWindowRequest doesn’t work
What happened?
If i subscribe the CoreWebView2 NewWindowRequest event and set e.Handled to true, it opens in a new window instead of doing nothing.
Importance
Blocking. My app's basic functions are not working due to this issue.
Runtime Channel
Stable release (WebView2 Runtime)
Runtime Version
122.0.2365.92
SDK Version
1.0.2151.40
Framework
WPF
Operating System
Windows 11
OS Version
22621.3296
Repro steps
-
Add Microsoft.AspNetCore.Components.WebView.Wpf NuGet to a WPF project
-
Add BlazorWebView in the MainWindow and subscribe the BlazorWebViewInitializing event
<blazor:BlazorWebView x:Name="blazorWebView" HostPage="wwwroot\Index.html" Services="{DynamicResource services}" BlazorWebViewInitializing="OnInitWebView">
<blazor:BlazorWebView.RootComponents>
<blazor:RootComponent Selector="#app" ComponentType="{x:Type local:Main}" />
</blazor:BlazorWebView.RootComponents>
</blazor:BlazorWebView>
- Subscribe CoreWebView2InitializationCompleted in the OnInitWebView event handler
private void OnInitWebView(object sender, BlazorWebViewInitializingEventArgs e)
{
blazorWebView.WebView.CoreWebView2InitializationCompleted += CoreWebView2InitializationCompleted;
}
- Subscribe NewWindowRequested in the CoreWebView2InitializationCompleted event handler and set e.Handled to true
private void CoreWebView2InitializationCompleted(object? sender, CoreWebView2InitializationCompletedEventArgs e)
{
blazorWebView.WebView.CoreWebView2.NewWindowRequested += (sender, e) =>
{
e.Handled = true;
};
}
- Start the application and drag and drop a text file on the WebView2
It opens the text file in editor instead of doing nothing.
Repros in Edge Browser
No, issue does not reproduce in the corresponding Edge version
Regression
Don't know
Last working version (if regression)
No response
I could not repro this issue in 122.0.2365.92 on my end. @neo42deg would you mind to upload your sample app?
@JosephJin0815 I can repro the issue with the attached sample app in runtime version 122.0.2365.92 and 124.0.2478.80.
Thanks. I can repro the issue with the app you uploaded. But not in WPF sample with the runtime you provided. There might be some gaps in BlazorWebView. This issue is tracked in our backlog.