Skip to content

Commit

Permalink
add logs and check browser exists before checking process()
Browse files Browse the repository at this point in the history
  • Loading branch information
lluisd committed Feb 13, 2024
1 parent b0c4f02 commit 525445e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 2 additions & 1 deletion helpers/browserApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ class PuppeteerApi {
async createNewBrowser() {
this.browser = await puppeteer.connect({ browserWSEndpoint: config.browserlessUrl })
this.browser.on('disconnected', async () => {
console.log('disconnected browser')
if (this.browser) await this.browser.close()
if (this.browser.process() != null) this.browser.process().kill('SIGINT')
if (this.browser && this.browser.process() != null) this.browser.process().kill('SIGINT')
this.browser = null
})
}
Expand Down
2 changes: 2 additions & 0 deletions services/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ async function startAndWarmUpBrowserIfNeeded() {
const browserIsOpen = await browserApi.checkIfBrowserIsOpen()

if (!browserIsOpen) {
console.log('Browser is not open, creating new one')
await browserApi.createNewBrowser()
}
const pageIsOpen = await browserApi.checkIfPageIsOpen()
if (!pageIsOpen) {
console.log('Page is not open, creating new one')
await browserApi.createNewPage()
}
}
Expand Down

0 comments on commit 525445e

Please sign in to comment.