如何在 UWP WebView2 上下载文件?

How to download a file on a UWP WebView2?

我正在尝试支持 UWP WebView2 上的文件下载。
不确定我是否做错了什么或者这是一个错误,但我不断将状态更改更新为 Interrupted with reason UserCanceled。

以下是我在主页上对其进行测试的方式:

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;
            }
        };
    }

我还尝试将 ResultFilePath 设置为 TemporaryFolder 或用户的 DownloadsFolder,并为应用程序提供这些受限功能 <rescap:Capability Name="broadFileSystemAccess" /><rescap:Capability Name="runFullTrust" />
但是我一直不断地对同一个 Interrupted UserCanceled 错误进行单一状态更新。

这是一个演示问题的示例项目:https://github.com/nirbil/WebView2FileDownload

有什么想法吗?

But I consistently keep getting a single state update to the same Interrupted UserCanceled error.

WebView2 下载文件known issue。我发现边缘成员已经确认了这一点。 我们有一个已知问题,即下载尚未在 UWP 中运行(由于文件权限)。我们已经在着手修复,应该会在下个月内进行测试。我将我们现有的工作与这个问题联系起来,以跟踪它何时完成。谢谢!请关注后续更新