From 484262ca8a66ea06490f9b1350c55968b5f375d2 Mon Sep 17 00:00:00 2001 From: BaskDuan <133692311@qq.com> Date: Thu, 2 Apr 2026 23:09:09 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=A2=9E=E5=8A=A0=20challenge=20?= =?UTF-8?q?=E5=AE=B9=E9=94=99=20=E2=80=94=20=E8=B6=85=E6=97=B6=E5=BB=B6?= =?UTF-8?q?=E9=95=BF=E5=88=B0=2030s=20=E5=B9=B6=E6=94=AF=E6=8C=81=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E9=87=8D=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - CHALLENGE_WAIT 从 15s 增加到 30s - challenge 页面改用 domcontentloaded + 60s 超时 - 首次获取 cookie 失败后自动刷新重试一次 Co-Authored-By: Claude Opus 4.6 (1M context) --- stealth-proxy/index.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/stealth-proxy/index.js b/stealth-proxy/index.js index fa62c1c..614ba8c 100644 --- a/stealth-proxy/index.js +++ b/stealth-proxy/index.js @@ -17,7 +17,7 @@ const crypto = require('crypto'); const PORT = parseInt(process.env.PORT || '3011'); const CHALLENGE_URL = process.env.CHALLENGE_URL || 'https://cursor.com/cn/docs'; const REFRESH_INTERVAL = parseInt(process.env.REFRESH_INTERVAL || '3000000'); // 50 分钟 -const CHALLENGE_WAIT = parseInt(process.env.CHALLENGE_WAIT || '15000'); // challenge 最长等待时间 +const CHALLENGE_WAIT = parseInt(process.env.CHALLENGE_WAIT || '30000'); // challenge 最长等待时间 let browser, context, challengePage, workerPage; let ready = false; @@ -61,13 +61,20 @@ async function initBrowser() { challengePage = await context.newPage(); console.log(`[Stealth] Passing Vercel challenge: ${CHALLENGE_URL}`); await challengePage.goto(CHALLENGE_URL, { - waitUntil: 'networkidle', - timeout: 30000, + waitUntil: 'domcontentloaded', + timeout: 60000, }); + // 等待 cookie(challenge JS 会异步设置 _vcrcs) const ok = await waitForCookie(); if (!ok) { - throw new Error('Failed to obtain _vcrcs cookie'); + // 重试一次:刷新页面再等 + console.log('[Stealth] First attempt failed, retrying challenge...'); + await challengePage.reload({ waitUntil: 'domcontentloaded', timeout: 60000 }); + const retryOk = await waitForCookie(); + if (!retryOk) { + throw new Error('Failed to obtain _vcrcs cookie after retry'); + } } challengeCount++;