抽取cookie清理逻辑为新的第六步
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
(function attachBackgroundStep7(root, factory) {
|
||||
root.MultiPageBackgroundStep7 = factory();
|
||||
})(typeof self !== 'undefined' ? self : globalThis, function createBackgroundStep7Module() {
|
||||
function createStep7Executor(deps = {}) {
|
||||
(function attachBackgroundStep8(root, factory) {
|
||||
root.MultiPageBackgroundStep8 = factory();
|
||||
})(typeof self !== 'undefined' ? self : globalThis, function createBackgroundStep8Module() {
|
||||
function createStep8Executor(deps = {}) {
|
||||
const {
|
||||
addLog,
|
||||
chrome,
|
||||
CLOUDFLARE_TEMP_EMAIL_PROVIDER,
|
||||
confirmCustomVerificationStepBypass,
|
||||
ensureStep7VerificationPageReady,
|
||||
executeStep6,
|
||||
ensureStep8VerificationPageReady,
|
||||
executeStep7,
|
||||
getPanelMode,
|
||||
getMailConfig,
|
||||
getState,
|
||||
@@ -29,7 +29,7 @@
|
||||
throwIfStopped,
|
||||
} = deps;
|
||||
|
||||
async function runStep7Attempt(state) {
|
||||
async function runStep8Attempt(state) {
|
||||
const mail = getMailConfig(state);
|
||||
if (mail.error) throw new Error(mail.error);
|
||||
const stepStartedAt = Date.now();
|
||||
@@ -39,25 +39,25 @@
|
||||
await chrome.tabs.update(authTabId, { active: true });
|
||||
} else {
|
||||
if (!state.oauthUrl) {
|
||||
throw new Error('缺少登录用 OAuth 链接,请先完成步骤 6。');
|
||||
throw new Error('缺少登录用 OAuth 链接,请先完成步骤 7。');
|
||||
}
|
||||
await reuseOrCreateTab('signup-page', state.oauthUrl);
|
||||
}
|
||||
|
||||
throwIfStopped();
|
||||
await ensureStep7VerificationPageReady();
|
||||
await addLog('步骤 7:登录验证码页面已就绪,开始获取验证码。', 'info');
|
||||
await ensureStep8VerificationPageReady();
|
||||
await addLog('步骤 8:登录验证码页面已就绪,开始获取验证码。', 'info');
|
||||
|
||||
if (shouldUseCustomRegistrationEmail(state)) {
|
||||
await confirmCustomVerificationStepBypass(7);
|
||||
await confirmCustomVerificationStepBypass(8);
|
||||
return;
|
||||
}
|
||||
|
||||
throwIfStopped();
|
||||
if (mail.provider === HOTMAIL_PROVIDER || mail.provider === LUCKMAIL_PROVIDER || mail.provider === CLOUDFLARE_TEMP_EMAIL_PROVIDER) {
|
||||
await addLog(`步骤 7:正在通过 ${mail.label} 轮询验证码...`);
|
||||
await addLog(`步骤 8:正在通过 ${mail.label} 轮询验证码...`);
|
||||
} else {
|
||||
await addLog(`步骤 7:正在打开${mail.label}...`);
|
||||
await addLog(`步骤 8:正在打开${mail.label}...`);
|
||||
|
||||
const alive = await isTabAlive(mail.source);
|
||||
if (alive) {
|
||||
@@ -79,54 +79,52 @@
|
||||
}
|
||||
|
||||
const shouldRefreshOAuthBeforeSubmit = getPanelMode(state) === 'cpa';
|
||||
let step6ReplayCompleted = false;
|
||||
let step7ReplayCompleted = false;
|
||||
|
||||
await resolveVerificationStep(7, state, mail, {
|
||||
await resolveVerificationStep(8, state, mail, {
|
||||
filterAfterTimestamp: mail.provider === HOTMAIL_PROVIDER ? undefined : Math.max(0, stepStartedAt - 60000),
|
||||
requestFreshCodeFirst: false,
|
||||
resendIntervalMs: (mail.provider === HOTMAIL_PROVIDER || mail.provider === '2925')
|
||||
? 0
|
||||
: STANDARD_MAIL_VERIFICATION_RESEND_INTERVAL_MS,
|
||||
beforeSubmit: shouldRefreshOAuthBeforeSubmit ? async (result) => {
|
||||
if (step6ReplayCompleted) {
|
||||
if (step7ReplayCompleted) {
|
||||
return;
|
||||
}
|
||||
|
||||
step6ReplayCompleted = true;
|
||||
await addLog(`步骤 7:已拿到登录验证码 ${result.code},先刷新 CPA OAuth 链接并重走步骤 6,再回填验证码。`, 'warn');
|
||||
await rerunStep6ForStep7Recovery({
|
||||
logMessage: '步骤 7:正在重新获取最新 CPA OAuth 链接,并快速重走步骤 6...',
|
||||
skipPreLoginCleanup: true,
|
||||
step7ReplayCompleted = true;
|
||||
await addLog(`步骤 8:已拿到登录验证码 ${result.code},先刷新 CPA OAuth 链接并重走步骤 7,再回填验证码。`, 'warn');
|
||||
await rerunStep7ForStep8Recovery({
|
||||
logMessage: '步骤 8:正在重新获取最新 CPA OAuth 链接,并快速重走步骤 7...',
|
||||
postStepDelayMs: 1200,
|
||||
});
|
||||
await ensureStep7VerificationPageReady();
|
||||
await addLog('步骤 7:登录验证码页面已重新就绪,开始回填刚才获取到的验证码。', 'info');
|
||||
await ensureStep8VerificationPageReady();
|
||||
await addLog('步骤 8:登录验证码页面已重新就绪,开始回填刚才获取到的验证码。', 'info');
|
||||
} : undefined,
|
||||
});
|
||||
}
|
||||
|
||||
async function rerunStep6ForStep7Recovery(options = {}) {
|
||||
async function rerunStep7ForStep8Recovery(options = {}) {
|
||||
const {
|
||||
logMessage = '步骤 7:正在回到步骤 6,重新发起登录验证码流程...',
|
||||
skipPreLoginCleanup = false,
|
||||
logMessage = '步骤 8:正在回到步骤 7,重新发起登录验证码流程...',
|
||||
postStepDelayMs = 3000,
|
||||
} = options;
|
||||
const currentState = await getState();
|
||||
await addLog(logMessage, 'warn');
|
||||
await executeStep6(currentState, { skipPreLoginCleanup });
|
||||
await executeStep7(currentState);
|
||||
if (postStepDelayMs > 0) {
|
||||
await sleepWithStop(postStepDelayMs);
|
||||
}
|
||||
}
|
||||
|
||||
async function executeStep7(state) {
|
||||
async function executeStep8(state) {
|
||||
if (shouldSkipLoginVerificationForCpaCallback(state)) {
|
||||
await setState({
|
||||
lastLoginCode: null,
|
||||
loginVerificationRequestedAt: null,
|
||||
});
|
||||
await setStepStatus(7, 'skipped');
|
||||
await addLog('步骤 7:当前已选择“第六步回调”,本轮无需获取登录验证码。', 'warn');
|
||||
await setStepStatus(8, 'skipped');
|
||||
await addLog('步骤 8:当前已选择“第七步回调”,本轮无需获取登录验证码。', 'warn');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -136,7 +134,7 @@
|
||||
|
||||
while (true) {
|
||||
try {
|
||||
await runStep7Attempt(currentState);
|
||||
await runStep8Attempt(currentState);
|
||||
return;
|
||||
} catch (err) {
|
||||
if (!isVerificationMailPollingError(err)) {
|
||||
@@ -150,25 +148,25 @@
|
||||
|
||||
mailPollingAttempt += 1;
|
||||
await addLog(
|
||||
`步骤 7:检测到邮箱轮询类失败,准备从步骤 6 重新开始(${mailPollingAttempt}/${STEP7_MAIL_POLLING_RECOVERY_MAX_ATTEMPTS})...`,
|
||||
`步骤 8:检测到邮箱轮询类失败,准备从步骤 7 重新开始(${mailPollingAttempt}/${STEP7_MAIL_POLLING_RECOVERY_MAX_ATTEMPTS})...`,
|
||||
'warn'
|
||||
);
|
||||
await rerunStep6ForStep7Recovery();
|
||||
await rerunStep7ForStep8Recovery();
|
||||
currentState = await getState();
|
||||
}
|
||||
}
|
||||
|
||||
if (lastMailPollingError) {
|
||||
throw new Error(
|
||||
`步骤 7:登录验证码流程在 ${STEP7_MAIL_POLLING_RECOVERY_MAX_ATTEMPTS} 轮邮箱轮询恢复后仍未成功。最后一次原因:${lastMailPollingError.message}`
|
||||
`步骤 8:登录验证码流程在 ${STEP7_MAIL_POLLING_RECOVERY_MAX_ATTEMPTS} 轮邮箱轮询恢复后仍未成功。最后一次原因:${lastMailPollingError.message}`
|
||||
);
|
||||
}
|
||||
|
||||
throw new Error('步骤 7:登录验证码流程未成功完成。');
|
||||
throw new Error('步骤 8:登录验证码流程未成功完成。');
|
||||
}
|
||||
|
||||
return { executeStep7 };
|
||||
return { executeStep8 };
|
||||
}
|
||||
|
||||
return { createStep7Executor };
|
||||
return { createStep8Executor };
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user