Skip to content

Commit

Permalink
fix browser api
Browse files Browse the repository at this point in the history
  • Loading branch information
lluisd committed Feb 9, 2024
1 parent ff7bf45 commit b47c347
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
16 changes: 12 additions & 4 deletions helpers/browserApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,21 @@ class PuppeteerApi {
}

async checkIfBrowserIsOpen() {
const isConnected = await this.browser.isConnected()
return this.browser && isConnected
let isConnected = false
if (this.browser) {
isConnected = await this.browser.isConnected()
}

return isConnected
}

async checkIfPageIsOpen() {
const isClosed = await this.page.isClosed()
return this.page && !isClosed
let isClosed = false
if (this.page) {
isClosed = await this.page.isClosed()
}

return !isClosed
}

async resfreshPage() {
Expand Down
2 changes: 1 addition & 1 deletion services/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ async function getScreenshot() {
await browserApi.getPage()
} catch (error) {
console.log(error)
await browserApi.createNewPage()
await this.startAndWarmUpBrowserIfNeeded()
return null
}
const name = Math.random().toString(36).substring(2,8)
Expand Down

0 comments on commit b47c347

Please sign in to comment.