diff --git a/src/chatgpt-api-browser.ts b/src/chatgpt-api-browser.ts index 097a322..2f95c0c 100644 --- a/src/chatgpt-api-browser.ts +++ b/src/chatgpt-api-browser.ts @@ -662,16 +662,21 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI { } if (this._browser) { - const pages = await this._browser.pages() - for (const page of pages) { - await page.close() + try { + const pages = await this._browser.pages() + for (const page of pages) { + await page.close() + } + } catch (err) { + console.warn('closeSession error', err) } await this._browser.close() + const browserProcess = this._browser.process() // Rule number 1 of zombie process hunting: double-tap - if (this._browser.process()) { - this._browser.process().kill('SIGINT') + if (browserProcess) { + browserProcess.kill('SIGKILL') } } diff --git a/src/openai-auth.ts b/src/openai-auth.ts index eead110..5bc6375 100644 --- a/src/openai-auth.ts +++ b/src/openai-auth.ts @@ -188,12 +188,12 @@ export async function getOpenAIAuth({ } } - await delay(1200) + await delay(2000) const frame = page.mainFrame() const submit = await page.waitForSelector('button[type="submit"]', { timeout: timeoutMs }) - frame.focus('button[type="submit"]') + await frame.focus('button[type="submit"]') await submit.focus() await submit.click() await page.waitForSelector('#password', { timeout: timeoutMs }) @@ -588,12 +588,14 @@ async function waitForRecaptcha( const captcha = await page.$('textarea#g-recaptcha-response') if (!captcha) { // the user may have gone past the page manually + console.log('captcha no longer found; continuing') break } const value = (await captcha.evaluate((el) => el.value))?.trim() if (value?.length) { // recaptcha has been solved! + console.log('captcha solved; continuin') break } } catch (err) {