0

我正在尝试在 UWP 应用程序中使用 PuppeteerSharp。所有依赖项似乎都很好,但我遇到了铬位置的权限问题。

Access to the path "{AppRoot}\bin\x86\Debug\AppX\.local-chromium" is denied.

UWP 中的文件权限非常有限,但我的应用程序仍然具有广泛的文件访问权限。唯一的问题是我只能通过某种用户交互(如选择器)打开文件。

有没有办法解决这个问题?

4

1 回答 1

2

如何在 UWP 应用程序中使用 PuppeteerSharp?

PuppeteerSharp在 UWP 中不支持,您可以查看 PuppeteerSharp代码来验证这一点。这是DownloadsFolder = Path.Combine(Directory.GetCurrentDirectory(), ".local-chromium")并且匹配的路径是“{AppRoot}\bin\x86\Debug\AppX.local-chromium”。在下面的代码中,我们在其中调用 Create方法,但上面的路径在 UWP 中是只读的。

    public async Task<RevisionInfo> DownloadAsync(int revision)
    {
        var url = GetDownloadURL(Platform, DownloadHost, revision);
        var zipPath = Path.Combine(DownloadsFolder, $"download-{Platform.ToString()}-{revision}.zip");
        var folderPath = GetFolderPath(revision);

        if (new DirectoryInfo(folderPath).Exists)
        {
            return RevisionInfo(revision);
        }

        var downloadFolder = new DirectoryInfo(DownloadsFolder);
        if (!downloadFolder.Exists)
        {
            downloadFolder.Create();
        }

        if (DownloadProgressChanged != null)
        {
            _webClient.DownloadProgressChanged += DownloadProgressChanged;
        }
        await _webClient.DownloadFileTaskAsync(new Uri(url), zipPath).ConfigureAwait(false);

        if (Platform == Platform.MacOS)
        {
            //ZipFile and many others unzip libraries have issues extracting .app files
            //Until we have a clear solution we'll call the native unzip tool
            //https://github.com/dotnet/corefx/issues/15516
            NativeExtractToDirectory(zipPath, folderPath);
        }
        else
        {
            ZipFile.ExtractToDirectory(zipPath, folderPath);
        }

        new FileInfo(zipPath).Delete();

        var revisionInfo = RevisionInfo(revision);

        if (revisionInfo != null && GetCurrentPlatform() == Platform.Linux)
        {
            LinuxSysCall.Chmod(revisionInfo.ExecutablePath, LinuxSysCall.ExecutableFilePermissions);
        }
        return revisionInfo;
    }
于 2019-08-09T02:38:36.870 回答