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

[Problem/Bug]: Prevent opening a window via CoreWebView2 NewWindowRequest doesn’t work #4453

Open
neo42deg opened this issue Mar 26, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@neo42deg
Copy link

neo42deg commented Mar 26, 2024

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

@neo42deg neo42deg added the bug Something isn't working label Mar 26, 2024
@JosephJin0815
Copy link

I could not repro this issue in 122.0.2365.92 on my end. @neo42deg would you mind to upload your sample app?

@neo42deg
Copy link
Author

neo42deg commented May 6, 2024

@JosephJin0815 I can repro the issue with the attached sample app in runtime version 122.0.2365.92 and 124.0.2478.80.

Wpf_Blazor_Test.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants