Repository: transitive-bullshit/chatgpt-api
File: src/openai-auth.ts (TypeScript)

Code before:

      await checkForChatGPTAtCapacity(page, { timeoutMs })

      let submitP: () => Promise<void>

      if (isGoogleLogin) {
        await page.click('button[data-provider="google"]')
        await page.waitForSelector('input[type="email"]')
        await page.type('input[type="email"]', email, { delay: 10 })
        await Promise.all([
          page.waitForNavigation(),
          await page.keyboard.press('Enter')
        ])
        await page.waitForSelector('input[type="password"]', { visible: true })
        await page.type('input[type="password"]', password, { delay: 10 })
        submitP = () => page.keyboard.press('Enter')
      } else if (isWindowsLogin) {
        await page.click('button[data-provider="windowslive"]')
        await page.waitForSelector('input[type="email"]')
        await page.type('input[type="email"]', email, { delay: 10 })
        await Promise.all([
          page.waitForNavigation(),
          await page.keyboard.press('Enter')
        ])
        await delay(1500)
        await page.waitForSelector('input[type="password"]', { visible: true })
        await page.type('input[type="password"]', password, { delay: 10 })
        submitP = () => page.keyboard.press('Enter')
        await Promise.all([
          page.waitForNavigation(),
          await page.keyboard.press('Enter')
        ])
        await delay(1000)
      } else {
        await page.waitForSelector('#username')
        await page.type('#username', email, { delay: 20 })
        await delay(100)

        // NOTE: this is where you may encounter a CAPTCHA
        if (hasNopechaExtension) {
          await waitForRecaptcha(page, { timeoutMs })
        } else if (hasRecaptchaPlugin) {
          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')
          }
        }


Review comment (suggestion):
```suggestion
        await page.waitForSelector('input[type="password"]', { visible: true })
```
Don't think the delay is necessary since we're already waiting for the selector here

Code after:

      await checkForChatGPTAtCapacity(page, { timeoutMs })

      let submitP: () => Promise<void>

      if (isGoogleLogin) {
        await page.click('button[data-provider="google"]')
        await page.waitForSelector('input[type="email"]')
        await page.type('input[type="email"]', email, { delay: 10 })
        await Promise.all([
          page.waitForNavigation(),
          await page.keyboard.press('Enter')
        ])
        await page.waitForSelector('input[type="password"]', { visible: true })
        await page.type('input[type="password"]', password, { delay: 10 })
        submitP = () => page.keyboard.press('Enter')
      } else if (isMicrosoftLogin) {
        await page.click('button[data-provider="windowslive"]')
        await page.waitForSelector('input[type="email"]')
        await page.type('input[type="email"]', email, { delay: 10 })
        await Promise.all([
          page.waitForNavigation(),
          await page.keyboard.press('Enter')
        ])
        await delay(1500)
        await page.waitForSelector('input[type="password"]', { visible: true })
        await page.type('input[type="password"]', password, { delay: 10 })
        submitP = () => page.keyboard.press('Enter')
        await Promise.all([
          page.waitForNavigation(),
          await page.keyboard.press('Enter')
        ])
        await delay(1000)
      } else {
        await page.waitForSelector('#username')
        await page.type('#username', email, { delay: 20 })
        await delay(100)

        // NOTE: this is where you may encounter a CAPTCHA
        if (hasNopechaExtension) {
          await waitForRecaptcha(page, { timeoutMs })
        } else if (hasRecaptchaPlugin) {
          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')
          }
        }