0

I'm trying to use PuppeteerSharp inside an UWP app. All the dependencies seem fine but I got a permission problem with the location of chromium.

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

File permission is very restricted in UWP but my app has broadFileAccess anyways. The only thing is that I can only open a file with some kind of user interaction like a picker.

Is there a way to work around this?

jurihandl
  • 665
  • 1
  • 9
  • 24

1 Answers1

2

How to use PuppeteerSharp inside an UWP App?

PuppeteerSharp does not support in UWP, You could check PuppeteerSharp source code to verify this. This is DownloadsFolder = Path.Combine(Directory.GetCurrentDirectory(), ".local-chromium") and matched path is "{AppRoot}\bin\x86\Debug\AppX.local-chromium". In the following code we call Create method in it, but above path is read-only in 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;
    }
Nico Zhu
  • 32,367
  • 2
  • 15
  • 36