Skip to content

Commit dca5bfc

Browse files
authored
Restore BrowserFetcher.GetExecutablePath (#2363)
1 parent d5caa54 commit dca5bfc

File tree

4 files changed

+30
-22
lines changed

4 files changed

+30
-22
lines changed

lib/PuppeteerSharp/BrowserData/Cache.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ internal class Cache
99
{
1010
private readonly string _rootDir;
1111

12-
public Cache() => _rootDir = BrowserFetcher.GetExecutablePath();
12+
public Cache() => _rootDir = BrowserFetcher.GetBrowsersLocation();
1313

1414
public Cache(string rootDir) => _rootDir = rootDir;
1515

@@ -27,8 +27,8 @@ public IEnumerable<InstalledBrowser> GetInstalledBrowsers()
2727
return Array.Empty<InstalledBrowser>();
2828
}
2929

30-
var browerNames = Enum.GetNames(typeof(SupportedBrowser)).Select(browser => browser.ToUpperInvariant());
31-
var browsers = rootInfo.GetDirectories().Where(browser => browerNames.Contains(browser.Name.ToUpperInvariant()));
30+
var browserNames = Enum.GetNames(typeof(SupportedBrowser)).Select(browser => browser.ToUpperInvariant());
31+
var browsers = rootInfo.GetDirectories().Where(browser => browserNames.Contains(browser.Name.ToUpperInvariant()));
3232

3333
return browsers.SelectMany(browser =>
3434
{

lib/PuppeteerSharp/BrowserFetcher.cs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Diagnostics;
4-
using System.Globalization;
54
using System.IO;
65
using System.IO.Compression;
76
using System.Linq;
@@ -35,7 +34,7 @@ public class BrowserFetcher : IBrowserFetcher
3534
/// <inheritdoc cref="BrowserFetcher"/>
3635
public BrowserFetcher()
3736
{
38-
CacheDir = GetExecutablePath();
37+
CacheDir = GetBrowsersLocation();
3938
Platform = GetCurrentPlatform();
4039
Browser = SupportedBrowser.Chrome;
4140
_customFileDownload = _webClient.DownloadFileTaskAsync;
@@ -55,7 +54,7 @@ public BrowserFetcher(BrowserFetcherOptions options)
5554
}
5655

5756
Browser = options.Browser;
58-
CacheDir = string.IsNullOrEmpty(options.Path) ? GetExecutablePath() : options.Path;
57+
CacheDir = string.IsNullOrEmpty(options.Path) ? GetBrowsersLocation() : options.Path;
5958
Platform = options.Platform ?? GetCurrentPlatform();
6059
_customFileDownload = options.CustomFileDownload ?? _webClient.DownloadFileTaskAsync;
6160
}
@@ -92,10 +91,8 @@ public async Task<bool> CanDownloadAsync(string revision)
9291
var client = WebRequest.Create(url);
9392
client.Proxy = _webClient.Proxy;
9493
client.Method = "HEAD";
95-
using (var response = (HttpWebResponse)await client.GetResponseAsync().ConfigureAwait(false))
96-
{
97-
return response.StatusCode == HttpStatusCode.OK;
98-
}
94+
using var response = (HttpWebResponse)await client.GetResponseAsync().ConfigureAwait(false);
95+
return response.StatusCode == HttpStatusCode.OK;
9996
}
10097
catch (WebException)
10198
{
@@ -170,6 +167,14 @@ public async Task<InstalledBrowser> DownloadAsync(string buildId)
170167
return new InstalledBrowser(cache, Browser, buildId, Platform);
171168
}
172169

170+
/// <inheritdoc/>
171+
public string GetExecutablePath(string buildId)
172+
=> new InstalledBrowser(
173+
new Cache(CacheDir),
174+
Browser,
175+
buildId,
176+
Platform).GetExecutablePath();
177+
173178
/// <inheritdoc/>
174179
public void Dispose()
175180
{
@@ -197,7 +202,7 @@ internal static Platform GetCurrentPlatform()
197202
return Platform.Unknown;
198203
}
199204

200-
internal static string GetExecutablePath()
205+
internal static string GetBrowsersLocation()
201206
{
202207
var assembly = typeof(Puppeteer).Assembly;
203208
var assemblyName = assembly.GetName().Name + ".dll";
@@ -276,11 +281,8 @@ private Task InstallDMGAsync(string dmgPath, string folderPath)
276281

277282
var mountAndCopyTcs = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
278283

279-
using var process = new Process
280-
{
281-
EnableRaisingEvents = true,
282-
};
283-
284+
using var process = new Process();
285+
process.EnableRaisingEvents = true;
284286
process.StartInfo.FileName = "hdiutil";
285287
process.StartInfo.Arguments = $"attach -nobrowse -noautoopen \"{dmgPath}\"";
286288
process.StartInfo.RedirectStandardOutput = true;

lib/PuppeteerSharp/IBrowserFetcher.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@ namespace PuppeteerSharp
88
{
99
/// <summary>
1010
/// BrowserFetcher can download and manage different versions of Chromium.
11-
/// BrowserFetcher operates on revision strings that specify a precise version of Chromium, e.g. 533271. Revision strings can be obtained from omahaproxy.appspot.com.
1211
/// </summary>
1312
/// <example>
1413
/// Example on how to use BrowserFetcher to download a specific version of Chromium and run Puppeteer against it:
1514
/// <code>
1615
/// var browserFetcher = Puppeteer.CreateBrowserFetcher();
17-
/// var revisionInfo = await browserFetcher.DownloadAsync("533271");
16+
/// var revisionInfo = await browserFetcher.DownloadAsync(BrowserData.Chrome.DefaultBuildId);
1817
/// var browser = await await Puppeteer.LaunchAsync(new LaunchOptions { ExecutablePath = revisionInfo.ExecutablePath});
1918
/// </code>
2019
/// </example>
@@ -88,5 +87,12 @@ public interface IBrowserFetcher : IDisposable
8887
/// </summary>
8988
/// <param name="buildId">Browser to remove.</param>
9089
void Uninstall(string buildId);
90+
91+
/// <summary>
92+
/// Gets the executable path.
93+
/// </summary>
94+
/// <param name="buildId">Browser buildId.</param>
95+
/// <returns>The executable path.</returns>
96+
string GetExecutablePath(string buildId);
9197
}
9298
}

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

0 commit comments

Comments
 (0)