MicrosoftEdge / MicrosoftEdge/WebView2Feedback
[Problem/Bug]: Prevent opening a window via CoreWebView2 NewWindowRequest doesn’t work
@JosephJin0815 is already working on this.
Since Apr 11, 2024.
- Dominant language
- PowerShell
- Stars
- 526
- Forks
- 67
- PR merge metrics
- No merged PRs in 30d
Description
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
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.