fix kiro verification active page adoption

This commit is contained in:
QLHazyCoder
2026-05-22 12:20:54 +08:00
parent d0f6972268
commit ffa6ed7602
2 changed files with 145 additions and 0 deletions
+57
View File
@@ -444,6 +444,52 @@
return Boolean(await chrome.tabs.get(tabId).catch(() => null));
}
function isKiroRegisterCandidateUrl(rawUrl = '') {
let parsed = null;
try {
parsed = new URL(String(rawUrl || '').trim());
} catch (_error) {
return false;
}
if (!['http:', 'https:'].includes(parsed.protocol)) {
return false;
}
const hostname = parsed.hostname.toLowerCase();
return hostname === 'app.kiro.dev'
|| hostname === 'kiro.dev'
|| hostname === 'view.awsapps.com'
|| hostname === 'login.awsapps.com'
|| hostname === 'profile.aws.amazon.com'
|| hostname === 'profile.aws'
|| hostname.endsWith('.profile.aws.amazon.com')
|| hostname.endsWith('.profile.aws')
|| hostname === 'signin.aws.amazon.com'
|| hostname === 'signin.aws'
|| hostname.endsWith('.signin.aws.amazon.com')
|| hostname.endsWith('.signin.aws');
}
async function getActiveKiroRegisterTabId() {
if (!chrome?.tabs?.query) {
return null;
}
const queryAttempts = [
{ active: true, lastFocusedWindow: true },
{ active: true, currentWindow: true },
{ active: true },
];
for (const queryInfo of queryAttempts) {
const tabs = await chrome.tabs.query(queryInfo).catch(() => []);
const matchedTab = (Array.isArray(tabs) ? tabs : []).find((tab) => (
Number.isInteger(tab?.id) && isKiroRegisterCandidateUrl(tab?.url)
));
if (Number.isInteger(matchedTab?.id)) {
return matchedTab.id;
}
}
return null;
}
async function getExecutionState(state = {}) {
if (state && typeof state === 'object' && !Array.isArray(state) && Object.keys(state).length) {
return state;
@@ -521,6 +567,17 @@
return tabId;
}
const activeKiroTabId = await getActiveKiroRegisterTabId();
if (Number.isInteger(activeKiroTabId)) {
await registerTab(KIRO_REGISTER_PAGE_SOURCE_ID, activeKiroTabId);
await setState(mergeRuntimePatch(state, {
session: {
registerTabId: activeKiroTabId,
},
}));
return activeKiroTabId;
}
if (!loginUrl) {
throw new Error(options.missingUrlMessage || '缺少 Kiro 注册页地址,请先执行步骤 1。');
}