@@ -21,6 +21,8 @@ const getIntegerPercent = (callback: PercentCallback): PuppeteerProgressCallback
2121let downloadProm : ReturnType < typeof downloadChromium > | null = null ;
2222
2323export default async function downloadChromium ( installPath : string , onProgress ?: PercentCallback ) : Promise < string > {
24+ if ( downloadProm ) return downloadProm ;
25+
2426 const platform = detectBrowserPlatform ( ) ;
2527 if ( ! platform ) {
2628 throw new Error ( `Cannot download a binary for the provided platform: ${ os . platform ( ) } (${ os . arch ( ) } )` ) ;
@@ -40,32 +42,21 @@ export default async function downloadChromium(installPath: string, onProgress?:
4042 // No cached version found, proceed with download
4143 logger . log ( 'No cached Chromium found, downloading...' ) ;
4244
43- if ( downloadProm ) return downloadProm ;
44-
45- downloadProm = ( async ( ) => {
46- try {
47- const progressCallback = onProgress && getIntegerPercent ( onProgress ) ;
48- const buildId = await resolveBuildId ( Browser . CHROMIUM , platform , 'latest' ) ;
45+ const progressCallback = onProgress && getIntegerPercent ( onProgress ) ;
46+ const buildId = await resolveBuildId ( Browser . CHROMIUM , platform , 'latest' ) ;
4947
50- logger . log ( `Browser: ${ Browser . CHROMIUM } , Platform: ${ platform } , Tag: latest, BuildId: ${ buildId } ` ) ;
48+ logger . log ( `Browser: ${ Browser . CHROMIUM } , Platform: ${ platform } , Tag: latest, BuildId: ${ buildId } ` ) ;
5149
52- const installOptions = {
53- cacheDir : installPath ,
54- browser : Browser . CHROMIUM ,
55- buildId,
56- downloadProgressCallback : progressCallback ,
57- } ;
58-
59- const { executablePath } = await install ( installOptions ) ;
60-
61- downloadProm = null ;
62- logger . log ( 'Chromium downloaded to' , executablePath ) ;
63- return executablePath ;
64- } catch ( error ) {
65- downloadProm = null ; // Reset promise so next attempt will retry
66- throw error ;
67- }
68- } ) ( ) ;
50+ downloadProm = install ( {
51+ cacheDir : installPath ,
52+ browser : Browser . CHROMIUM ,
53+ buildId,
54+ downloadProgressCallback : progressCallback ,
55+ } ) . then ( ( { executablePath } ) => {
56+ downloadProm = null ;
57+ logger . log ( 'Chromium downloaded to' , executablePath ) ;
58+ return executablePath ;
59+ } ) ;
6960
70- return downloadProm ;
61+ return downloadProm ! ;
7162}
0 commit comments