diff --git a/background/signup-flow-helpers.js b/background/signup-flow-helpers.js index 0009105..35f372e 100644 --- a/background/signup-flow-helpers.js +++ b/background/signup-flow-helpers.js @@ -36,22 +36,9 @@ return null; } - if (typeof chrome?.tabs?.get === 'function' && typeof chrome?.windows?.update === 'function') { - try { - const tab = await chrome.tabs.get(tabId); - const windowId = Number(tab?.windowId); - if (Number.isInteger(windowId) && windowId >= 0) { - await chrome.windows.update(windowId, { state: 'normal', focused: true }).catch(() => {}); - await chrome.windows.update(windowId, { - focused: true, - width: 1200, - height: 900, - }).catch(() => {}); - } - } catch { - // Best-effort only. Step 2 still has content-side entry retries. - } - } + // Do not request window focus here. The automation tab is already + // locked to the selected Chrome window; raising that window would + // interrupt the user's active workspace. if (typeof addLog === 'function') { await addLog( diff --git a/background/steps/submit-signup-email.js b/background/steps/submit-signup-email.js index 49e75f0..c484f09 100644 --- a/background/steps/submit-signup-email.js +++ b/background/steps/submit-signup-email.js @@ -185,31 +185,11 @@ }); } - async function normalizeSignupTabWindowForStep2(tabId) { - if ( - !Number.isInteger(tabId) - || typeof chrome?.tabs?.get !== 'function' - || typeof chrome?.windows?.update !== 'function' - ) { - return; - } - - try { - const tab = await chrome.tabs.get(tabId); - const windowId = Number(tab?.windowId); - if (!Number.isInteger(windowId) || windowId < 0) { - return; - } - - await chrome.windows.update(windowId, { state: 'normal', focused: true }).catch(() => {}); - await chrome.windows.update(windowId, { - focused: true, - width: 1200, - height: 900, - }).catch(() => {}); - } catch { - // Best-effort only: content-side retries still handle layout recovery. - } + async function keepSignupTabWindowInBackgroundForStep2(tabId) { + // Intentionally no-op: the task tab is locked to the selected Chrome + // window by the tab-runtime layer. Step 2 must not focus/raise that + // window while the user is working in another app or browser window. + void tabId; } async function ensureSignupPhoneEntryReady(tabId) { @@ -257,7 +237,7 @@ signupTabId = (await ensureSignupEntryPageReady(2)).tabId; } else { await chrome.tabs.update(signupTabId, { active: true }); - await normalizeSignupTabWindowForStep2(signupTabId); + await keepSignupTabWindowInBackgroundForStep2(signupTabId); await waitForStep2SignupTabToSettle( signupTabId, '步骤 2:已切换到注册页标签,正在等待页面加载完成并额外稳定 3 秒...' diff --git a/tests/background-signup-step2-branching.test.js b/tests/background-signup-step2-branching.test.js index 7a3b663..864f685 100644 --- a/tests/background-signup-step2-branching.test.js +++ b/tests/background-signup-step2-branching.test.js @@ -442,7 +442,12 @@ test('step 2 waits for the existing signup tab to settle before probing the entr update: async () => { events.push('tab-update'); }, - get: async () => ({ url: 'https://chatgpt.com/' }), + get: async () => ({ id: 17, windowId: 91, url: 'https://chatgpt.com/' }), + }, + windows: { + update: async () => { + throw new Error('step 2 must not focus or raise the automation window'); + }, }, }, completeStepFromBackground: async (step, payload) => { @@ -565,6 +570,16 @@ test('signup flow helper waits for the signup entry tab to settle for step 2 bef logs.push({ message, level, meta }); }, buildGeneratedAliasEmail: () => '', + chrome: { + tabs: { + get: async () => ({ id: 23, windowId: 92, url: 'https://chatgpt.com/' }), + }, + windows: { + update: async () => { + throw new Error('signup entry helper must not focus or raise the automation window'); + }, + }, + }, ensureContentScriptReadyOnTab: async () => { events.push('content-ready'); },