diff --git a/background/steps/oauth-login.js b/background/steps/oauth-login.js index f24178e..6a323ce 100644 --- a/background/steps/oauth-login.js +++ b/background/steps/oauth-login.js @@ -75,7 +75,7 @@ await addLog(`步骤 7:上一轮失败后,正在进行第 ${attempt} 次尝试(最多 ${STEP6_MAX_ATTEMPTS} 次)...`, 'warn'); } - await reuseOrCreateTab('signup-page', oauthUrl); + await reuseOrCreateTab('signup-page', oauthUrl, { forceNew: true }); const result = await sendToContentScriptResilient( 'signup-page', diff --git a/background/tab-runtime.js b/background/tab-runtime.js index 17b3275..6a4c004 100644 --- a/background/tab-runtime.js +++ b/background/tab-runtime.js @@ -527,6 +527,31 @@ } async function reuseOrCreateTab(source, url, options = {}) { + if (options.forceNew) { + await closeConflictingTabsForSource(source, url); + const tab = await chrome.tabs.create({ url, active: true }); + + if (options.inject) { + await waitForTabUpdateComplete(tab.id); + if (options.injectSource) { + await chrome.scripting.executeScript({ + target: { tabId: tab.id }, + func: (injectedSource) => { + window.__MULTIPAGE_SOURCE = injectedSource; + }, + args: [options.injectSource], + }); + } + await chrome.scripting.executeScript({ + target: { tabId: tab.id }, + files: options.inject, + }); + } + + await rememberSourceLastUrl(source, url); + return tab.id; + } + const alive = await isTabAlive(source); if (alive) { const tabId = await getTabId(source);