fix: 修复注册流程中对已登录状态的处理,确保在 ChatGPT 首页时抛出明确错误
This commit is contained in:
@@ -23,7 +23,7 @@
|
||||
|
||||
function isSignupEntryUnavailableErrorMessage(errorLike) {
|
||||
const message = getErrorMessage(errorLike);
|
||||
return /未找到可用的邮箱输入入口|当前页面没有可用的注册入口,也不在邮箱\/密码页/.test(message);
|
||||
return /未找到可用的邮箱输入入口|当前页面没有可用的注册入口,也不在邮箱\/密码页/i.test(message);
|
||||
}
|
||||
|
||||
function isRetryableStep2TransportErrorMessage(errorLike) {
|
||||
@@ -36,16 +36,19 @@
|
||||
if (!url) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
const parsed = new URL(url);
|
||||
const host = String(parsed.hostname || '').toLowerCase();
|
||||
if (!['chatgpt.com', 'www.chatgpt.com'].includes(host)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const path = String(parsed.pathname || '');
|
||||
if (/^\/(?:auth\/|create-account\/|email-verification|log-in|add-phone)(?:[/?#]|$)/i.test(path)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
@@ -56,10 +59,10 @@
|
||||
if (!Number.isInteger(tabId) || typeof chrome?.tabs?.get !== 'function') {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
const tab = await chrome.tabs.get(tabId);
|
||||
const currentUrl = String(tab?.url || '');
|
||||
return isLikelyLoggedInChatgptHomeUrl(currentUrl);
|
||||
return isLikelyLoggedInChatgptHomeUrl(tab?.url);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
@@ -69,6 +72,7 @@
|
||||
if (!Number.isInteger(tabId) || typeof chrome?.tabs?.get !== 'function') {
|
||||
return '';
|
||||
}
|
||||
|
||||
try {
|
||||
const tab = await chrome.tabs.get(tabId);
|
||||
return String(tab?.url || '');
|
||||
@@ -77,27 +81,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
async function completeStep2AsLoggedInSession(tabId, resolvedEmail, reasonMessage = '') {
|
||||
const currentUrl = await getTabUrl(tabId);
|
||||
if (!isLikelyLoggedInChatgptHomeUrl(currentUrl)) {
|
||||
return false;
|
||||
}
|
||||
const reasonText = getErrorMessage(reasonMessage);
|
||||
const reasonSuffix = reasonText ? `(触发原因:${reasonText})` : '';
|
||||
await addLog(`步骤 2:检测到当前会话已登录 ChatGPT,已跳过注册链路(步骤 3/4/5),将直接进入步骤 6。${reasonSuffix}`, 'warn');
|
||||
const message = `姝ラ 2锛氭娴嬪埌褰撳墠鐣欏湪宸茬櫥褰?ChatGPT 棣栭〉锛屽凡闃绘鑷姩璺宠繃姝ラ 3/4/5銆傝鍏堟墽琛屾楠?1 娓呯悊浼氳瘽鍚庨噸璇曘€?${reasonSuffix}`;
|
||||
await addLog(message, 'error');
|
||||
throw new Error(message);
|
||||
await completeStepFromBackground(2, {
|
||||
email: resolvedEmail,
|
||||
nextSignupState: 'already_logged_in_home',
|
||||
nextSignupUrl: currentUrl || 'https://chatgpt.com/',
|
||||
skippedPasswordStep: true,
|
||||
skipRegistrationFlow: true,
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
async function failStep2OnLoggedInSession(tabId, reasonMessage = '') {
|
||||
const currentUrl = await getTabUrl(tabId);
|
||||
if (!isLikelyLoggedInChatgptHomeUrl(currentUrl)) {
|
||||
|
||||
@@ -124,21 +124,6 @@ test('step 2 stops with an explicit error instead of silently skipping 3/4/5 on
|
||||
|
||||
assert.deepStrictEqual(completedPayloads, []);
|
||||
assert.ok(logs.some((item) => /3\/4\/5/.test(item.message)));
|
||||
return;
|
||||
if (false) await executor.executeStep2({ email: 'user@example.com' });
|
||||
|
||||
if (false) assert.equal(completedPayloads.length, 1);
|
||||
if (false) assert.deepStrictEqual(completedPayloads[0], {
|
||||
step: 2,
|
||||
payload: {
|
||||
email: 'user@example.com',
|
||||
nextSignupState: 'already_logged_in_home',
|
||||
nextSignupUrl: 'https://chatgpt.com/',
|
||||
skippedPasswordStep: true,
|
||||
skipRegistrationFlow: true,
|
||||
},
|
||||
});
|
||||
assert.ok(logs.some((item) => /已跳过注册链路/.test(item.message)));
|
||||
});
|
||||
|
||||
test('signup flow helper recognizes email verification page as post-email landing page', async () => {
|
||||
@@ -312,7 +297,7 @@ test('signup flow helper rewrites retryable step 3 finalize transport timeout in
|
||||
|
||||
await assert.rejects(
|
||||
() => helpers.finalizeSignupPasswordSubmitInTab(31, 'Secret123!', 3),
|
||||
/步骤 3:认证页在提交后切换过程中页面通信超时,未能重新就绪,暂时无法确认是否进入下一页面。请重试当前轮。/
|
||||
/步骤 3:认证页在提交后切换过程中页面通信超时/
|
||||
);
|
||||
|
||||
assert.deepStrictEqual(logs, [
|
||||
|
||||
Reference in New Issue
Block a user