From c2a1a6b5b8e545b2c318fd39ebaac6b9b5294c6d Mon Sep 17 00:00:00 2001 From: Miles Hilton Date: Wed, 15 May 2024 12:46:13 -0400 Subject: [PATCH] adding browser clsoe in finally --- src/collector.ts | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/collector.ts b/src/collector.ts index fbdcccf..51d7627 100644 --- a/src/collector.ts +++ b/src/collector.ts @@ -114,6 +114,7 @@ export const collect = async (inUrl: string, args: CollectorOptions) => { if (args.puppeteerExecutablePath) { options['executablePath'] = args.puppeteerExecutablePath; } + try { browser = await puppeteer.launch(options); browser.on('disconnected', () => { didBrowserDisconnect = true; @@ -387,22 +388,23 @@ export const collect = async (inUrl: string, args: CollectorOptions) => { clearDir(args.outDir, false); } return { status: 'success', ...output, reports }; + } // } catch (error) { // // return error // return { // status: 'failed', // page_response: 'Run failed, please try again' // }; - // } finally { - // // close browser and clear tmp dir - // if (browser && !didBrowserDisconnect) { - // await browser.close(); - // } - // if (typeof userDataDir !== 'undefined') { - // clearDir(userDataDir, false); - // } - // if (args.outDir.includes('bl-tmp')) { - // clearDir(args.outDir, false); - // } - // } + finally { + // close browser and clear tmp dir + if (browser && !didBrowserDisconnect) { + await browser.close(); + } + // if (typeof userDataDir !== 'undefined') { + // clearDir(userDataDir, false); + // } + // if (args.outDir.includes('bl-tmp')) { + // clearDir(args.outDir, false); + // } + } };