Commit 1f1fc664 authored by Travis Fischer's avatar Travis Fischer

feat: close browser on error

parent b3f71bc1
...@@ -59,18 +59,29 @@ export class ChatGPTAPIBrowser { ...@@ -59,18 +59,29 @@ export class ChatGPTAPIBrowser {
this._browser = null this._browser = null
} }
this._browser = await getBrowser({ captchaToken: this._captchaToken }) try {
this._page = this._browser = await getBrowser({ captchaToken: this._captchaToken })
(await this._browser.pages())[0] || (await this._browser.newPage()) this._page =
(await this._browser.pages())[0] || (await this._browser.newPage())
// bypass cloudflare and login
await getOpenAIAuth({ // bypass cloudflare and login
email: this._email, await getOpenAIAuth({
password: this._password, email: this._email,
browser: this._browser, password: this._password,
page: this._page, browser: this._browser,
isGoogleLogin: this._isGoogleLogin 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 chatUrl = 'https://chat.openai.com/chat'
const url = this._page.url().replace(/\/$/, '') const url = this._page.url().replace(/\/$/, '')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment