Skip to content

Commit

Permalink
Bump chrome to 127 (#2717)
Browse files Browse the repository at this point in the history
* Bump chrome to 127

* Prepare package for beta

* Add optional logger
  • Loading branch information
kblok authored Aug 5, 2024
1 parent f5ebfa6 commit c4c67db
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lib/PuppeteerSharp.Tests/PuppeteerSharp.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.4" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.5" />
<PackageReference Include="Microsoft.AspNetCore.Connections.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="7.0.0" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion lib/PuppeteerSharp/BrowserData/Chrome.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static class Chrome
/// <summary>
/// Default chrome build.
/// </summary>
public static string DefaultBuildId => "124.0.6367.201";
public static string DefaultBuildId => "127.0.6533.88";

internal static async Task<string> ResolveBuildIdAsync(ChromeReleaseChannel channel)
=> (await GetLastKnownGoodReleaseForChannel(channel).ConfigureAwait(false)).Version;
Expand Down
55 changes: 48 additions & 7 deletions lib/PuppeteerSharp/BrowserFetcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using PuppeteerSharp.BrowserData;
using PuppeteerSharp.Helpers;
using PuppeteerSharp.Helpers.Linux;
Expand All @@ -30,6 +31,7 @@ public sealed class BrowserFetcher : IBrowserFetcher
};

private readonly CustomFileDownloadAction _customFileDownload;
private readonly ILogger<BrowserFetcher> _logger;

/// <inheritdoc cref="BrowserFetcher"/>
public BrowserFetcher()
Expand All @@ -41,12 +43,13 @@ public BrowserFetcher()
}

/// <inheritdoc cref="BrowserFetcher"/>
public BrowserFetcher(SupportedBrowser browser) : this(new BrowserFetcherOptions { Browser = browser })
public BrowserFetcher(SupportedBrowser browser, ILoggerFactory loggerFactory = null)
: this(new BrowserFetcherOptions { Browser = browser }, loggerFactory)
{
}

/// <inheritdoc cref="BrowserFetcher"/>
public BrowserFetcher(BrowserFetcherOptions options)
public BrowserFetcher(BrowserFetcherOptions options, ILoggerFactory loggerFactory = null)
{
if (options == null)
{
Expand All @@ -57,6 +60,7 @@ public BrowserFetcher(BrowserFetcherOptions options)
CacheDir = string.IsNullOrEmpty(options.Path) ? GetBrowsersLocation() : options.Path;
Platform = options.Platform ?? GetCurrentPlatform();
_customFileDownload = options.CustomFileDownload ?? DownloadFileUsingHttpClientTaskAsync;
_logger = loggerFactory?.CreateLogger<BrowserFetcher>();
}

/// <inheritdoc/>
Expand Down Expand Up @@ -93,8 +97,9 @@ public async Task<bool> CanDownloadAsync(string revision)
using var response = await client.SendAsync(requestMessage).ConfigureAwait(false);
return response.StatusCode == HttpStatusCode.OK;
}
catch (HttpRequestException)
catch (HttpRequestException ex)
{
_logger?.LogError(ex, $"Failed to check download {Browser} for {Platform} from {BaseUrl}");
return false;
}
}
Expand Down Expand Up @@ -246,7 +251,9 @@ private async Task<InstalledBrowser> DownloadAsync(SupportedBrowser browser, str

if (new DirectoryInfo(outputPath).Exists)
{
return new InstalledBrowser(cache, browser, buildId, Platform);
var existingBrowser = new InstalledBrowser(cache, browser, buildId, Platform);
RunSetup(existingBrowser);
return existingBrowser;
}

try
Expand All @@ -261,7 +268,41 @@ private async Task<InstalledBrowser> DownloadAsync(SupportedBrowser browser, str
await UnpackArchiveAsync(archivePath, outputPath, fileName).ConfigureAwait(false);
new FileInfo(archivePath).Delete();

return new InstalledBrowser(cache, browser, buildId, Platform);
var installedBrowser = new InstalledBrowser(cache, browser, buildId, Platform);
RunSetup(installedBrowser);
return installedBrowser;
}

private void RunSetup(InstalledBrowser installedBrowser)
{
// On Windows for Chrome invoke setup.exe to configure sandboxes.
if (
installedBrowser.Platform is Platform.Win32 or Platform.Win64 &&
installedBrowser.Browser == SupportedBrowser.Chrome && installedBrowser.Platform == GetCurrentPlatform())
{
try
{
var browserDir = new FileInfo(installedBrowser.GetExecutablePath()).Directory;
var setupExePath = Path.Combine(browserDir!.FullName, "setup.exe");

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

using var process = new Process();
process.StartInfo.FileName = setupExePath;
process.StartInfo.Arguments = $"--configure-browser-in-directory=\"{browserDir.FullName}\"";
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.UseShellExecute = false;
process.Start();
process.WaitForExit();
}
catch (Exception ex)
{
_logger?.LogError(ex, "Failed to run setup.exe");
}
}
}

private async Task InstallDmgAsync(string dmgPath, string folderPath)
Expand Down Expand Up @@ -337,9 +378,9 @@ private void UnmountDmg(string dmgPath)
process.Start();
process.WaitForExit();
}
catch
catch (Exception ex)
{
// swallow
_logger?.LogError(ex, "Failed to unmount dmg");
}
}

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>18.0.5</PackageVersion>
<ReleaseVersion>18.0.5</ReleaseVersion>
<AssemblyVersion>18.0.5</AssemblyVersion>
<FileVersion>18.0.5</FileVersion>
<PackageVersion>18.1.0-beta1</PackageVersion>
<ReleaseVersion>18.1.0</ReleaseVersion>
<AssemblyVersion>18.1.0</AssemblyVersion>
<FileVersion>18.1.0</FileVersion>
<SynchReleaseVersion>false</SynchReleaseVersion>
<StyleCopTreatErrorsAsWarnings>false</StyleCopTreatErrorsAsWarnings>
<DebugType>embedded</DebugType>
Expand Down

0 comments on commit c4c67db

Please sign in to comment.