MicrosoftEdge / MicrosoftEdge/WebView2Feedback

BeforeDownloadStarting event

Open
#2,890 8 comments 3 reactions 1 assignee View on GitHub

@Lakshmisha-KS is already working on this.

Since Feb 12, 2025.

feature request priority-low tracked
Dominant language
PowerShell
Stars
526
Forks
67
PR merge metrics
No merged PRs in 30d

Description

Is your feature request related to a problem? Please describe.
Say I want to intercept some type of file when downloading using the DownloadStarting event and change the local download path for it using CoreWebView2DownloadStartingEventArgs::ResultPath(newPath) and I want to keep the original file name. First, I would parse the filename from the original ResultPath, then combine that with the desired directory, and then set it as the new ResultPath. So far so good.

However, the download is already beginning concurrently in the background using default download settings by the time the DownloadStarting event gets fired. The issue now is that when in the default download location (e.g. the user's download folder) there is already a file with the same name, so WebView2 adds an index to the filename like "MyDownload (1).txt". Even though I want to save the file in a totally different location where there's no conflicting file, I get the index in the filename because WebView2 already evaluated the default download location and started the download. Then, in the DownloadStarting event I am presented only with the already modified filename. There is no way to tell if such a rename has occurred, because there is no indicator for that and the original file also may have actually been called "MyDownload (1).txt".

Another issue with the DownloadStarting event is the race condition regarding the event handlers that can be registered there for the DownloadOperation, which is described in issue #2180.

Describe the solution you'd like and alternatives you've considered
Either a completely new event BeforeDownloadStarting which has to finish before WebView2 starts downloading anything in the background which allows the developer to configure the download settings such as the local target directory and event handlers for the DownloadOperation before the download starts or - as a more mundane solution solving this particular case - two new attributes inside CoreWebView2DownloadStartingEventArgs like bool IsResultFilepathModified and hstring OriginalResultFilePath which would indicate if the ResultFilePath was modified and what its original value has been.
I definitely like the first solution better, since it also provides the possibility of registering event handlers for the upcoming DownloadOperation which will definitely get executed during the download and not be subject to a race condition.

AB#41838437

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.