fix: change default timeout

This commit is contained in:
ikechan8370 2023-02-15 11:37:42 +08:00
parent 23b16a7f85
commit ca83acb3c7
3 changed files with 9 additions and 7 deletions

View file

@ -62,5 +62,7 @@ export const Config = {
proxy: PROXY, proxy: PROXY,
debug: false, debug: false,
// 各个地方的默认超时时间 // 各个地方的默认超时时间
defaultTimeoutMs: 12000 defaultTimeoutMs: 12000,
// 浏览器默认超时,浏览器可能需要更高的超时时间
chromeTimeoutMS: 120000
} }

View file

@ -350,7 +350,7 @@ export class ChatGPTPuppeteer extends Puppeteer {
await maximizePage(this._page) await maximizePage(this._page)
await this._page.reload({ await this._page.reload({
waitUntil: 'networkidle2', waitUntil: 'networkidle2',
timeout: 2 * 60 * 1000 // 2 minutes timeout: Config.chromeTimeoutMS // 2 minutes
}) })
if (this._minimize) { if (this._minimize) {
await minimizePage(this._page) await minimizePage(this._page)
@ -465,7 +465,7 @@ export class ChatGPTPuppeteer extends Puppeteer {
) )
throw err throw err
} }
let timeout = 10000 let timeout = 100000
if (isAuthenticated) { if (isAuthenticated) {
while (!this._accessToken) { while (!this._accessToken) {
// wait for async response hook result // wait for async response hook result

View file

@ -10,7 +10,7 @@ export async function getOpenAIAuth (opt) {
password, password,
browser, browser,
page, page,
timeoutMs = 2 * 60 * 1000, timeoutMs = Config.chromeTimeoutMS,
isGoogleLogin = false, isGoogleLogin = false,
captchaToken = Config['2captchaToken'], captchaToken = Config['2captchaToken'],
executablePath = Config.chromePath executablePath = Config.chromePath
@ -48,7 +48,7 @@ export async function getOpenAIAuth (opt) {
while (retry > 0) { while (retry > 0) {
try { try {
await waitForConditionOrAtCapacity(page, () => await waitForConditionOrAtCapacity(page, () =>
page.waitForSelector('#__next .btn-primary', { timeout: 2000 }) page.waitForSelector('#__next .btn-primary', { timeout: timeoutMs / 3 })
) )
} catch (e) { } catch (e) {
await checkForChatGPTAtCapacity(page) await checkForChatGPTAtCapacity(page)
@ -56,7 +56,7 @@ export async function getOpenAIAuth (opt) {
retry-- retry--
} }
await waitForConditionOrAtCapacity(page, () => await waitForConditionOrAtCapacity(page, () =>
page.waitForSelector('#__next .btn-primary', { timeout: 2000 }) page.waitForSelector('#__next .btn-primary', { timeout: timeoutMs / 3 })
) )
await delay(500) await delay(500)
@ -156,7 +156,7 @@ export async function getOpenAIAuth (opt) {
async function checkForChatGPTAtCapacity (page, opts = {}) { async function checkForChatGPTAtCapacity (page, opts = {}) {
const { const {
timeoutMs = 2 * 60 * 1000, // 2 minutes timeoutMs = Config.chromeTimeoutMS, // 2 minutes
pollingIntervalMs = 3000, pollingIntervalMs = 3000,
retries = 10 retries = 10
} = opts } = opts