Skip to content

Commit de7b94c

Browse files
kblokCopilot
andauthored
Add support to ARM browsers (#2937)
* Add support to ARM browsers * thank you copilot * Update lib/PuppeteerSharp/Platform.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 384e9d6 commit de7b94c

File tree

7 files changed

+40
-28
lines changed

7 files changed

+40
-28
lines changed

lib/PuppeteerSharp/BrowserData/Chrome.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ internal static string RelativeExecutablePath(Platform platform, string builId)
3030
"Contents",
3131
"MacOS",
3232
"Google Chrome for Testing"),
33-
Platform.Linux => Path.Combine("chrome-linux64", "chrome"),
33+
Platform.Linux or Platform.LinuxArm64 => Path.Combine("chrome-linux64", "chrome"),
3434
Platform.Win32 or Platform.Win64 => Path.Combine("chrome-" + GetFolder(platform), "chrome.exe"),
3535
_ => throw new ArgumentException("Invalid platform", nameof(platform)),
3636
};
@@ -60,6 +60,7 @@ internal static string ResolveSystemExecutablePath(Platform platform, ChromeRele
6060
ChromeReleaseChannel.Dev => $"/Applications/Google Chrome Dev.app/Contents/MacOS/Google Chrome Dev",
6161
_ => throw new PuppeteerException($"{channel} is not supported"),
6262
};
63+
case Platform.LinuxArm64:
6364
case Platform.Linux:
6465
return channel switch
6566
{
@@ -86,17 +87,17 @@ internal static string ResolveSystemExecutablePath(Platform platform, ChromeRele
8687
}
8788

8889
private static string[] ResolveDownloadPath(Platform platform, string buildId)
89-
=> new string[]
90-
{
90+
=>
91+
[
9192
buildId,
9293
GetFolder(platform),
93-
$"chrome-{GetFolder(platform)}.zip",
94-
};
94+
$"chrome-{GetFolder(platform)}.zip"
95+
];
9596

9697
private static string GetFolder(Platform platform)
9798
=> platform switch
9899
{
99-
Platform.Linux => "linux64",
100+
Platform.Linux or Platform.LinuxArm64 => "linux64",
100101
Platform.MacOSArm64 => "mac-arm64",
101102
Platform.MacOS => "mac-x64",
102103
Platform.Win32 => "win32",

lib/PuppeteerSharp/BrowserData/ChromeHeadlessShell.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,23 @@ internal static string RelativeExecutablePath(Platform platform, string buildId)
1717
Platform.MacOS or Platform.MacOSArm64 => Path.Combine(
1818
"chrome-headless-shell-" + GetFolder(platform),
1919
"chrome-headless-shell"),
20-
Platform.Linux => Path.Combine("chrome-headless-shell-linux64", "chrome-headless-shell"),
20+
Platform.Linux or Platform.LinuxArm64 => Path.Combine("chrome-headless-shell-linux64", "chrome-headless-shell"),
2121
Platform.Win32 or Platform.Win64 => Path.Combine("chrome-headless-shell-" + GetFolder(platform), "chrome-headless-shell.exe"),
2222
_ => throw new ArgumentException("Invalid platform", nameof(platform)),
2323
};
2424

2525
private static string[] ResolveDownloadPath(Platform platform, string buildId)
26-
=> new string[]
27-
{
26+
=>
27+
[
2828
buildId,
2929
GetFolder(platform),
30-
$"chrome-headless-shell-{GetFolder(platform)}.zip",
31-
};
30+
$"chrome-headless-shell-{GetFolder(platform)}.zip"
31+
];
3232

3333
private static string GetFolder(Platform platform)
3434
=> platform switch
3535
{
36-
Platform.Linux => "linux64",
36+
Platform.Linux or Platform.LinuxArm64 => "linux64",
3737
Platform.MacOSArm64 => "mac-arm64",
3838
Platform.MacOS => "mac-x64",
3939
Platform.Win32 => "win32",

lib/PuppeteerSharp/BrowserData/Chromium.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,23 @@ internal static string RelativeExecutablePath(Platform platform, string builId)
2121
"Contents",
2222
"MacOS",
2323
"Chromium"),
24-
Platform.Linux => Path.Combine("chrome-linux", "chrome"),
24+
Platform.Linux or Platform.LinuxArm64 => Path.Combine("chrome-linux", "chrome"),
2525
Platform.Win32 or Platform.Win64 => Path.Combine("chrome-win", "chrome.exe"),
2626
_ => throw new ArgumentException("Invalid platform", nameof(platform)),
2727
};
2828

2929
private static string[] ResolveDownloadPath(Platform platform, string buildId)
30-
=> new string[]
31-
{
30+
=>
31+
[
3232
GetFolder(platform),
3333
buildId,
34-
$"{GetArchive(platform, buildId)}.zip",
35-
};
34+
$"{GetArchive(platform, buildId)}.zip"
35+
];
3636

3737
private static string GetArchive(Platform platform, string buildId)
3838
=> platform switch
3939
{
40-
Platform.Linux => "chrome-linux",
40+
Platform.Linux or Platform.LinuxArm64 => "chrome-linux",
4141
Platform.MacOS or Platform.MacOSArm64 => "chrome-mac",
4242

4343
// Windows archive name changed at r591479.
@@ -48,7 +48,7 @@ private static string GetArchive(Platform platform, string buildId)
4848
private static string GetFolder(Platform platform)
4949
=> platform switch
5050
{
51-
Platform.Linux => "Linux_x64",
51+
Platform.Linux or Platform.LinuxArm64 => "Linux_x64",
5252
Platform.MacOSArm64 => "Mac_Arm",
5353
Platform.MacOS => "Mac",
5454
Platform.Win32 => "Win",

lib/PuppeteerSharp/BrowserData/Firefox.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ internal static string RelativeExecutablePath(Platform platform, string buildId)
9090
"Contents",
9191
"MacOS",
9292
"firefox"),
93-
Platform.Linux => Path.Combine("firefox", "firefox"),
93+
Platform.Linux or Platform.LinuxArm64 => Path.Combine("firefox", "firefox"),
9494
Platform.Win32 or Platform.Win64 => Path.Combine("firefox", "firefox.exe"),
9595
_ => throw new ArgumentException("Invalid platform", nameof(platform)),
9696
};
@@ -102,7 +102,7 @@ internal static string RelativeExecutablePath(Platform platform, string buildId)
102102
"Contents",
103103
"MacOS",
104104
"firefox"),
105-
Platform.Linux => Path.Combine("firefox", "firefox"),
105+
Platform.Linux or Platform.LinuxArm64 => Path.Combine("firefox", "firefox"),
106106
Platform.Win32 or Platform.Win64 => Path.Combine("core", "firefox.exe"),
107107
_ => throw new ArgumentException("Invalid platform", nameof(platform)),
108108
};
@@ -162,6 +162,7 @@ private static string GetPlatformNameForUrl(Platform platform)
162162
=> platform switch
163163
{
164164
Platform.Linux => "linux-x86_64",
165+
Platform.LinuxArm64 => "linux-aarch64",
165166
Platform.MacOS or Platform.MacOSArm64 => "mac",
166167
Platform.Win32 => "win32",
167168
Platform.Win64 => "win64",
@@ -171,7 +172,7 @@ private static string GetPlatformNameForUrl(Platform platform)
171172
private static string GetFirefoxPlatform(Platform platform)
172173
=> platform switch
173174
{
174-
Platform.Linux => "linux",
175+
Platform.Linux or Platform.LinuxArm64 => "linux",
175176
Platform.MacOS => "mac",
176177
Platform.MacOSArm64 => "mac_arm",
177178
Platform.Win32 => "win32",
@@ -182,6 +183,7 @@ private static string GetFirefoxPlatform(Platform platform)
182183
private static string GetArchiveNightly(Platform platform, string buildId)
183184
=> platform switch
184185
{
186+
Platform.LinuxArm64 => $"firefox-{buildId}.en-US.{GetFirefoxPlatform(platform)}-aarch64.tar.{GetFormat(buildId)}",
185187
Platform.Linux => $"firefox-{buildId}.en-US.{GetFirefoxPlatform(platform)}-x86_64.tar.{GetFormat(buildId)}",
186188
Platform.MacOS or Platform.MacOSArm64 => $"firefox-{buildId}.en-US.mac.dmg",
187189
Platform.Win32 or Platform.Win64 => $"firefox-{buildId}.en-US.{GetFirefoxPlatform(platform)}.zip",
@@ -197,7 +199,7 @@ private static string GetFormat(string buildId)
197199
private static string GetArchive(Platform platform, string buildId)
198200
=> platform switch
199201
{
200-
Platform.Linux => $"firefox-{buildId}.tar.bz2",
202+
Platform.Linux or Platform.LinuxArm64 => $"firefox-{buildId}.tar.bz2",
201203
Platform.MacOS or Platform.MacOSArm64 => $"Firefox {buildId}.dmg",
202204
Platform.Win32 or Platform.Win64 =>
203205
$"Firefox Setup {buildId}.exe",

lib/PuppeteerSharp/BrowserFetcher.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,16 @@ internal static Platform GetCurrentPlatform()
160160

161161
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
162162
{
163-
return RuntimeInformation.OSArchitecture == Architecture.X64 ? Platform.Win64 : Platform.Win32;
163+
return RuntimeInformation.OSArchitecture == Architecture.X64 ||
164+
(RuntimeInformation.OSArchitecture == Architecture.Arm64 && IsWindows11()) ? Platform.Win64 : Platform.Win32;
164165
}
165166

166167
return Platform.Unknown;
167168
}
168169

170+
internal static bool IsWindows11()
171+
=> RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && Environment.OSVersion.Version.Build >= 22000;
172+
169173
internal static string GetBrowsersLocation()
170174
{
171175
var assembly = typeof(Puppeteer).Assembly;

lib/PuppeteerSharp/Platform.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ public enum Platform
2525
/// </summary>
2626
Linux,
2727

28+
/// <summary>
29+
/// Linux ARM64.
30+
/// </summary>
31+
LinuxArm64,
32+
2833
/// <summary>
2934
/// Win32.
3035
/// </summary>

lib/PuppeteerSharp/PuppeteerSharp.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
<Description>Headless Browser .NET API</Description>
1313
<PackageId>PuppeteerSharp</PackageId>
1414
<PackageReleaseNotes></PackageReleaseNotes>
15-
<PackageVersion>20.2.1</PackageVersion>
16-
<ReleaseVersion>20.2.1</ReleaseVersion>
17-
<AssemblyVersion>20.2.1</AssemblyVersion>
18-
<FileVersion>20.2.1</FileVersion>
15+
<PackageVersion>20.2.2</PackageVersion>
16+
<ReleaseVersion>20.2.2</ReleaseVersion>
17+
<AssemblyVersion>20.2.2</AssemblyVersion>
18+
<FileVersion>20.2.2</FileVersion>
1919
<SynchReleaseVersion>false</SynchReleaseVersion>
2020
<StyleCopTreatErrorsAsWarnings>false</StyleCopTreatErrorsAsWarnings>
2121
<DebugType>embedded</DebugType>

0 commit comments

Comments
 (0)