kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
feat: add logic to solve simple captchas in addition to recaptchas
rodzic
71de95ab97
commit
3e6db370ea
|
@ -44,6 +44,7 @@
|
|||
"puppeteer-extra": "^3.3.4",
|
||||
"puppeteer-extra-plugin-recaptcha": "^3.6.6",
|
||||
"puppeteer-extra-plugin-stealth": "^2.11.1",
|
||||
"random": "^4.1.0",
|
||||
"remark": "^14.0.2",
|
||||
"strip-markdown": "^5.0.0",
|
||||
"uuid": "^9.0.0"
|
||||
|
|
|
@ -21,6 +21,7 @@ specifiers:
|
|||
puppeteer-extra: ^3.3.4
|
||||
puppeteer-extra-plugin-recaptcha: ^3.6.6
|
||||
puppeteer-extra-plugin-stealth: ^2.11.1
|
||||
random: ^4.1.0
|
||||
remark: ^14.0.2
|
||||
strip-markdown: ^5.0.0
|
||||
tsup: ^6.5.0
|
||||
|
@ -39,6 +40,7 @@ dependencies:
|
|||
puppeteer-extra: 3.3.4_puppeteer@19.4.0
|
||||
puppeteer-extra-plugin-recaptcha: 3.6.6_puppeteer-extra@3.3.4
|
||||
puppeteer-extra-plugin-stealth: 2.11.1_puppeteer-extra@3.3.4
|
||||
random: 4.1.0
|
||||
remark: 14.0.2
|
||||
strip-markdown: 5.0.0
|
||||
uuid: 9.0.0
|
||||
|
@ -3224,6 +3226,13 @@ packages:
|
|||
engines: {node: '>=10'}
|
||||
dev: true
|
||||
|
||||
/random/4.1.0:
|
||||
resolution: {integrity: sha512-6Ajb7XmMSE9EFAMGC3kg9mvE7fGlBip25mYYuSMzw/uUSrmGilvZo2qwX3RnTRjwXkwkS+4swse9otZ92VjAtQ==}
|
||||
engines: {node: '>=14'}
|
||||
dependencies:
|
||||
seedrandom: 3.0.5
|
||||
dev: false
|
||||
|
||||
/read-pkg-up/8.0.0:
|
||||
resolution: {integrity: sha512-snVCqPczksT0HS2EC+SxUndvSzn6LRCwpfSvLrIfR5BKDQQZMaI6jPRC9dYvYFDRAuFEAnkwww8kBBNE/3VvzQ==}
|
||||
engines: {node: '>=12'}
|
||||
|
@ -3412,6 +3421,10 @@ packages:
|
|||
is-regex: 1.1.4
|
||||
dev: true
|
||||
|
||||
/seedrandom/3.0.5:
|
||||
resolution: {integrity: sha512-8OwmbklUNzwezjGInmZ+2clQmExQPvomqjL7LFqOYqtmuxRgQYqOD3mHaU+MvZn5FLUeVxVfQjwLZW/n/JFuqg==}
|
||||
dev: false
|
||||
|
||||
/semver/5.7.1:
|
||||
resolution: {integrity: sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==}
|
||||
hasBin: true
|
||||
|
|
|
@ -9,6 +9,7 @@ import type { Browser, Page, Protocol, PuppeteerLaunchOptions } from 'puppeteer'
|
|||
import puppeteer from 'puppeteer-extra'
|
||||
import RecaptchaPlugin from 'puppeteer-extra-plugin-recaptcha'
|
||||
import StealthPlugin from 'puppeteer-extra-plugin-stealth'
|
||||
import random from 'random'
|
||||
|
||||
import * as types from './types'
|
||||
|
||||
|
@ -17,7 +18,6 @@ puppeteer.use(StealthPlugin())
|
|||
let hasRecaptchaPlugin = false
|
||||
let hasNopechaExtension = false
|
||||
|
||||
const __filename = url.fileURLToPath(import.meta.url)
|
||||
const __dirname = url.fileURLToPath(new URL('.', import.meta.url))
|
||||
|
||||
/**
|
||||
|
@ -129,6 +129,7 @@ export async function getOpenAIAuth({
|
|||
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) {
|
||||
|
@ -367,6 +368,8 @@ async function checkForChatGPTAtCapacity(
|
|||
|
||||
do {
|
||||
try {
|
||||
await solveSimpleCaptchas(page)
|
||||
|
||||
const res = await page.$x("//div[contains(., 'ChatGPT is at capacity')]")
|
||||
isAtCapacity = !!res?.length
|
||||
|
||||
|
@ -446,6 +449,30 @@ async function waitForConditionOrAtCapacity(
|
|||
})
|
||||
}
|
||||
|
||||
async function solveSimpleCaptchas(page: Page) {
|
||||
try {
|
||||
const verifyYouAreHuman = await page.$('text=Verify you are human')
|
||||
if (verifyYouAreHuman) {
|
||||
await delay(2000)
|
||||
await verifyYouAreHuman.click({
|
||||
delay: random.int(5, 25)
|
||||
})
|
||||
await delay(1000)
|
||||
}
|
||||
|
||||
const cloudflareButton = await page.$('.hcaptcha-box')
|
||||
if (cloudflareButton) {
|
||||
await delay(2000)
|
||||
await cloudflareButton.click({
|
||||
delay: random.int(5, 25)
|
||||
})
|
||||
await delay(1000)
|
||||
}
|
||||
} catch (err) {
|
||||
// ignore errors
|
||||
}
|
||||
}
|
||||
|
||||
async function waitForRecaptcha(
|
||||
page: Page,
|
||||
opts: {
|
||||
|
@ -453,6 +480,8 @@ async function waitForRecaptcha(
|
|||
timeoutMs?: number
|
||||
} = {}
|
||||
) {
|
||||
await solveSimpleCaptchas(page)
|
||||
|
||||
if (!hasNopechaExtension) {
|
||||
return
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue