mirror of
https://github.com/7836246/cursor2api.git
synced 2026-09-03 07:20:02 +08:00
fix: 增加 challenge 容错 — 超时延长到 30s 并支持自动重试
- CHALLENGE_WAIT 从 15s 增加到 30s - challenge 页面改用 domcontentloaded + 60s 超时 - 首次获取 cookie 失败后自动刷新重试一次 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -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++;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user