Skip to content

Commit

Permalink
Merge pull request transitive-bullshit#219 from fuergaosi233/feat/imp…
Browse files Browse the repository at this point in the history
…ove-robustness

Fix undefined
  • Loading branch information
transitive-bullshit authored Dec 31, 2022
2 parents c29a5f3 + e98f740 commit 5c7b9d6
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions src/openai-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,16 @@ export async function getOpenAIAuth({
await delay(500)

// click login button and wait for navigation to finish
await Promise.all([
page.waitForNavigation({
waitUntil: 'networkidle2',
timeout: timeoutMs
}),

page.click('#__next .btn-primary')
])
while (page.url().endsWith('/auth/login')) {
await Promise.all([
page.waitForNavigation({
waitUntil: 'networkidle2',
timeout: timeoutMs
}),
page.click('#__next .btn-primary')
])
delay(500)
}

await checkForChatGPTAtCapacity(page, { timeoutMs })

Expand Down Expand Up @@ -179,12 +181,22 @@ export async function getOpenAIAuth({
if (hasNopechaExtension) {
await waitForRecaptcha(page, { timeoutMs })
} else if (hasRecaptchaPlugin) {
// Add retry for network unstable
console.log('solving captchas using 2captcha...')
const res = await page.solveRecaptchas()
if (res.captchas?.length) {
console.log('captchas result', res)
} else {
console.log('no captchas found')
const retries = 3
for (let i = 0; i < retries; i++) {
try {
const res = await page.solveRecaptchas()
if (res.captchas?.length) {
console.log('captchas result', res)
break
} else {
console.log('no captchas found')
delay(500)
}
} catch (e) {
console.log('captcha error', e)
}
}
}

Expand Down

0 comments on commit 5c7b9d6

Please sign in to comment.