Merge pull request #219 from fuergaosi233/feat/impove-robustness

Fix undefined
pull/220/head
Travis Fischer 2022-12-31 15:18:33 -06:00 zatwierdzone przez GitHub
commit 5c7b9d64a4
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
1 zmienionych plików z 25 dodań i 13 usunięć

Wyświetl plik

@ -126,14 +126,16 @@ export async function getOpenAIAuth({
await delay(500) await delay(500)
// click login button and wait for navigation to finish // click login button and wait for navigation to finish
while (page.url().endsWith('/auth/login')) {
await Promise.all([ await Promise.all([
page.waitForNavigation({ page.waitForNavigation({
waitUntil: 'networkidle2', waitUntil: 'networkidle2',
timeout: timeoutMs timeout: timeoutMs
}), }),
page.click('#__next .btn-primary') page.click('#__next .btn-primary')
]) ])
delay(500)
}
await checkForChatGPTAtCapacity(page, { timeoutMs }) await checkForChatGPTAtCapacity(page, { timeoutMs })
@ -179,12 +181,22 @@ export async function getOpenAIAuth({
if (hasNopechaExtension) { if (hasNopechaExtension) {
await waitForRecaptcha(page, { timeoutMs }) await waitForRecaptcha(page, { timeoutMs })
} else if (hasRecaptchaPlugin) { } else if (hasRecaptchaPlugin) {
// Add retry for network unstable
console.log('solving captchas using 2captcha...') console.log('solving captchas using 2captcha...')
const retries = 3
for (let i = 0; i < retries; i++) {
try {
const res = await page.solveRecaptchas() const res = await page.solveRecaptchas()
if (res.captchas?.length) { if (res.captchas?.length) {
console.log('captchas result', res) console.log('captchas result', res)
break
} else { } else {
console.log('no captchas found') console.log('no captchas found')
delay(500)
}
} catch (e) {
console.log('captcha error', e)
}
} }
} }