@@ -23,6 +23,7 @@ public class BrowserFetcher : IBrowserFetcher
2323 private static readonly Dictionary < SupportedBrowser , Func < Platform , string , string , string > > _downloadsUrl = new ( )
2424 {
2525 [ SupportedBrowser . Chrome ] = Chrome . ResolveDownloadUrl ,
26+ [ SupportedBrowser . ChromeHeadlessShell ] = ChromeHeadlessShell . ResolveDownloadUrl ,
2627 [ SupportedBrowser . Chromium ] = Chromium . ResolveDownloadUrl ,
2728 [ SupportedBrowser . Firefox ] = Firefox . ResolveDownloadUrl ,
2829 } ;
@@ -128,42 +129,14 @@ public void Uninstall(string buildId)
128129 /// <inheritdoc/>
129130 public async Task < InstalledBrowser > DownloadAsync ( string buildId )
130131 {
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 ) ;
146133
147- var outputPath = cache . GetInstallationDir ( Browser , Platform , buildId ) ;
148-
149- if ( new DirectoryInfo ( outputPath ) . Exists )
134+ if ( Browser == SupportedBrowser . Chrome )
150135 {
151- return new InstalledBrowser ( cache , Browser , buildId , Platform ) ;
136+ await DownloadAsync ( SupportedBrowser . ChromeHeadlessShell , buildId ) . ConfigureAwait ( false ) ;
152137 }
153138
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 ;
167140 }
168141
169142 /// <inheritdoc/>
@@ -267,6 +240,46 @@ private static void ExtractTar(string zipPath, string folderPath)
267240 process . WaitForExit ( ) ;
268241 }
269242
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+
270283 private Task InstallDMGAsync ( string dmgPath , string folderPath )
271284 {
272285 try
0 commit comments