优化步骤在日志中的显示
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
|
||||
function createVerificationFlowHelpers(deps = {}) {
|
||||
const {
|
||||
addLog,
|
||||
addLog: rawAddLog = async () => {},
|
||||
chrome,
|
||||
closeConflictingTabsForSource,
|
||||
CLOUDFLARE_TEMP_EMAIL_PROVIDER,
|
||||
@@ -34,6 +34,33 @@
|
||||
throwIfStopped,
|
||||
VERIFICATION_POLL_MAX_ROUNDS,
|
||||
} = deps;
|
||||
let activeVerificationLogStep = null;
|
||||
|
||||
function normalizeLogStep(value) {
|
||||
const step = Math.floor(Number(value) || 0);
|
||||
return step > 0 ? step : null;
|
||||
}
|
||||
|
||||
function normalizeVerificationLogMessage(message) {
|
||||
return String(message || '')
|
||||
.replace(/^步骤\s*\d+\s*[::]\s*/, '')
|
||||
.replace(/^Step\s+\d+\s*[::]\s*/i, '')
|
||||
.trim();
|
||||
}
|
||||
|
||||
function addLog(message, level = 'info', options = {}) {
|
||||
const normalizedOptions = options && typeof options === 'object' ? { ...options } : {};
|
||||
const step = normalizeLogStep(normalizedOptions.step || normalizedOptions.visibleStep)
|
||||
|| normalizeLogStep(activeVerificationLogStep);
|
||||
if (step) {
|
||||
normalizedOptions.step = step;
|
||||
if (!normalizedOptions.stepKey) {
|
||||
normalizedOptions.stepKey = step === 4 ? 'fetch-signup-code' : 'fetch-login-code';
|
||||
}
|
||||
}
|
||||
delete normalizedOptions.visibleStep;
|
||||
return rawAddLog(normalizeVerificationLogMessage(message), level, normalizedOptions);
|
||||
}
|
||||
|
||||
const isRetryableVerificationTransportError = typeof deps.isRetryableContentScriptTransportError === 'function'
|
||||
? deps.isRetryableContentScriptTransportError
|
||||
@@ -518,6 +545,8 @@
|
||||
timeoutMs: responseTimeoutMs,
|
||||
responseTimeoutMs,
|
||||
maxRecoveryAttempts: 2,
|
||||
logStep: activeVerificationLogStep,
|
||||
logStepKey: step === 4 ? 'fetch-signup-code' : 'fetch-login-code',
|
||||
}
|
||||
);
|
||||
|
||||
@@ -583,6 +612,8 @@
|
||||
timeoutMs: 10000,
|
||||
responseTimeoutMs: 5000,
|
||||
maxRecoveryAttempts: 1,
|
||||
logStep: activeVerificationLogStep,
|
||||
logStepKey: step === 4 ? 'fetch-signup-code' : 'fetch-login-code',
|
||||
}
|
||||
);
|
||||
} catch (_) {
|
||||
@@ -693,6 +724,8 @@
|
||||
timeoutMs: timeoutWindow.timeoutMs,
|
||||
maxRecoveryAttempts: 2,
|
||||
responseTimeoutMs: timeoutWindow.responseTimeoutMs,
|
||||
logStep: activeVerificationLogStep,
|
||||
logStepKey: step === 4 ? 'fetch-signup-code' : 'fetch-login-code',
|
||||
}
|
||||
);
|
||||
|
||||
@@ -959,6 +992,8 @@
|
||||
timeoutMs: timeoutWindow.timeoutMs,
|
||||
maxRecoveryAttempts: 2,
|
||||
responseTimeoutMs: timeoutWindow.responseTimeoutMs,
|
||||
logStep: activeVerificationLogStep,
|
||||
logStepKey: step === 4 ? 'fetch-signup-code' : 'fetch-login-code',
|
||||
}
|
||||
);
|
||||
|
||||
@@ -1000,6 +1035,8 @@
|
||||
}
|
||||
|
||||
async function submitVerificationCode(step, code, options = {}) {
|
||||
const completionStep = getCompletionStep(step, options);
|
||||
const authLoginStep = completionStep >= 11 ? 10 : 7;
|
||||
const signupTabId = await getTabId('signup-page');
|
||||
if (!signupTabId) {
|
||||
throw new Error('认证页面标签页已关闭,无法填写验证码。');
|
||||
@@ -1028,7 +1065,9 @@
|
||||
timeoutMs: Math.max(baseResponseTimeoutMs + 15000, 30000),
|
||||
retryDelayMs: 700,
|
||||
responseTimeoutMs: baseResponseTimeoutMs,
|
||||
logMessage: `步骤 ${step}:认证页正在切换,等待页面重新就绪后继续确认验证码提交结果...`,
|
||||
logMessage: '认证页正在切换,等待页面重新就绪后继续确认验证码提交结果...',
|
||||
logStep: completionStep,
|
||||
logStepKey: step === 4 ? 'fetch-signup-code' : 'fetch-login-code',
|
||||
});
|
||||
} catch (err) {
|
||||
if (step === 4 && isRetryableVerificationTransportError(err)) {
|
||||
@@ -1058,9 +1097,15 @@
|
||||
});
|
||||
if (fallback.success) {
|
||||
if (fallback.addPhonePage) {
|
||||
await addLog('步骤 8:验证码提交后通信中断,但页面已进入手机号验证页,按提交成功继续。', 'warn');
|
||||
await addLog('验证码提交后通信中断,但页面已进入手机号验证页,按提交成功继续。', 'warn', {
|
||||
step: completionStep,
|
||||
stepKey: 'fetch-login-code',
|
||||
});
|
||||
} else {
|
||||
await addLog('步骤 8:验证码提交后通信中断,但页面已进入 OAuth 授权页,按提交成功继续。', 'warn');
|
||||
await addLog('验证码提交后通信中断,但页面已进入 OAuth 授权页,按提交成功继续。', 'warn', {
|
||||
step: completionStep,
|
||||
stepKey: 'fetch-login-code',
|
||||
});
|
||||
}
|
||||
return {
|
||||
success: true,
|
||||
@@ -1072,7 +1117,7 @@
|
||||
}
|
||||
if (fallback.restartStep7) {
|
||||
const urlPart = fallback.url ? ` URL: ${fallback.url}` : '';
|
||||
throw new Error(`STEP8_RESTART_STEP7::步骤 8:验证码提交后认证页进入登录超时报错页,请回到步骤 7 重新开始。${urlPart}`.trim());
|
||||
throw new Error(`STEP8_RESTART_STEP7::步骤 ${completionStep}:验证码提交后认证页进入登录超时报错页,请回到步骤 ${authLoginStep} 重新开始。${urlPart}`.trim());
|
||||
}
|
||||
}
|
||||
throw err;
|
||||
@@ -1092,6 +1137,7 @@
|
||||
|
||||
async function resolveVerificationStep(step, state, mail, options = {}) {
|
||||
const completionStep = getCompletionStep(step, options);
|
||||
activeVerificationLogStep = completionStep;
|
||||
const stateKey = getVerificationCodeStateKey(step);
|
||||
const rejectedCodes = new Set();
|
||||
const hotmailPollConfig = mail.provider === HOTMAIL_PROVIDER
|
||||
|
||||
Reference in New Issue
Block a user