fix(tabs): avoid raising automation window

This commit is contained in:
朴圣佑
2026-05-12 11:07:11 +08:00
parent 2bb34f9064
commit 80c3e6217f
3 changed files with 25 additions and 43 deletions
+3 -16
View File
@@ -36,22 +36,9 @@
return null; return null;
} }
if (typeof chrome?.tabs?.get === 'function' && typeof chrome?.windows?.update === 'function') { // Do not request window focus here. The automation tab is already
try { // locked to the selected Chrome window; raising that window would
const tab = await chrome.tabs.get(tabId); // interrupt the user's active workspace.
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.
}
}
if (typeof addLog === 'function') { if (typeof addLog === 'function') {
await addLog( await addLog(
+6 -26
View File
@@ -185,31 +185,11 @@
}); });
} }
async function normalizeSignupTabWindowForStep2(tabId) { async function keepSignupTabWindowInBackgroundForStep2(tabId) {
if ( // Intentionally no-op: the task tab is locked to the selected Chrome
!Number.isInteger(tabId) // window by the tab-runtime layer. Step 2 must not focus/raise that
|| typeof chrome?.tabs?.get !== 'function' // window while the user is working in another app or browser window.
|| typeof chrome?.windows?.update !== 'function' void tabId;
) {
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 ensureSignupPhoneEntryReady(tabId) { async function ensureSignupPhoneEntryReady(tabId) {
@@ -257,7 +237,7 @@
signupTabId = (await ensureSignupEntryPageReady(2)).tabId; signupTabId = (await ensureSignupEntryPageReady(2)).tabId;
} else { } else {
await chrome.tabs.update(signupTabId, { active: true }); await chrome.tabs.update(signupTabId, { active: true });
await normalizeSignupTabWindowForStep2(signupTabId); await keepSignupTabWindowInBackgroundForStep2(signupTabId);
await waitForStep2SignupTabToSettle( await waitForStep2SignupTabToSettle(
signupTabId, signupTabId,
'步骤 2:已切换到注册页标签,正在等待页面加载完成并额外稳定 3 秒...' '步骤 2:已切换到注册页标签,正在等待页面加载完成并额外稳定 3 秒...'
@@ -442,7 +442,12 @@ test('step 2 waits for the existing signup tab to settle before probing the entr
update: async () => { update: async () => {
events.push('tab-update'); 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) => { 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 }); logs.push({ message, level, meta });
}, },
buildGeneratedAliasEmail: () => '', 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 () => { ensureContentScriptReadyOnTab: async () => {
events.push('content-ready'); events.push('content-ready');
}, },