refactor: 移除网络超时相关逻辑,简化错误处理

This commit is contained in:
QLHazyCoder
2026-04-19 03:28:15 +08:00
parent e8b8af47c4
commit afef124856
9 changed files with 8 additions and 199 deletions
-2
View File
@@ -548,7 +548,6 @@ Cloudflare 模式下,插件不会再调用 Cloudflare API 创建路由。
- 如遇登录超时报错,会先尝试自动点击认证页上的 `重试` 恢复当前页面,再按既有逻辑重跑整个 Step 7
- 如遇登录页长时间停滞,会由后台刷新 OAuth 后重跑整个 Step 7
- 如果重试页内容中出现 `max_check_attempts`,会立刻完全停止流程,并在侧边栏复用现有确认弹窗提示这是 Cloudflare 风控拦截,确认按钮显示为“我知道了”
- 如果重试页内容中出现 `Operation timed out`,也会立刻完全停止流程,并提示先检查当前代理 / VPN 节点是否稳定,如节点本身无明显延迟问题则更换服务器后继续使用当前邮箱登录
支持:
@@ -567,7 +566,6 @@ Step 8 默认要求当前认证页已经处于登录验证码页。
- 验证码链路失败后按有限次数回退到 Step 7
- 如果进入登录超时报错/重试页,会直接报错并回到 Step 7,不会在 Step 8 内部点击 `重试`
- 如果重试页内容中出现 `max_check_attempts`,会直接完全停止整个流程,并复用现有确认弹窗提醒先等待 15 到 30 分钟或更换浏览器,确认按钮显示为“我知道了”
- 如果重试页内容中出现 `Operation timed out`,也会直接完全停止整个流程,并提醒先检查当前代理 / VPN 节点是否稳定,必要时更换服务器后再继续使用当前邮箱登录
与 Step 4 类似,但会使用稍微不同的关键词组合去找登录验证码邮件。
+1 -33
View File
@@ -134,8 +134,6 @@ const HOTMAIL_MAILBOXES = ['INBOX', 'Junk'];
const STOP_ERROR_MESSAGE = '流程已被用户停止。';
const CLOUDFLARE_SECURITY_BLOCK_ERROR_PREFIX = 'CF_SECURITY_BLOCKED::';
const CLOUDFLARE_SECURITY_BLOCK_USER_MESSAGE = '您已触发Cloudflare 安全防护系统,已完全停止流程,请不要短时间内多次进行重新发送验证码,连续刷新、反复点击重试会加重风控;请先关闭页面等待 15-30 分钟,让系统的临时限制自动解除。或者更换浏览器';
const NETWORK_TIMEOUT_BLOCK_ERROR_PREFIX = 'NETWORK_TIMEOUT_BLOCKED::';
const NETWORK_TIMEOUT_BLOCK_USER_MESSAGE = '请检查当前网络节点是否稳定,若你使用的代理 /VPN 节点无延迟过高问题,请换一个服务器继续使用此邮箱继续登陆';
const HUMAN_STEP_DELAY_MIN = 700;
const HUMAN_STEP_DELAY_MAX = 2200;
const STEP6_MAX_ATTEMPTS = 3;
@@ -3844,12 +3842,8 @@ function isCloudflareSecurityBlockedError(error) {
return getErrorMessage(error).startsWith(CLOUDFLARE_SECURITY_BLOCK_ERROR_PREFIX);
}
function isNetworkTimeoutBlockedError(error) {
return getErrorMessage(error).startsWith(NETWORK_TIMEOUT_BLOCK_ERROR_PREFIX);
}
function isTerminalSecurityBlockedError(error) {
return isCloudflareSecurityBlockedError(error) || isNetworkTimeoutBlockedError(error);
return isCloudflareSecurityBlockedError(error);
}
function getCloudflareSecurityBlockedMessage(error) {
@@ -3860,32 +3854,15 @@ function getCloudflareSecurityBlockedMessage(error) {
return CLOUDFLARE_SECURITY_BLOCK_USER_MESSAGE;
}
function getNetworkTimeoutBlockedMessage(error) {
const message = getErrorMessage(error);
if (message.startsWith(NETWORK_TIMEOUT_BLOCK_ERROR_PREFIX)) {
return message.slice(NETWORK_TIMEOUT_BLOCK_ERROR_PREFIX.length).trim() || NETWORK_TIMEOUT_BLOCK_USER_MESSAGE;
}
return NETWORK_TIMEOUT_BLOCK_USER_MESSAGE;
}
function getTerminalSecurityBlockedMessage(error) {
if (isNetworkTimeoutBlockedError(error)) {
return getNetworkTimeoutBlockedMessage(error);
}
return getCloudflareSecurityBlockedMessage(error);
}
function getTerminalSecurityBlockedAlertText(error) {
if (isNetworkTimeoutBlockedError(error)) {
return '检测到网络节点异常,请暂停当前操作。';
}
return '检测到 Cloudflare 风控,请暂停当前操作。';
}
function getTerminalSecurityBlockedTitle(error) {
if (isNetworkTimeoutBlockedError(error)) {
return '网络节点异常';
}
return 'Cloudflare 风控拦截';
}
@@ -6542,9 +6519,6 @@ async function ensureStep8VerificationPageReady(options = {}) {
if (pageState.maxCheckAttemptsBlocked) {
throw new Error(`${CLOUDFLARE_SECURITY_BLOCK_ERROR_PREFIX}${CLOUDFLARE_SECURITY_BLOCK_USER_MESSAGE}`);
}
if (pageState.operationTimedOutBlocked) {
throw new Error(`${NETWORK_TIMEOUT_BLOCK_ERROR_PREFIX}${NETWORK_TIMEOUT_BLOCK_USER_MESSAGE}`);
}
if (pageState.state === 'login_timeout_error_page') {
const urlPart = pageState.url ? ` URL: ${pageState.url}` : '';
@@ -6697,9 +6671,6 @@ async function waitForStep8Ready(tabId, timeoutMs = STEP8_READY_WAIT_TIMEOUT_MS)
if (pageState?.maxCheckAttemptsBlocked) {
throw new Error(`${CLOUDFLARE_SECURITY_BLOCK_ERROR_PREFIX}${CLOUDFLARE_SECURITY_BLOCK_USER_MESSAGE}`);
}
if (pageState?.operationTimedOutBlocked) {
throw new Error(`${NETWORK_TIMEOUT_BLOCK_ERROR_PREFIX}${NETWORK_TIMEOUT_BLOCK_USER_MESSAGE}`);
}
if (pageState?.addPhonePage) {
throw new Error('步骤 9:认证页进入了手机号页面,当前不是 OAuth 同意页,无法继续自动授权。');
}
@@ -6878,9 +6849,6 @@ async function waitForStep8ClickEffect(tabId, baselineUrl, timeoutMs = STEP8_CLI
if (pageState?.maxCheckAttemptsBlocked) {
throw new Error(`${CLOUDFLARE_SECURITY_BLOCK_ERROR_PREFIX}${CLOUDFLARE_SECURITY_BLOCK_USER_MESSAGE}`);
}
if (pageState?.operationTimedOutBlocked) {
throw new Error(`${NETWORK_TIMEOUT_BLOCK_ERROR_PREFIX}${NETWORK_TIMEOUT_BLOCK_USER_MESSAGE}`);
}
if (pageState?.addPhonePage) {
throw new Error('步骤 9:点击“继续”后页面跳到了手机号页面,当前流程无法继续自动授权。');
}
+1 -9
View File
@@ -66,9 +66,8 @@
? detailPattern.test(text)
: false;
const maxCheckAttemptsBlocked = /max_check_attempts/i.test(text);
const operationTimedOutBlocked = /operation\s+timed\s+out/i.test(text);
if (!titleMatched && !detailMatched && !maxCheckAttemptsBlocked && !operationTimedOutBlocked) {
if (!titleMatched && !detailMatched && !maxCheckAttemptsBlocked) {
return null;
}
@@ -80,7 +79,6 @@
titleMatched,
detailMatched,
maxCheckAttemptsBlocked,
operationTimedOutBlocked,
};
}
@@ -146,12 +144,6 @@
);
}
if (retryState.operationTimedOutBlocked) {
throw new Error(
'NETWORK_TIMEOUT_BLOCKED::请检查当前网络节点是否稳定,若你使用的代理 /VPN 节点无延迟过高问题,请换一个服务器继续使用此邮箱继续登陆'
);
}
if (retryState.retryButton && retryState.retryEnabled) {
clickCount += 1;
if (typeof log === 'function') {
+2 -11
View File
@@ -937,9 +937,8 @@ function getAuthTimeoutErrorPageState(options = {}) {
|| AUTH_TIMEOUT_ERROR_TITLE_PATTERN.test(document.title || '');
const detailMatched = AUTH_TIMEOUT_ERROR_DETAIL_PATTERN.test(text);
const maxCheckAttemptsBlocked = /max_check_attempts/i.test(text);
const operationTimedOutBlocked = /operation\s+timed\s+out/i.test(text);
if (!titleMatched && !detailMatched && !maxCheckAttemptsBlocked && !operationTimedOutBlocked) {
if (!titleMatched && !detailMatched && !maxCheckAttemptsBlocked) {
return null;
}
@@ -951,7 +950,6 @@ function getAuthTimeoutErrorPageState(options = {}) {
titleMatched,
detailMatched,
maxCheckAttemptsBlocked,
operationTimedOutBlocked,
};
}
@@ -1007,10 +1005,6 @@ async function recoverCurrentAuthRetryPage(payload = {}) {
if (retryState.maxCheckAttemptsBlocked) {
throw new Error('CF_SECURITY_BLOCKED::您已触发Cloudflare 安全防护系统,已完全停止流程,请不要短时间内多次进行重新发送验证码,连续刷新、反复点击重试会加重风控;请先关闭页面等待 15-30 分钟,让系统的临时限制自动解除。或者更换浏览器');
}
if (retryState.operationTimedOutBlocked) {
throw new Error('NETWORK_TIMEOUT_BLOCKED::请检查当前网络节点是否稳定,若你使用的代理 /VPN 节点无延迟过高问题,请换一个服务器继续使用此邮箱继续登陆');
}
if (retryState.retryButton && retryState.retryEnabled) {
clickCount += 1;
log(`${logLabel || `步骤 ${step || '?'}:检测到重试页,正在点击“重试”恢复`}(第 ${clickCount} 次)...`, 'warn');
@@ -1099,7 +1093,6 @@ function inspectLoginAuthState() {
titleMatched: Boolean(retryState?.titleMatched),
detailMatched: Boolean(retryState?.detailMatched),
maxCheckAttemptsBlocked: Boolean(retryState?.maxCheckAttemptsBlocked),
operationTimedOutBlocked: Boolean(retryState?.operationTimedOutBlocked),
verificationTarget,
passwordInput,
emailInput,
@@ -1166,7 +1159,6 @@ function serializeLoginAuthState(snapshot) {
titleMatched: Boolean(snapshot?.titleMatched),
detailMatched: Boolean(snapshot?.detailMatched),
maxCheckAttemptsBlocked: Boolean(snapshot?.maxCheckAttemptsBlocked),
operationTimedOutBlocked: Boolean(snapshot?.operationTimedOutBlocked),
hasVerificationTarget: Boolean(snapshot?.verificationTarget),
hasPasswordInput: Boolean(snapshot?.passwordInput),
hasEmailInput: Boolean(snapshot?.emailInput),
@@ -1271,7 +1263,7 @@ async function createStep6LoginTimeoutRecoverableResult(reason, snapshot, messag
log('步骤 7:登录超时报错页已点击“重试”,准备重新执行当前步骤。', 'warn');
}
} catch (error) {
if (/(?:CF_SECURITY_BLOCKED|NETWORK_TIMEOUT_BLOCKED)::/i.test(String(error?.message || error || ''))) {
if (/CF_SECURITY_BLOCKED::/i.test(String(error?.message || error || ''))) {
throw error;
}
log(`步骤 7:登录超时报错页自动点击“重试”失败:${error.message}`, 'warn');
@@ -1985,7 +1977,6 @@ function getStep8State() {
retryTitleMatched: Boolean(retryState?.titleMatched),
retryDetailMatched: Boolean(retryState?.detailMatched),
maxCheckAttemptsBlocked: Boolean(retryState?.maxCheckAttemptsBlocked),
operationTimedOutBlocked: Boolean(retryState?.operationTimedOutBlocked),
buttonFound: Boolean(continueBtn),
buttonEnabled: isButtonEnabled(continueBtn),
buttonText: continueBtn ? getActionText(continueBtn) : '',
-19
View File
@@ -79,7 +79,6 @@ test('auth page recovery detects retry page state', () => {
assert.equal(snapshot.titleMatched, true);
assert.equal(snapshot.detailMatched, false);
assert.equal(snapshot.maxCheckAttemptsBlocked, false);
assert.equal(snapshot.operationTimedOutBlocked, false);
});
test('auth page recovery clicks retry and waits until page recovers', async () => {
@@ -157,21 +156,3 @@ test('auth page recovery throws cloudflare security blocked error on max_check_a
);
});
test('auth page recovery throws network timeout block error on operation timed out page', async () => {
const state = {
clickCount: 0,
pageText: 'Something went wrong. Operation timed out.',
retryVisible: true,
};
const api = createRecoveryApi(state);
await assert.rejects(
() => api.recoverAuthRetryPage({
logLabel: '步骤 7:检测到登录超时报错,正在点击“重试”恢复当前页面',
pathPatterns: [/\/log-in(?:[/?#]|$)/i],
step: 7,
timeoutMs: 1000,
}),
/NETWORK_TIMEOUT_BLOCKED::/
);
});
@@ -60,11 +60,11 @@ function createRouter(overrides = {}) {
handleCloudflareSecurityBlocked: overrides.handleCloudflareSecurityBlocked || (async (error) => {
const message = typeof error === 'string' ? error : error?.message || '';
events.securityBlocks.push(message);
return message.replace(/^(?:CF_SECURITY_BLOCKED|NETWORK_TIMEOUT_BLOCKED)::/, '') || message;
return message.replace(/^CF_SECURITY_BLOCKED::/, '') || message;
}),
importSettingsBundle: async () => {},
invalidateDownstreamAfterStepRestart: async () => {},
isCloudflareSecurityBlockedError: overrides.isCloudflareSecurityBlockedError || ((error) => /^(?:CF_SECURITY_BLOCKED|NETWORK_TIMEOUT_BLOCKED)::/.test(typeof error === 'string' ? error : error?.message || '')),
isCloudflareSecurityBlockedError: overrides.isCloudflareSecurityBlockedError || ((error) => /^CF_SECURITY_BLOCKED::/.test(typeof error === 'string' ? error : error?.message || '')),
isAutoRunLockedState: () => false,
isHotmailProvider: () => false,
isLocalhostOAuthCallbackUrl: () => true,
@@ -226,26 +226,3 @@ test('message router stops the flow and surfaces cloudflare security block error
error: '您已触发Cloudflare 安全防护系统',
});
});
test('message router stops the flow and surfaces network timeout block errors', async () => {
const { router, events } = createRouter();
const response = await router.handleMessage({
type: 'STEP_ERROR',
step: 7,
source: 'signup-page',
payload: {},
error: 'NETWORK_TIMEOUT_BLOCKED::请检查当前网络节点是否稳定',
}, {});
assert.deepStrictEqual(events.securityBlocks, ['NETWORK_TIMEOUT_BLOCKED::请检查当前网络节点是否稳定']);
assert.deepStrictEqual(events.notifyErrors, [
{
step: 7,
error: '流程已被用户停止。',
},
]);
assert.deepStrictEqual(response, {
ok: true,
error: '请检查当前网络节点是否稳定',
});
});
+1 -62
View File
@@ -1,74 +1,13 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const source = fs.readFileSync('background.js', 'utf8');
function extractFunction(name) {
const markers = [`async function ${name}(`, `function ${name}(`];
const start = markers
.map((marker) => source.indexOf(marker))
.find((index) => index >= 0);
if (start < 0) {
throw new Error(`missing function ${name}`);
}
let parenDepth = 0;
let signatureEnded = false;
let braceStart = -1;
for (let i = start; i < source.length; i += 1) {
const ch = source[i];
if (ch === '(') {
parenDepth += 1;
} else if (ch === ')') {
parenDepth -= 1;
if (parenDepth === 0) {
signatureEnded = true;
}
} else if (ch === '{' && signatureEnded) {
braceStart = i;
break;
}
}
if (braceStart < 0) {
throw new Error(`missing body for function ${name}`);
}
let depth = 0;
let end = braceStart;
for (; end < source.length; end += 1) {
const ch = source[end];
if (ch === '{') depth += 1;
if (ch === '}') {
depth -= 1;
if (depth === 0) {
end += 1;
break;
}
}
}
return source.slice(start, end);
}
test('security blocked alert title distinguishes cloudflare and network timeout', () => {
const test = require('node:test');const assert = require('node:assert/strict');const fs = require('node:fs');const source = fs.readFileSync('background.js', 'utf8');function extractFunction(name) { const markers = [`async function ${name}(`, `function ${name}(`]; const start = markers .map((marker) => source.indexOf(marker)) .find((index) => index >= 0); if (start < 0) { throw new Error(`missing function ${name}`); } let parenDepth = 0; let signatureEnded = false; let braceStart = -1; for (let i = start; i < source.length; i += 1) { const ch = source[i]; if (ch === '(') { parenDepth += 1; } else if (ch === ')') { parenDepth -= 1; if (parenDepth === 0) { signatureEnded = true; } } else if (ch === '{' && signatureEnded) { braceStart = i; break; } } if (braceStart < 0) { throw new Error(`missing body for function ${name}`); } let depth = 0; let end = braceStart; for (; end < source.length; end += 1) { const ch = source[end]; if (ch === '{') depth += 1; if (ch === '}') { depth -= 1; if (depth === 0) { end += 1; break; } } } return source.slice(start, end);}test('security blocked alert title distinguishes cloudflare and network timeout', () => {
const api = new Function(`
const CLOUDFLARE_SECURITY_BLOCK_ERROR_PREFIX = 'CF_SECURITY_BLOCKED::';
const NETWORK_TIMEOUT_BLOCK_ERROR_PREFIX = 'NETWORK_TIMEOUT_BLOCKED::';
${extractFunction('getErrorMessage')}
${extractFunction('isCloudflareSecurityBlockedError')}
${extractFunction('isNetworkTimeoutBlockedError')}
${extractFunction('getTerminalSecurityBlockedTitle')}
return { getTerminalSecurityBlockedTitle };
`)();
assert.equal(
api.getTerminalSecurityBlockedTitle(new Error('CF_SECURITY_BLOCKED::blocked')),
'Cloudflare 风控拦截'
);
assert.equal(
api.getTerminalSecurityBlockedTitle(new Error('NETWORK_TIMEOUT_BLOCKED::timeout')),
'网络节点异常'
);
});
-36
View File
@@ -87,8 +87,6 @@ test('ensureStep8VerificationPageReady throws cloudflare security block error on
const api = new Function(`
const CLOUDFLARE_SECURITY_BLOCK_ERROR_PREFIX = 'CF_SECURITY_BLOCKED::';
const CLOUDFLARE_SECURITY_BLOCK_USER_MESSAGE = 'cloudflare blocked';
const NETWORK_TIMEOUT_BLOCK_ERROR_PREFIX = 'NETWORK_TIMEOUT_BLOCKED::';
const NETWORK_TIMEOUT_BLOCK_USER_MESSAGE = 'network timeout blocked';
function getLoginAuthStateLabel(state) {
return state === 'login_timeout_error_page' ? 'login timeout page' : 'unknown page';
@@ -117,40 +115,6 @@ return {
);
});
test('ensureStep8VerificationPageReady throws network timeout block error on operation timed out page', async () => {
const api = new Function(`
const CLOUDFLARE_SECURITY_BLOCK_ERROR_PREFIX = 'CF_SECURITY_BLOCKED::';
const CLOUDFLARE_SECURITY_BLOCK_USER_MESSAGE = 'cloudflare blocked';
const NETWORK_TIMEOUT_BLOCK_ERROR_PREFIX = 'NETWORK_TIMEOUT_BLOCKED::';
const NETWORK_TIMEOUT_BLOCK_USER_MESSAGE = 'network timeout blocked';
function getLoginAuthStateLabel(state) {
return state === 'login_timeout_error_page' ? 'login timeout page' : 'unknown page';
}
async function getLoginAuthStateFromContent() {
return {
state: 'login_timeout_error_page',
url: 'https://auth.openai.com/log-in',
operationTimedOutBlocked: true,
};
}
${extractFunction(backgroundSource, 'ensureStep8VerificationPageReady')}
return {
run() {
return ensureStep8VerificationPageReady({});
},
};
`)();
await assert.rejects(
() => api.run(),
/NETWORK_TIMEOUT_BLOCKED::/
);
});
test('step 8 reruns step 7 when auth page enters login timeout retry state', async () => {
const calls = {
executeStep7: 0,
+1 -2
View File
@@ -1,4 +1,4 @@
# 项目完整链路说明
# 项目完整链路说明
本文档面向 AI 与开发者,目标是让阅读者在最短时间内理解“项目做什么、怎么跑、数据怎么流、功能链路怎么串”,从而在新增功能时不漏逻辑、不误改边界。
@@ -550,5 +550,4 @@
- Step 7 在识别到登录超时报错页时,会先尝试自动点击 `重试` 恢复当前页面;若仍未恢复,则按原有可恢复失败逻辑重跑 Step 7。
- Step 8 如果发现认证页已经进入登录超时报错/重试页,会直接报错并回到 Step 7 重新开始,而不是在 Step 8 内部点击 `重试`
- 任意认证页重试页如果正文中出现 `max_check_attempts`,会被视为 Cloudflare 风控触发:后台立刻完全停止流程,侧边栏会复用现有确认弹窗提示等待 15~30 分钟后再试,避免继续刷新或反复重试加重风控,确认按钮显示为“我知道了”。
- 任意认证页重试页如果正文中出现 `Operation timed out`,会被视为网络节点异常:后台同样会立刻完全停止流程,并提示先检查当前代理 / VPN 节点是否稳定;若节点本身无明显高延迟问题,则更换服务器后继续使用当前邮箱登录。
- Step 9 在点击 OAuth 同意页 `继续` 后,会额外检查是否进入认证页重试页;若命中则先自动点击 `重试` 恢复,再重新执行当前轮的 `继续` 点击。