WebView2Feedback icon indicating copy to clipboard operation
WebView2Feedback copied to clipboard

DownloadStarting event not firing when selecting "Save as" from context menu

Open mikkelmogensen opened this issue 1 year ago • 5 comments

What happened?

Run the code and right click a white area. Afterwards select Save as from context menu

Expected behavior: MessageBox shows

Actual behavior: MessageBox does not show

However if the google logo is rightclicked the behavior is as expected

Importance

Moderate. My app's user experience is affected, but still usable.

Runtime Channel

Stable release (WebView2 Runtime)

Runtime Version

No response

SDK Version

1.0.2526-prerelease

Framework

WPF

Operating System

Windows 11

OS Version

OS build 22621.3593

Repro steps

using System.Windows; using Microsoft.Web.WebView2.Wpf; using Microsoft.Web.WebView2.Core; public partial class App: Window { public App() { var wv = new WebView2(); Dispatcher.Invoke(() => { wv.EnsureCoreWebView2Async(null); }); Content = wv; wv.CoreWebView2InitializationCompleted += (o2, e2) => { wv.Source = new Uri("https://google.com"); wv.CoreWebView2.DownloadStarting += (o, e) => { MessageBox.Show("----"); }; }; } [STAThread] static void Main(string[] sa) { new Application().Run(new App()); } }

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

AB#51156725

mikkelmogensen avatar May 16 '24 14:05 mikkelmogensen

Hi @mikkelmogensen, can you share what you would like to accomplish using the DownloadStarting API? We are adding a separate API for handling the Save As dialog. Will this meet your needs?

cc: @Master-Ukulele

vickiez avatar May 20 '24 17:05 vickiez

@vickiez as I pointed out in issue #1090 there is no TotalBytesToReceive property available and @Master-Ukulele is correct in the fact that issue only pertains to the ui.

I would like to know how large the download is for my app, among other things to be able to warn the user if they don't have enough storage available

For completeness it seems like a fairly good idea to have SaveAs hand it off to DownloadStarting in all cases

mikkelmogensen avatar May 21 '24 13:05 mikkelmogensen

@mikkelmogensen we'll look into adding support for this scenario. Because Save As downloads are handled differently, certain properties on the DownloadStarting API like ResultFilePath might not be available. We'll share updates here

vickiez avatar May 21 '24 18:05 vickiez

After the investigation, unfortunately this scenario is not able to be supported currently. Right click a white area save as is a special case for save web page. It's handled differently because it needs to support 3 save page types. If we integrate it into the DownloadStarting as a regular download, it will lose all save page special features. This will be a breaking change, and impact many users, so, we can't support.

@mikkelmogensen - In your request, I see you want to know and control if the downloading file size is larger than the remain disk storge. Here's more details might help. The save web page special case doesn't know the real size (even if the original UI may show the size, it still depends on the real web page content). So, save page download is designed to save a temp file to a temp folder (e.g. C drive, it will assume the temp folder has enough space). After that, the process attempts to move it to user's assigned location. If this step fails because of no enough space, the process stops silently. Users won't know this happens.

In your App, is it possible to do an additional check if the file exists at the assigned location, after save page process completes? This might be a solution. Thanks for your patience.

Master-Ukulele avatar Sep 24 '24 16:09 Master-Ukulele

thanks for replying @Master-Ukulele: it might be a possible solution, but i would still need to know the final download size, perhaps by knowing the temp file/folder location somehow and then counting up all the file sizes. but like you wrote, the temp drive might not have enough storage, so knowing the size in advance would of course be preferable

this issue is somewhat similar to another issue i have raised #4609

in my app i have custom dialogs for downloadstarting, save as and preferably also screenshot that allow the user to choose drive, folder and filename. i would like to know the total download size to prevent starting a download onto a drive that does not have enough storage available and instead tell the user how much storage they need to free up before the download can be started

cc: @maurawinstanley

mikkelmogensen avatar Sep 26 '24 13:09 mikkelmogensen

@Master-Ukulele - we are also being impacted by this issue.

I'm evaluating potential workarounds but, in your previous response, you highlighted that allowing "Save As" has to "support 3 save page types". Could you claify what you mean by this so I can ensure I'm able to handle these scenarios?

ibebbs avatar Jun 18 '25 10:06 ibebbs

@ibebbs - It's by design to support 3 save page types. You can check this from context menu to save as a page: Image These 3 types deal the web page to be saved/downloaded to local with special ways. And they are default when you use context menu to "save as". DownloadStarting event is from regular download, you can also use it to save/download a web page to local, but it will work as download a regular document. Generally, there are gaps between DownloadStaring and SaveAs related events. You can use either one of them, but not together.

I'm considering this issue to be closed, as it's clear can't be supported. Please feel free to ask things about your scenario and contact @gourabkmsft for further assistance.

Master-Ukulele avatar Jun 19 '25 17:06 Master-Ukulele