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;
}
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(
+6 -26
View File
@@ -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 秒...'
@@ -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');
},