MicrosoftEdge / MicrosoftEdge/WebView2Feedback
Download API: StateChanged event not fired if downloading file is locked.
Nobody has claimed this yet.
- Dominant language
- PowerShell
- Stars
- 526
- Forks
- 67
- PR merge metrics
- No merged PRs in 30d
Description
Description
When I download a file and WebView2 decides that the file could harm the device, StateChanged event is not fired.
Version
SDK: 1.0.865.0-prerelease
Runtime: 92.0.891.1 Dev
Framework: WinForms
OS: Win10
Repro Steps
I mostly used the code from CustomDownload.md document.
private void DownloadStarting(object sender, CoreWebView2DownloadStartingEventArgs e)
{
// create download id
var random = new Random();
int downloadID = random.Next();
// https://github.com/MicrosoftEdge/WebView2Feedback/blob/master/specs/CustomDownload.md
// Developer can obtain a deferral for the event so that the CoreWebView2
// doesn't examine the properties we set on the event args until
// after the deferral completes asynchronously.
CoreWebView2Deferral deferral = e.GetDeferral();
// We avoid potential reentrancy from running a message loop in the download
// starting event handler by showing our download dialog later when we
// complete the deferral asynchronously.
System.Threading.SynchronizationContext.Current.Post((_) =>
{
using (deferral)
{
UpdateDownloadProgress(e.DownloadOperation, downloadID);
}
}, null);
}
private void UpdateDownloadProgress(CoreWebView2DownloadOperation download, int downloadID)
{
download.BytesReceivedChanged += delegate (object sender, Object e)
{
// this event is fired ok.
Log(downloadID, download.BytesReceived, download.TotalBytesToReceive);
};
download.StateChanged += delegate (object sender, Object e)
{
// this event is not fired if downloadable file was marked as dangerous.
Log(downloadID, download.State, download.InterruptReason);
};
}
}
Screenshots
The screenshot shows "the file is locked because it could harm the device" message at the bottom.

Additional context
Also if I select "Leave" option to not delete the file, WebView2 opens empty window, only with url "edge://downloads/apprep?id=53" in address bar.
When I close the window with WebView2 (that window with download link), downloaded file is deleted from Downloads folder, even I choosed to leave it.
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.
Research direction
Start with the CustomDownload.md document and the DownloadStarting and UpdateDownloadProgress methods in the repro. Reproduce a download blocked as dangerous, then compare StateChanged, InterruptReason, and the Leave behavior with a normal download. Done means the blocked download's state and resulting file behavior are consistently observable and documented or corrected.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api, desktop
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100