Skip to content

Commit

Permalink
detect on browser disconnected to clean up browser
Browse files Browse the repository at this point in the history
  • Loading branch information
lluisd committed Feb 13, 2024
1 parent b47c347 commit 35cbb5b
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions helpers/browserApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 35cbb5b

Please sign in to comment.