import { getPuppeteerConfig } from 'israeli-bank-scrapers-core' ; import puppeteer from 'puppeteer-core' ; type PuppeteerProgressCallback = ( downloadBytes : number , totalBytes : number ) => void ; type PercentCallback = ( percent : number ) => void ; const getIntegerPercent = ( callback ) : PuppeteerProgressCallback => { let prevPercent = - 1 ; return ( downloadBytes , totalBytes ) => { const p = Math . floor ( ( downloadBytes / totalBytes ) * 100 ) ; if ( p > prevPercent ) { prevPercent = p ; callback ( p ) ; } } ; } ; const revision = getPuppeteerConfig ( ) . chromiumRevision ; let downloadProm = null ; export default async function downloadChromium ( installPath ? , onProgress ? ) { if ( downloadProm ) return downloadProm ; const progressCallback = onProgress && getIntegerPercent ( onProgress ) ; const browserFetcher = puppeteer . createBrowserFetcher ( { path : installPath } ) ; downloadProm = browserFetcher . download ( revision , progressCallback ) . then ( ( { executablePath } ) => { downloadProm = null ; return executablePath ; } ) ; return downloadProm ; }