From 5feb2c1d300fe07e0b598d776390bd62d753c391 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Kondratiuk?= Date: Wed, 28 Aug 2024 11:49:40 -0300 Subject: [PATCH] Return whether the permissions fix was executed successfully --- lib/PuppeteerSharp/BrowserData/InstalledBrowser.cs | 8 ++++++++ lib/PuppeteerSharp/BrowserFetcher.cs | 13 +++++++++---- lib/PuppeteerSharp/PuppeteerSharp.csproj | 8 ++++---- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/lib/PuppeteerSharp/BrowserData/InstalledBrowser.cs b/lib/PuppeteerSharp/BrowserData/InstalledBrowser.cs index dff41b1b4..8f0b52dbf 100644 --- a/lib/PuppeteerSharp/BrowserData/InstalledBrowser.cs +++ b/lib/PuppeteerSharp/BrowserData/InstalledBrowser.cs @@ -38,6 +38,14 @@ internal InstalledBrowser(Cache cache, SupportedBrowser browser, string buildId, /// public Platform Platform { get; set; } + /// + /// Whether the permissions have been fixed in the browser. + /// If Puppeteer executed the command to fix the permissions, this will be true. + /// If Puppeteer failed to fix the permissions, this will be false. + /// If the platform does not require permissions to be fixed, this will be null. + /// + public bool? PermissionsFixed { get; internal set; } + /// /// Revision platform. /// diff --git a/lib/PuppeteerSharp/BrowserFetcher.cs b/lib/PuppeteerSharp/BrowserFetcher.cs index b3393b0b3..f70f6d9f4 100644 --- a/lib/PuppeteerSharp/BrowserFetcher.cs +++ b/lib/PuppeteerSharp/BrowserFetcher.cs @@ -250,7 +250,7 @@ private async Task DownloadAsync(SupportedBrowser browser, str if (new DirectoryInfo(outputPath).Exists) { var existingBrowser = new InstalledBrowser(cache, browser, buildId, Platform); - RunSetup(existingBrowser); + existingBrowser.PermissionsFixed = RunSetup(existingBrowser); return existingBrowser; } @@ -267,11 +267,11 @@ private async Task DownloadAsync(SupportedBrowser browser, str new FileInfo(archivePath).Delete(); var installedBrowser = new InstalledBrowser(cache, browser, buildId, Platform); - RunSetup(installedBrowser); + installedBrowser.PermissionsFixed = RunSetup(installedBrowser); return installedBrowser; } - private void RunSetup(InstalledBrowser installedBrowser) + private bool? RunSetup(InstalledBrowser installedBrowser) { // On Windows for Chrome invoke setup.exe to configure sandboxes. if ( @@ -285,7 +285,7 @@ installedBrowser.Platform is Platform.Win32 or Platform.Win64 && if (!File.Exists(setupExePath)) { - return; + return false; } using var process = new Process(); @@ -295,12 +295,17 @@ installedBrowser.Platform is Platform.Win32 or Platform.Win64 && process.StartInfo.UseShellExecute = false; process.Start(); process.WaitForExit(); + + return true; } catch (Exception ex) { _logger?.LogError(ex, "Failed to run setup.exe"); + return false; } } + + return null; } private async Task InstallDmgAsync(string dmgPath, string folderPath) diff --git a/lib/PuppeteerSharp/PuppeteerSharp.csproj b/lib/PuppeteerSharp/PuppeteerSharp.csproj index dbc981596..271d343e9 100644 --- a/lib/PuppeteerSharp/PuppeteerSharp.csproj +++ b/lib/PuppeteerSharp/PuppeteerSharp.csproj @@ -12,10 +12,10 @@ Headless Browser .NET API PuppeteerSharp - 19.0.1 - 19.0.1 - 19.0.1 - 19.0.1 + 19.0.2 + 19.0.2 + 19.0.2 + 19.0.2 false false embedded