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

Dragging a file from Explorer over top of a WebView2 in the application window will launch another process #9650

Open
jschick04 opened this issue May 21, 2024 · 10 comments
Labels
area-WebView bug Something isn't working team-Controls Issue for the Controls team

Comments

@jschick04
Copy link

Describe the bug

I am working on a project that is basically an alternative to the Event Viewer MMC snap-in where we load evtx files and parse and display those events. Recently, I have noticed that dragging and dropping a .evtx files onto the application window is now launching an additional application process. If go into settings and change the .evtx extension default handler back to the Event View MMC then dragging and dropping a file onto the window will launch the Event Viewer MMC snap-in.

There have been no code changes to how we handle OnDrop or OnDragging and I have not been able to pinpoint any specific change around when this issue started. If I install a previous version of the app before the issue started then it does not repro but if I roll back to the commit tied to that release then I can reproduce the issue again. I have also tested previous .NET SDK versions with no success.

My suspicion is that it may be tied to the fix for the following issue that was recently resolved but do not have any hard evidence against this right now.
#7366

I have been able to reproduce this issue on a clean MAUI Hybrid project in VS 17.9.

Initially filed this over on the Maui repo but was recommended to bring this issue over here.
dotnet/maui#22556

Steps to reproduce the bug

  1. Create New Project > .NET MAUI Blazor Hybrid App
  2. Add the following to MainPage.xaml inside BlazorWebView
<BlazorWebView.GestureRecognizers>
    <DropGestureRecognizer AllowDrop="True" />
</BlazorWebView.GestureRecognizers>
  1. Run the app and drag a file over the window and 2 ghost icons will show up
    image
    Release the mouse button and the default application for the extension of the file being dragged will be launched. In the case of the above screen shot, dragging a .PML file over the window and releasing will launch procmon

Expected behavior

App should be able to handle this file via OnDrop and no other applications should be launched

Screenshots

No response

NuGet package version

None

Windows version

Windows 11 (22H2): Build 22621

Additional context

No response

@jschick04 jschick04 added the bug Something isn't working label May 21, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added the needs-triage Issue needs to be triaged by the area owners label May 21, 2024
Copy link

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one. Thank you!

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

@jschick04
Copy link
Author

If it helps, it seems like it may be EmbeddedBrowserWebView!base::LaunchProcess that is making the call to CreateProcess that results in the default extension handler in windows launching based on the extension.

kernel32.dll!CreateProcessWStub
windows.storage.dll!CInvokeCreateProcessVerb::CallCreateProcess
EmbeddedBrowserWebView.dll!base::LaunchProcess
EmbeddedBrowserWebView.dll!embedded_browser_webview::internal::WebViewFactory::EnsureConnection
EmbeddedBrowserWebView.dll!embedded_browser_webview_current::EmbeddedBrowserWebView::CreateWebViewOnIOThread
<snip>

@codendone codendone added area-WebView team-Controls Issue for the Controls team and removed needs-triage Issue needs to be triaged by the area owners labels Jun 6, 2024
@codendone codendone changed the title Dragging a file from Explorer over top of the application window will launch another process Dragging a file from Explorer over top of a WebView2 in the application window will launch another process Jun 6, 2024
@jschick04
Copy link
Author

Looks like this is the last version that doesn't reproduce the issue

<PackageReference Include="Microsoft.Maui.Controls" Version="8.0.14" />
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.14" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebView.Maui" Version="8.0.14" />

@ranjeshj ranjeshj closed this as not planned Won't fix, can't repro, duplicate, stale Jun 25, 2024
@jschick04
Copy link
Author

Curious as to why this regression is being closed as not planned? This is a major accessibility feature for our app that is widely used by CSS and not fixing this regression will result in us being unable to update to latest WebView.

@microsoft-github-policy-service microsoft-github-policy-service bot added the needs-triage Issue needs to be triaged by the area owners label Jun 28, 2024
@ranjeshj
Copy link
Contributor

ranjeshj commented Jul 3, 2024

@jschick04 apologies. I mistook your last comment that this was fixed in the last release. Could you provide a simple repro project for this in WinUI3 if possible (not MAUI) ?. EmbeddedBrowserWebview.dll is not part of WinUI. Let me follow up to find more.

@ranjeshj ranjeshj reopened this Jul 3, 2024
@jschick04
Copy link
Author

I will see if I can repro this with a WinUI project.

My app and the repro provided above was done with Maui hybrid and I initially opened an issue with Maui and was directed to this repro (issue linked in the first comment).

@jschick04
Copy link
Author

Ok, I was able to reproduce the issue by creating a WinUI3 project and adding the following to MainWindow.xaml

<WebView2 x:Name="webView" AllowDrop="True" DragOver="OnDragOver" Drop="OnDrop"></WebView2>

Inside of MainWindow.xaml.cs I replace MainWindow constructor with the following and add the OnDragOver function to allow the copy operation.

public MainWindow()
{
    InitializeComponent();

    webView.Source = new Uri("https://www.bing.com");
}

private void OnDragOver(object sender, DragEventArgs e)
{
    e.AcceptedOperation = DataPackageOperation.Copy;
}

private void OnDrop(object sender, DragEventArgs e) { }

Running the application will show the double icons as shown in the initial post. This scenario doesn't launch the default extension handler but will launch a separate window with a prompt to download the file that I drag over the application.

@ranjeshj
Copy link
Contributor

ranjeshj commented Jul 3, 2024

There is an API to intercept the new window creation – have you tried using that to see if you can achieve the experience you want? The code below works for me. It automatically downloads the file without asking for consent, but I assume that can be added in the code below if needed.

webView.CoreWebView2.NewWindowRequested += CoreWebView2_NewWindowRequested;

private void CoreWebView2_NewWindowRequested(Microsoft.Web.WebView2.Core.CoreWebView2 sender, Microsoft.Web.WebView2.Core.CoreWebView2NewWindowRequestedEventArgs args)
{
    args.Handled = true;
    this.webView.Source = new Uri(args.Uri);
}

@jschick04
Copy link
Author

Using the NewWindowRequested callback and just setting args.Handled = true prevents the new window but still shows the double icon. I can probably work around this by just disabling the icon and text from the XAML side.

I will need to see how I can adapt this to Maui Hybrid to see if it works around the issue there and to see how this interacts with the addition of the drag handlers on the web side of things. This was another issue that I ran into is the WebView2 drag/drop functionality did not play well with Blazor Hybrid but that is another issue for when we can go back to using the most recent version of WebView2.

Ideally it seems that WebView2 should respect the drag/drop handlers from the XAML side or XAML should defer to WebView2 if that is where the drag/drop functionality is going to have to be configured. Or maybe a global option to configure XAML or WebView2 as the default handler for drag/drop, especially since it looks like the addition of drag/drop functionality from WebView2 is where this all started.

@jschick04
Copy link
Author

Looks like this workaround isn't viable for Maui or at least I cannot find the NewWindowRequested callback for how this is implemented with Maui Hybrid.

@codendone codendone removed the needs-triage Issue needs to be triaged by the area owners label Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-WebView bug Something isn't working team-Controls Issue for the Controls team
Projects
None yet
Development

No branches or pull requests

3 participants