Skip to content

Commit

Permalink
adding browser clsoe in finally
Browse files Browse the repository at this point in the history
  • Loading branch information
BatMiles committed May 15, 2024
1 parent 2c27028 commit c2a1a6b
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/collector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
// }
}
};

0 comments on commit c2a1a6b

Please sign in to comment.