Skip to content

Commit

Permalink
Return whether the permissions fix was executed successfully (#2754)
Browse files Browse the repository at this point in the history
  • Loading branch information
kblok authored Aug 29, 2024
1 parent 3315b38 commit a4f43fa
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
8 changes: 8 additions & 0 deletions lib/PuppeteerSharp/BrowserData/InstalledBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ internal InstalledBrowser(Cache cache, SupportedBrowser browser, string buildId,
/// </summary>
public Platform Platform { get; set; }

/// <summary>
/// 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.
/// </summary>
public bool? PermissionsFixed { get; internal set; }

/// <summary>
/// Revision platform.
/// </summary>
Expand Down
13 changes: 9 additions & 4 deletions lib/PuppeteerSharp/BrowserFetcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ private async Task<InstalledBrowser> 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;
}

Expand All @@ -267,11 +267,11 @@ private async Task<InstalledBrowser> 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 (
Expand All @@ -285,7 +285,7 @@ installedBrowser.Platform is Platform.Win32 or Platform.Win64 &&

if (!File.Exists(setupExePath))
{
return;
return false;
}

using var process = new Process();
Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions lib/PuppeteerSharp/PuppeteerSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
<Description>Headless Browser .NET API</Description>
<PackageId>PuppeteerSharp</PackageId>
<PackageReleaseNotes></PackageReleaseNotes>
<PackageVersion>19.0.1</PackageVersion>
<ReleaseVersion>19.0.1</ReleaseVersion>
<AssemblyVersion>19.0.1</AssemblyVersion>
<FileVersion>19.0.1</FileVersion>
<PackageVersion>19.0.2</PackageVersion>
<ReleaseVersion>19.0.2</ReleaseVersion>
<AssemblyVersion>19.0.2</AssemblyVersion>
<FileVersion>19.0.2</FileVersion>
<SynchReleaseVersion>false</SynchReleaseVersion>
<StyleCopTreatErrorsAsWarnings>false</StyleCopTreatErrorsAsWarnings>
<DebugType>embedded</DebugType>
Expand Down

0 comments on commit a4f43fa

Please sign in to comment.