I'm trying to support file downloads on a UWP WebView2.
Not sure whether I'm doing something wrong or if this a bug, but I keep getting state change update to Interrupted with reason UserCanceled.
Here's how I'm testing it on the main page:
public MainPage()
{
this.InitializeComponent();
wv2.EnsureCoreWebView2Async().AsTask().ContinueWith(async (task) =>
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
() =>
{
wv2.CoreWebView2.DownloadStarting += OnDownloadStarting;
wv2.CoreWebView2.Navigate("http://demo.borland.com/testsite/downloads/downloadfile.php?file=dotNetFx40_Full_x86_x64.exe&cd=attachment+filename");
});
});
}
private void OnDownloadStarting(Microsoft.Web.WebView2.Core.CoreWebView2 sender, Microsoft.Web.WebView2.Core.CoreWebView2DownloadStartingEventArgs args)
{
Trace.WriteLine("DownloadStarting");
var downloadOp = args.DownloadOperation;
args.DownloadOperation.StateChanged += (sender2, args2) =>
{
var state = downloadOp.State;
switch (state)
{
case Microsoft.Web.WebView2.Core.CoreWebView2DownloadState.InProgress:
Trace.WriteLine("Download StateChanged: InProgress");
break;
case Microsoft.Web.WebView2.Core.CoreWebView2DownloadState.Completed:
Trace.WriteLine("Download StateChanged: Completed");
break;
case Microsoft.Web.WebView2.Core.CoreWebView2DownloadState.Interrupted:
Trace.WriteLine("Download StateChanged: Interrupted, reason: " + downloadOp.InterruptReason);
break;
}
};
}
I also tried setting the ResultFilePath to the TemporaryFolder or to the user's DownloadsFolder and gave the app these restricted capabilities <rescap:Capability Name="broadFileSystemAccess" /> and <rescap:Capability Name="runFullTrust" />.
But I consistently keep getting a single state update to the same Interrupted UserCanceled error.
Here's a sample project demonstrating the problem: https://github.com/nirbil/WebView2FileDownload
Any ideas?