From 35cbb5b784375e445eb9db07c6fdf591a7d9faee Mon Sep 17 00:00:00 2001 From: Lluis Date: Tue, 13 Feb 2024 15:07:56 +0100 Subject: [PATCH] detect on browser disconnected to clean up browser --- helpers/browserApi.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/helpers/browserApi.js b/helpers/browserApi.js index 0d8f5c8..acc3c14 100644 --- a/helpers/browserApi.js +++ b/helpers/browserApi.js @@ -13,12 +13,14 @@ class PuppeteerApi { return this.svgImage } - async newBrowser() { - return await puppeteer.connect({ browserWSEndpoint: config.browserlessUrl }) - } async createNewBrowser() { - this.browser = await this.newBrowser() + this.browser = await puppeteer.connect({ browserWSEndpoint: config.browserlessUrl }) + this.browser.on('disconnected', async () => { + if (this.browser) await this.browser.close() + if (this.browser.process() != null) this.browser.process().kill('SIGINT') + this.browser = null + }) } async getBrowser() {