From ca83acb3c7e1ddfa7c8156944ea41ebdd5991732 Mon Sep 17 00:00:00 2001 From: ikechan8370 Date: Wed, 15 Feb 2023 11:37:42 +0800 Subject: [PATCH] fix: change default timeout --- config/index.js | 4 +++- utils/browser.js | 4 ++-- utils/openai-auth.js | 8 ++++---- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/config/index.js b/config/index.js index 5c21a80..a13fe95 100644 --- a/config/index.js +++ b/config/index.js @@ -62,5 +62,7 @@ export const Config = { proxy: PROXY, debug: false, // 各个地方的默认超时时间 - defaultTimeoutMs: 12000 + defaultTimeoutMs: 12000, + // 浏览器默认超时,浏览器可能需要更高的超时时间 + chromeTimeoutMS: 120000 } diff --git a/utils/browser.js b/utils/browser.js index 5e3be2d..5984274 100644 --- a/utils/browser.js +++ b/utils/browser.js @@ -350,7 +350,7 @@ export class ChatGPTPuppeteer extends Puppeteer { await maximizePage(this._page) await this._page.reload({ waitUntil: 'networkidle2', - timeout: 2 * 60 * 1000 // 2 minutes + timeout: Config.chromeTimeoutMS // 2 minutes }) if (this._minimize) { await minimizePage(this._page) @@ -465,7 +465,7 @@ export class ChatGPTPuppeteer extends Puppeteer { ) throw err } - let timeout = 10000 + let timeout = 100000 if (isAuthenticated) { while (!this._accessToken) { // wait for async response hook result diff --git a/utils/openai-auth.js b/utils/openai-auth.js index 68fab17..2ca88dc 100644 --- a/utils/openai-auth.js +++ b/utils/openai-auth.js @@ -10,7 +10,7 @@ export async function getOpenAIAuth (opt) { password, browser, page, - timeoutMs = 2 * 60 * 1000, + timeoutMs = Config.chromeTimeoutMS, isGoogleLogin = false, captchaToken = Config['2captchaToken'], executablePath = Config.chromePath @@ -48,7 +48,7 @@ export async function getOpenAIAuth (opt) { while (retry > 0) { try { await waitForConditionOrAtCapacity(page, () => - page.waitForSelector('#__next .btn-primary', { timeout: 2000 }) + page.waitForSelector('#__next .btn-primary', { timeout: timeoutMs / 3 }) ) } catch (e) { await checkForChatGPTAtCapacity(page) @@ -56,7 +56,7 @@ export async function getOpenAIAuth (opt) { retry-- } await waitForConditionOrAtCapacity(page, () => - page.waitForSelector('#__next .btn-primary', { timeout: 2000 }) + page.waitForSelector('#__next .btn-primary', { timeout: timeoutMs / 3 }) ) await delay(500) @@ -156,7 +156,7 @@ export async function getOpenAIAuth (opt) { async function checkForChatGPTAtCapacity (page, opts = {}) { const { - timeoutMs = 2 * 60 * 1000, // 2 minutes + timeoutMs = Config.chromeTimeoutMS, // 2 minutes pollingIntervalMs = 3000, retries = 10 } = opts