From 42b1fd036c94205a1dd3c1bea9c016086cc98547 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Kondratiuk?= Date: Thu, 6 Jun 2024 07:26:20 -0400 Subject: [PATCH] Fix chromium version fetcher (#2654) --- lib/PuppeteerSharp/BrowserFetcher.cs | 10 +++++++--- lib/PuppeteerSharp/Launcher.cs | 11 ++++++++--- lib/PuppeteerSharp/PuppeteerSharp.csproj | 6 +++--- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/lib/PuppeteerSharp/BrowserFetcher.cs b/lib/PuppeteerSharp/BrowserFetcher.cs index 6a5f190fc..7f4b2ff88 100644 --- a/lib/PuppeteerSharp/BrowserFetcher.cs +++ b/lib/PuppeteerSharp/BrowserFetcher.cs @@ -102,9 +102,13 @@ public async Task CanDownloadAsync(string revision) /// public async Task DownloadAsync() { - var buildId = Browser == SupportedBrowser.Firefox - ? await Firefox.GetDefaultBuildIdAsync().ConfigureAwait(false) - : Chrome.DefaultBuildId; + var buildId = Browser switch + { + SupportedBrowser.Firefox => await Firefox.GetDefaultBuildIdAsync().ConfigureAwait(false), + SupportedBrowser.Chrome or SupportedBrowser.ChromeHeadlessShell => Chrome.DefaultBuildId, + SupportedBrowser.Chromium => await Chromium.ResolveBuildIdAsync(Platform).ConfigureAwait(false), + _ => throw new PuppeteerException($"{Browser} not supported."), + }; return await DownloadAsync(buildId).ConfigureAwait(false); } diff --git a/lib/PuppeteerSharp/Launcher.cs b/lib/PuppeteerSharp/Launcher.cs index f26353570..ef0e7b7a4 100644 --- a/lib/PuppeteerSharp/Launcher.cs +++ b/lib/PuppeteerSharp/Launcher.cs @@ -50,9 +50,14 @@ public async Task LaunchAsync(LaunchOptions options) EnsureSingleLaunchOrConnect(); _browser = options.Browser; - var executable = options.ExecutablePath ?? GetExecutablePath( - options, - options.Browser == SupportedBrowser.Firefox ? await Firefox.GetDefaultBuildIdAsync().ConfigureAwait(false) : Chrome.DefaultBuildId); + var buildId = options.Browser switch + { + SupportedBrowser.Firefox => await Firefox.GetDefaultBuildIdAsync().ConfigureAwait(false), + SupportedBrowser.Chrome or SupportedBrowser.ChromeHeadlessShell => Chrome.DefaultBuildId, + SupportedBrowser.Chromium => await Chromium.ResolveBuildIdAsync(BrowserFetcher.GetCurrentPlatform()).ConfigureAwait(false), + _ => throw new ArgumentException("Invalid browser"), + }; + var executable = options.ExecutablePath ?? GetExecutablePath(options, buildId); Process = options.Browser switch { diff --git a/lib/PuppeteerSharp/PuppeteerSharp.csproj b/lib/PuppeteerSharp/PuppeteerSharp.csproj index 9374ee3db..2516f5110 100644 --- a/lib/PuppeteerSharp/PuppeteerSharp.csproj +++ b/lib/PuppeteerSharp/PuppeteerSharp.csproj @@ -12,9 +12,9 @@ Headless Browser .NET API PuppeteerSharp - 18.0.0 - 18.0.0 - 18.0.0 + 18.0.1 + 18.0.1 + 18.0.1 18.0.0 false false