Skip to content

Commit 2885c8d

Browse files
committed
Merge branch 'v21' into webdriver-unlock-setcontent
2 parents bf2db01 + 4896303 commit 2885c8d

17 files changed

+57
-53
lines changed

lib/PuppeteerSharp.Tests/PuppeteerSharp.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
</PackageReference>
1919
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
2020
<PackageReference Include="System.Net.Http" Version="4.3.4" />
21-
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.7" />
21+
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.11" />
2222
<PackageReference Include="Microsoft.AspNetCore.Connections.Abstractions" Version="2.2.0" />
2323
</ItemGroup>
2424
<Import Project="../Common/CommonProps.props" />

lib/PuppeteerSharp/Binding.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ await context.EvaluateFunctionAsync(
137137
}
138138
finally
139139
{
140-
await Task.WhenAll(garbage.ToArray()).ConfigureAwait(false);
140+
await Task.WhenAll(garbage).ConfigureAwait(false);
141141
}
142142
}
143143
}

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: 7 additions & 5 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
};
@@ -123,7 +123,7 @@ private static void SyncPreferences(Dictionary<string, object> defaultPreference
123123
var userPath = Path.Combine(tempUserDataDirectory, "user.js");
124124
var lines = string.Join(
125125
"\n",
126-
defaultPreferences.Select(i => $"user_pref({JsonSerializer.Serialize(i.Key)}, {JsonSerializer.Serialize(i.Value)});").ToArray());
126+
defaultPreferences.Select(i => $"user_pref({JsonSerializer.Serialize(i.Key)}, {JsonSerializer.Serialize(i.Value)});"));
127127

128128
BackupFile(userPath);
129129
BackupFile(prefsPath);
@@ -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/Cdp/CdpBrowser.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,7 @@ public override async Task<IBrowserContext> CreateBrowserContextAsync(BrowserCon
143143
}
144144

145145
/// <inheritdoc/>
146-
public override IBrowserContext[] BrowserContexts()
147-
{
148-
var contexts = _contexts.Values.ToArray<IBrowserContext>();
149-
150-
var allContexts = new IBrowserContext[contexts.Length + 1];
151-
allContexts[0] = DefaultContext;
152-
contexts.CopyTo(allContexts, 1);
153-
return allContexts;
154-
}
146+
public override IBrowserContext[] BrowserContexts() => [DefaultContext, .. _contexts.Values];
155147

156148
internal static async Task<CdpBrowser> CreateAsync(
157149
SupportedBrowser browserToCreate,

lib/PuppeteerSharp/Cdp/Connection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,14 @@ internal void Close(string closeReason)
203203
Transport.StopReading();
204204
Disconnected?.Invoke(this, EventArgs.Empty);
205205

206-
foreach (var session in _sessions.Values.ToArray())
206+
foreach (var session in _sessions.Values)
207207
{
208208
session.Close(closeReason);
209209
}
210210

211211
_sessions.Clear();
212212

213-
foreach (var response in _callbacks.Values.ToArray())
213+
foreach (var response in _callbacks.Values)
214214
{
215215
response.TaskWrapper.TrySetException(new TargetClosedException(
216216
$"Protocol error({response.Method}): Target closed.",

lib/PuppeteerSharp/Cdp/FrameManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ private void OnLifeCycleEvent(LifecycleEventResponse e)
283283

284284
private void OnExecutionContextsCleared(CDPSession session)
285285
{
286-
foreach (var key in _contextIdToContext.Keys.ToArray())
286+
foreach (var key in _contextIdToContext.Keys)
287287
{
288288
var context = _contextIdToContext[key];
289289
if (context.Client != session)

0 commit comments

Comments
 (0)