Skip to content

Commit 676edec

Browse files
authored
Switch to Firefox stable version (#2662)
* Switch to Firefox stable version * Improve platform fetching * Fix some firefox tests * fix windows
1 parent 3fe756c commit 676edec

File tree

3 files changed

+45
-20
lines changed

3 files changed

+45
-20
lines changed
Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
using System;
21
using System.IO;
32
using NUnit.Framework;
4-
using PuppeteerSharp.BrowserData;
53
using PuppeteerSharp.Nunit;
64

75
namespace PuppeteerSharp.Tests.Browsers.Firefox
@@ -12,19 +10,19 @@ public class FirefoxDataTests
1210
public void ShouldResolveDownloadUrls()
1311
{
1412
Assert.AreEqual(
15-
"https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central/firefox-111.0a1.en-US.linux-x86_64.tar.bz2",
13+
"https://archive.mozilla.org/pub/firefox/releases/111.0a1/linux-x86_64/en-US/firefox-111.0a1.tar.bz2",
1614
BrowserData.Firefox.ResolveDownloadUrl(Platform.Linux, "111.0a1", null));
1715
Assert.AreEqual(
18-
"https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central/firefox-111.0a1.en-US.mac.dmg",
16+
"https://archive.mozilla.org/pub/firefox/releases/111.0a1/mac/en-US/Firefox 111.0a1.dmg",
1917
BrowserData.Firefox.ResolveDownloadUrl(Platform.MacOS, "111.0a1", null));
2018
Assert.AreEqual(
21-
"https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central/firefox-111.0a1.en-US.mac.dmg",
19+
"https://archive.mozilla.org/pub/firefox/releases/111.0a1/mac/en-US/Firefox 111.0a1.dmg",
2220
BrowserData.Firefox.ResolveDownloadUrl(Platform.MacOSArm64, "111.0a1", null));
2321
Assert.AreEqual(
24-
"https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central/firefox-111.0a1.en-US.win32.zip",
22+
"https://archive.mozilla.org/pub/firefox/releases/111.0a1/win32/en-US/Firefox Setup 111.0a1.exe",
2523
BrowserData.Firefox.ResolveDownloadUrl(Platform.Win32, "111.0a1", null));
2624
Assert.AreEqual(
27-
"https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central/firefox-111.0a1.en-US.win64.zip",
25+
"https://archive.mozilla.org/pub/firefox/releases/111.0a1/win64/en-US/Firefox Setup 111.0a1.exe",
2826
BrowserData.Firefox.ResolveDownloadUrl(Platform.Win64, "111.0a1", null));
2927
}
3028

@@ -37,7 +35,7 @@ public void ShouldResolveExecutablePath()
3735

3836
Assert.AreEqual(
3937
Path.Combine(
40-
"Firefox Nightly.app",
38+
"Firefox.app",
4139
"Contents",
4240
"MacOS",
4341
"firefox"
@@ -46,20 +44,20 @@ public void ShouldResolveExecutablePath()
4644

4745
Assert.AreEqual(
4846
Path.Combine(
49-
"Firefox Nightly.app",
47+
"Firefox.app",
5048
"Contents",
5149
"MacOS",
5250
"firefox"
5351
),
5452
BrowserData.Firefox.RelativeExecutablePath(Platform.MacOSArm64, "111.0a1"));
5553

5654
Assert.AreEqual(
57-
Path.Combine("firefox", "firefox.exe"),
55+
Path.Combine("core", "firefox.exe"),
5856
BrowserData.Firefox.RelativeExecutablePath(Platform.Win32, "111.0a1"));
5957

6058
Assert.AreEqual(
6159
BrowserData.Firefox.RelativeExecutablePath(Platform.Win64, "111.0a1"),
62-
Path.Combine("firefox", "firefox.exe"));
60+
Path.Combine("core", "firefox.exe"));
6361
}
6462
}
6563
}

lib/PuppeteerSharp/BrowserData/Firefox.cs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ public static class Firefox
1515
/// <summary>
1616
/// Default firefox build.
1717
/// </summary>
18-
public const string DefaultBuildId = "FIREFOX_NIGHTLY";
18+
public const string DefaultBuildId = "128.0b5";
1919

2020
private static readonly Dictionary<string, string> _cachedBuildIds = [];
2121

22-
internal static Task<string> GetDefaultBuildIdAsync() => ResolveBuildIdAsync(DefaultBuildId);
22+
internal static Task<string> GetDefaultBuildIdAsync() => Task.FromResult(DefaultBuildId);
2323

2424
internal static string ResolveDownloadUrl(Platform platform, string buildId, string baseUrl)
2525
=>
26-
$"{baseUrl ?? "https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central"}/{string.Join("/", ResolveDownloadPath(platform, buildId))}";
26+
$"{baseUrl ?? "https://archive.mozilla.org/pub/firefox/releases"}/{string.Join("/", ResolveDownloadPath(platform, buildId))}";
2727

2828
internal static async Task<string> ResolveBuildIdAsync(string channel)
2929
{
@@ -49,12 +49,12 @@ internal static string RelativeExecutablePath(Platform platform, string buildId)
4949
=> platform switch
5050
{
5151
Platform.MacOS or Platform.MacOSArm64 => Path.Combine(
52-
"Firefox Nightly.app",
52+
"Firefox.app",
5353
"Contents",
5454
"MacOS",
5555
"firefox"),
5656
Platform.Linux => Path.Combine("firefox", "firefox"),
57-
Platform.Win32 or Platform.Win64 => Path.Combine("firefox", "firefox.exe"),
57+
Platform.Win32 or Platform.Win64 => Path.Combine("core", "firefox.exe"),
5858
_ => throw new ArgumentException("Invalid platform", nameof(platform)),
5959
};
6060

@@ -74,17 +74,27 @@ internal static void CreateProfile(string tempUserDataDirectory, Dictionary<stri
7474
}
7575

7676
private static string[] ResolveDownloadPath(Platform platform, string buildId)
77-
=> new string[] { GetArchive(platform, buildId), };
77+
=> [buildId, GetFirefoxPlatform(platform), "en-US", GetArchive(platform, buildId)];
78+
79+
private static string GetFirefoxPlatform(Platform platform)
80+
=> platform switch
81+
{
82+
Platform.Linux => "linux-x86_64",
83+
Platform.MacOS or Platform.MacOSArm64 => "mac",
84+
Platform.Win32 => "win32",
85+
Platform.Win64 => "win64",
86+
_ => throw new PuppeteerException($"Unknown platform: {platform}"),
87+
};
7888

7989
private static string GetArchive(Platform platform, string buildId)
8090
=> platform switch
8191
{
82-
Platform.Linux => $"firefox-{buildId}.en-US.{platform.ToString().ToLowerInvariant()}-x86_64.tar.bz2",
83-
Platform.MacOS or Platform.MacOSArm64 => $"firefox-{buildId}.en-US.mac.dmg",
92+
Platform.Linux => $"firefox-{buildId}.tar.bz2",
93+
Platform.MacOS or Platform.MacOSArm64 => $"Firefox {buildId}.dmg",
8494

8595
// Windows archive name changed at r591479.
8696
Platform.Win32 or Platform.Win64 =>
87-
$"firefox-{buildId}.en-US.{platform.ToString().ToLowerInvariant()}.zip",
97+
$"Firefox Setup {buildId}.exe",
8898
_ => throw new PuppeteerException($"Unknown platform: {platform}"),
8999
};
90100

lib/PuppeteerSharp/BrowserFetcher.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,19 @@ private static void ExtractTar(string zipPath, string folderPath)
216216
process.WaitForExit();
217217
}
218218

219+
private static void ExecuteSetup(string exePath, string folderPath)
220+
{
221+
new DirectoryInfo(folderPath).Create();
222+
using var process = new Process();
223+
process.StartInfo.FileName = exePath;
224+
process.StartInfo.Arguments = $"/ExtractDir={folderPath}";
225+
process.StartInfo.EnvironmentVariables.Add("__compat_layer", "RuAsInvoker");
226+
process.StartInfo.RedirectStandardOutput = true;
227+
process.StartInfo.UseShellExecute = false;
228+
process.Start();
229+
process.WaitForExit();
230+
}
231+
219232
private async Task<InstalledBrowser> DownloadAsync(SupportedBrowser browser, string buildId)
220233
{
221234
var url = _downloadsUrl[browser](Platform, buildId, BaseUrl);
@@ -367,6 +380,10 @@ private async Task UnpackArchiveAsync(string archivePath, string outputPath, str
367380
{
368381
ZipFile.ExtractToDirectory(archivePath, outputPath);
369382
}
383+
else if (archivePath.EndsWith(".exe", StringComparison.OrdinalIgnoreCase))
384+
{
385+
ExecuteSetup(archivePath, outputPath);
386+
}
370387
else if (archivePath.EndsWith(".tar.bz2", StringComparison.OrdinalIgnoreCase))
371388
{
372389
ExtractTar(archivePath, outputPath);

0 commit comments

Comments
 (0)