@@ -23,6 +23,7 @@ public class BrowserFetcher : IBrowserFetcher
23
23
private static readonly Dictionary < SupportedBrowser , Func < Platform , string , string , string > > _downloadsUrl = new ( )
24
24
{
25
25
[ SupportedBrowser . Chrome ] = Chrome . ResolveDownloadUrl ,
26
+ [ SupportedBrowser . ChromeHeadlessShell ] = ChromeHeadlessShell . ResolveDownloadUrl ,
26
27
[ SupportedBrowser . Chromium ] = Chromium . ResolveDownloadUrl ,
27
28
[ SupportedBrowser . Firefox ] = Firefox . ResolveDownloadUrl ,
28
29
} ;
@@ -128,42 +129,14 @@ public void Uninstall(string buildId)
128
129
/// <inheritdoc/>
129
130
public async Task < InstalledBrowser > DownloadAsync ( string buildId )
130
131
{
131
- var url = _downloadsUrl [ Browser ] ( Platform , buildId , BaseUrl ) ;
132
- var fileName = url . Split ( '/' ) . Last ( ) ;
133
- var cache = new Cache ( CacheDir ) ;
134
- var archivePath = Path . Combine ( CacheDir , fileName ) ;
135
- var downloadFolder = new DirectoryInfo ( CacheDir ) ;
136
-
137
- if ( ! downloadFolder . Exists )
138
- {
139
- downloadFolder . Create ( ) ;
140
- }
141
-
142
- if ( DownloadProgressChanged != null )
143
- {
144
- _webClient . DownloadProgressChanged += DownloadProgressChanged ;
145
- }
132
+ var installedBrowser = await DownloadAsync ( Browser , buildId ) . ConfigureAwait ( false ) ;
146
133
147
- var outputPath = cache . GetInstallationDir ( Browser , Platform , buildId ) ;
148
-
149
- if ( new DirectoryInfo ( outputPath ) . Exists )
134
+ if ( Browser == SupportedBrowser . Chrome )
150
135
{
151
- return new InstalledBrowser ( cache , Browser , buildId , Platform ) ;
136
+ await DownloadAsync ( SupportedBrowser . ChromeHeadlessShell , buildId ) . ConfigureAwait ( false ) ;
152
137
}
153
138
154
- try
155
- {
156
- await _customFileDownload ( url , archivePath ) . ConfigureAwait ( false ) ;
157
- }
158
- catch ( Exception ex )
159
- {
160
- throw new PuppeteerException ( $ "Failed to download { Browser } for { Platform } from { url } ", ex ) ;
161
- }
162
-
163
- await UnpackArchiveAsync ( archivePath , outputPath , fileName ) . ConfigureAwait ( false ) ;
164
- new FileInfo ( archivePath ) . Delete ( ) ;
165
-
166
- return new InstalledBrowser ( cache , Browser , buildId , Platform ) ;
139
+ return installedBrowser ;
167
140
}
168
141
169
142
/// <inheritdoc/>
@@ -267,6 +240,46 @@ private static void ExtractTar(string zipPath, string folderPath)
267
240
process . WaitForExit ( ) ;
268
241
}
269
242
243
+ private async Task < InstalledBrowser > DownloadAsync ( SupportedBrowser browser , string buildId )
244
+ {
245
+ var url = _downloadsUrl [ browser ] ( Platform , buildId , BaseUrl ) ;
246
+ var fileName = url . Split ( '/' ) . Last ( ) ;
247
+ var cache = new Cache ( CacheDir ) ;
248
+ var archivePath = Path . Combine ( CacheDir , fileName ) ;
249
+ var downloadFolder = new DirectoryInfo ( CacheDir ) ;
250
+
251
+ if ( ! downloadFolder . Exists )
252
+ {
253
+ downloadFolder . Create ( ) ;
254
+ }
255
+
256
+ if ( DownloadProgressChanged != null )
257
+ {
258
+ _webClient . DownloadProgressChanged += DownloadProgressChanged ;
259
+ }
260
+
261
+ var outputPath = cache . GetInstallationDir ( browser , Platform , buildId ) ;
262
+
263
+ if ( new DirectoryInfo ( outputPath ) . Exists )
264
+ {
265
+ return new InstalledBrowser ( cache , browser , buildId , Platform ) ;
266
+ }
267
+
268
+ try
269
+ {
270
+ await _customFileDownload ( url , archivePath ) . ConfigureAwait ( false ) ;
271
+ }
272
+ catch ( Exception ex )
273
+ {
274
+ throw new PuppeteerException ( $ "Failed to download { browser } for { Platform } from { url } ", ex ) ;
275
+ }
276
+
277
+ await UnpackArchiveAsync ( archivePath , outputPath , fileName ) . ConfigureAwait ( false ) ;
278
+ new FileInfo ( archivePath ) . Delete ( ) ;
279
+
280
+ return new InstalledBrowser ( cache , browser , buildId , Platform ) ;
281
+ }
282
+
270
283
private Task InstallDMGAsync ( string dmgPath , string folderPath )
271
284
{
272
285
try
0 commit comments