feat: close browser on error

pull/142/head
Travis Fischer 2022-12-15 02:14:17 -06:00
rodzic b3f71bc1e4
commit 1f1fc66429
1 zmienionych plików z 22 dodań i 11 usunięć

Wyświetl plik

@ -59,6 +59,7 @@ export class ChatGPTAPIBrowser {
this._browser = null
}
try {
this._browser = await getBrowser({ captchaToken: this._captchaToken })
this._page =
(await this._browser.pages())[0] || (await this._browser.newPage())
@ -71,6 +72,16 @@ export class ChatGPTAPIBrowser {
page: this._page,
isGoogleLogin: this._isGoogleLogin
})
} catch (err) {
if (this._browser) {
await this._browser.close()
}
this._browser = null
this._page = null
throw err
}
const chatUrl = 'https://chat.openai.com/chat'
const url = this._page.url().replace(/\/$/, '')