From 08c361711c25947d8388a7ab6fcca0e69b6a4b5d Mon Sep 17 00:00:00 2001 From: QLHazyCoder <2825305047@qq.com> Date: Sat, 25 Apr 2026 19:33:36 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=B3=A8=E5=86=8C?= =?UTF-8?q?=E6=B5=81=E7=A8=8B=E4=B8=AD=E5=AF=B9=E5=B7=B2=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E7=9A=84=E5=A4=84=E7=90=86=EF=BC=8C=E7=A1=AE?= =?UTF-8?q?=E4=BF=9D=E5=9C=A8=20ChatGPT=20=E9=A6=96=E9=A1=B5=E6=97=B6?= =?UTF-8?q?=E6=8A=9B=E5=87=BA=E6=98=8E=E7=A1=AE=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- background/steps/submit-signup-email.js | 31 +++++-------------- .../background-signup-step2-branching.test.js | 17 +--------- 2 files changed, 8 insertions(+), 40 deletions(-) diff --git a/background/steps/submit-signup-email.js b/background/steps/submit-signup-email.js index 2fd1839..3b6be68 100644 --- a/background/steps/submit-signup-email.js +++ b/background/steps/submit-signup-email.js @@ -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)) { diff --git a/tests/background-signup-step2-branching.test.js b/tests/background-signup-step2-branching.test.js index 55b7097..c38cb40 100644 --- a/tests/background-signup-step2-branching.test.js +++ b/tests/background-signup-step2-branching.test.js @@ -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, [