feat: 添加手机号认证失败处理逻辑,确保在遇到手机号页面时自动停止授权流程

This commit is contained in:
祁连海
2026-04-18 12:20:11 +08:00
parent 687bf7f71b
commit e22c36328b
10 changed files with 371 additions and 10 deletions
+26 -1
View File
@@ -21,6 +21,7 @@
getRunningSteps,
getState,
hasSavedProgress,
isAddPhoneAuthFailure,
isRestartCurrentAttemptError,
isStopError,
launchAutoRunTimerPlan,
@@ -456,12 +457,36 @@
const reason = getErrorMessage(err);
roundSummary.failureReasons.push(reason);
const canRetry = autoRunSkipFailures && attemptRun < maxAttemptsForRound;
const blockedByAddPhone = typeof isAddPhoneAuthFailure === 'function' && isAddPhoneAuthFailure(err);
const canRetry = !blockedByAddPhone && autoRunSkipFailures && attemptRun < maxAttemptsForRound;
if (blockedByAddPhone) {
roundSummary.status = 'failed';
roundSummary.finalFailureReason = reason;
}
await setState({
autoRunRoundSummaries: serializeAutoRunRoundSummaries(totalRuns, roundSummaries),
});
if (blockedByAddPhone) {
await appendRoundRecordIfNeeded('failed', reason);
cancelPendingCommands('当前轮因认证流程进入 add-phone 已终止。');
await broadcastStopToContentScripts();
await addLog(
`${targetRun}/${totalRuns} 轮触发 add-phone/手机号页,当前自动运行将立即停止,不再重试或进入下一轮。`,
'warn'
);
stoppedEarly = true;
await broadcastAutoRunStatus('stopped', {
currentRun: targetRun,
totalRuns,
attemptRun,
sessionId: 0,
});
break;
}
if (canRetry) {
const retryIndex = attemptRun;
if (isRestartCurrentAttemptError(err)) {
+6
View File
@@ -61,6 +61,11 @@
return /未在 .*邮箱中找到新的匹配邮件|未在 Hotmail 收件箱中找到新的匹配验证码|邮箱轮询结束,但未获取到验证码|无法获取新的(?:注册|登录)验证码|页面未能重新就绪|页面通信异常|did not respond in \d+s/i.test(message);
}
function isAddPhoneAuthFailure(error) {
const message = getErrorMessage(error);
return /https:\/\/auth\.openai\.com\/add-phone(?:[/?#]|$)|\badd-phone\b|添加手机号|手机号码|手机号页|手机号页面|手机号|phone\s+number|telephone/i.test(message);
}
function getLoginAuthStateLabel(state) {
state = state === 'oauth_consent_page' ? 'unknown' : state;
switch (state) {
@@ -148,6 +153,7 @@
return {
addLog,
getAutoRunStatusPayload,
isAddPhoneAuthFailure,
getErrorMessage,
getFirstUnfinishedStep,
getLoginAuthStateLabel,
+4 -5
View File
@@ -9,6 +9,10 @@
getLoginAuthStateLabel,
getOAuthFlowStepTimeoutMs,
getState,
isAddPhoneAuthFailure = (error) => {
const message = String(typeof error === 'string' ? error : error?.message || '');
return /https:\/\/auth\.openai\.com\/add-phone(?:[/?#]|$)|\badd-phone\b|添加手机号|手机号码|手机号页|手机号页面|手机号|phone\s+number|telephone/i.test(message);
},
isStep6RecoverableResult,
isStep6SuccessResult,
refreshOAuthUrlBeforeStep6,
@@ -19,11 +23,6 @@
throwIfStopped,
} = deps;
function isAddPhoneAuthFailure(error) {
const message = String(typeof error === 'string' ? error : error?.message || '');
return /https:\/\/auth\.openai\.com\/add-phone(?:[/?#]|$)|add-phone|手机号页面|手机号码|手机号|phone\s+number|telephone/i.test(message);
}
async function executeStep7(state) {
if (!state.email) {
throw new Error('缺少邮箱地址,请先完成步骤 3。');
+5
View File
@@ -642,6 +642,11 @@
continue;
}
if (submitResult.addPhonePage) {
const urlPart = submitResult.url ? ` URL: ${submitResult.url}` : '';
throw new Error(`步骤 ${step}:验证码提交后页面进入手机号页面,当前流程无法继续自动授权。${urlPart}`.trim());
}
await setState({
lastEmailTimestamp: result.emailTimestamp,
[stateKey]: result.code,