如何在UWP应用中使用PuppeteerSharp?

时间:2019-08-08 13:02:18

标签: c# uwp puppeteer-sharp

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

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

在UWP中,文件许可权非常受限制,但是我的应用程序仍然具有broadFileAccess。唯一的是,我只能通过某种用户交互(例如选择器)打开文件。

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

1 个答案:

答案 0 :(得分:1)

  

如何在UWP App中使用PuppeteerSharp?

PuppeteerSharp 在UWP中不受支持,您可以检查PuppeteerSharp source代码以进行验证。这是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;
    }