Skip to content

Commit f7cfaac

Browse files
committed
Merge branch 'master' into protocol-using-webdriver-driver
2 parents ba490de + 96d9e3a commit f7cfaac

File tree

8 files changed

+75
-35
lines changed

8 files changed

+75
-35
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.Tests/PageTests/RemoveExposedFunctionTests.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@ public class RemoveExposeFunctionTests : PuppeteerPageBaseTest
99
[Test, Retry(2), PuppeteerTest("page.spec", "Page Page.removeExposedFunction", "should work")]
1010
public async Task ShouldWork()
1111
{
12-
await Page.ExposeFunctionAsync("compute", (int a, int b) => a * b);
13-
var result = await Page.EvaluateFunctionAsync<int>("async () => compute(9, 4)");
14-
Assert.AreEqual(36, result);
15-
16-
await Page.RemoveExposedFunctionAsync("compute");
12+
// Run twice to verify function can be added again after remove
13+
for (var i = 0; i < 2; i++)
14+
{
15+
await Page.ExposeFunctionAsync("compute", (int a, int b) => a * b);
16+
var result = await Page.EvaluateFunctionAsync<int>("async () => compute(9, 4)");
17+
Assert.AreEqual(36, result);
1718

19+
await Page.RemoveExposedFunctionAsync("compute");
20+
}
1821
Assert.ThrowsAsync<EvaluationFailedException>(() => Page.EvaluateFunctionAsync<int>("async () => compute(9, 4)"));
1922
}
2023
}

lib/PuppeteerSharp.Tests/PuppeteerBrowserBaseTest.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.IO;
32
using System.Threading.Tasks;
43
using NUnit.Framework;
54

@@ -18,7 +17,13 @@ public virtual async Task InitializeAsync()
1817
TestConstants.LoggerFactory);
1918

2019
[TearDown]
21-
public virtual async Task DisposeAsync() => await Browser.CloseAsync();
20+
public virtual async Task DisposeAsync()
21+
{
22+
if (Browser is not null)
23+
{
24+
await Browser.CloseAsync();
25+
}
26+
}
2227

2328
public void Dispose()
2429
{

lib/PuppeteerSharp.Tests/PuppeteerPageBaseTest.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Diagnostics;
12
using System.Threading.Tasks;
23
using NUnit.Framework;
34

@@ -11,11 +12,17 @@ public class PuppeteerPageBaseTest : PuppeteerBrowserContextBaseTest
1112
public async Task CreatePageAsync()
1213
{
1314
Page = await Context.NewPageAsync();
14-
Page.DefaultTimeout = System.Diagnostics.Debugger.IsAttached ? TestConstants.DebuggerAttachedTestTimeout : TestConstants.DefaultPuppeteerTimeout;
15+
Page.DefaultTimeout = Debugger.IsAttached ? TestConstants.DebuggerAttachedTestTimeout : TestConstants.DefaultPuppeteerTimeout;
1516
}
1617

1718
[TearDown]
18-
public Task ClosePageAsync() => Page.CloseAsync();
19+
public async Task ClosePageAsync()
20+
{
21+
if (Page is not null)
22+
{
23+
await Page.CloseAsync();
24+
}
25+
}
1926

2027
protected Task WaitForError()
2128
{

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: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public async Task<bool> CanDownloadAsync(string revision)
9393
using var response = await client.SendAsync(requestMessage).ConfigureAwait(false);
9494
return response.StatusCode == HttpStatusCode.OK;
9595
}
96-
catch (WebException)
96+
catch (HttpRequestException)
9797
{
9898
return false;
9999
}
@@ -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);

lib/PuppeteerSharp/Cdp/CdpPage.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ public override async Task RemoveExposedFunctionAsync(string name)
236236
throw new ArgumentNullException(nameof(name));
237237
}
238238

239-
if (!_exposedFunctions.TryRemove(name, out var exposedFun) && !_bindings.TryRemove(name, out _))
239+
if (!_exposedFunctions.TryRemove(name, out var exposedFun) || !_bindings.TryRemove(name, out _))
240240
{
241241
throw new PuppeteerException(
242242
$"Failed to remove page binding with name {name}: window['{name}'] does not exists!");

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>18.0.1</PackageVersion>
16-
<ReleaseVersion>18.0.1</ReleaseVersion>
17-
<AssemblyVersion>18.0.1</AssemblyVersion>
18-
<FileVersion>18.0.0</FileVersion>
15+
<PackageVersion>18.0.2</PackageVersion>
16+
<ReleaseVersion>18.0.2</ReleaseVersion>
17+
<AssemblyVersion>18.0.2</AssemblyVersion>
18+
<FileVersion>18.0.2</FileVersion>
1919
<SynchReleaseVersion>false</SynchReleaseVersion>
2020
<StyleCopTreatErrorsAsWarnings>false</StyleCopTreatErrorsAsWarnings>
2121
<DebugType>embedded</DebugType>

0 commit comments

Comments
 (0)