fix: stop kiro auto-run on proxy error pages

This commit is contained in:
QLHazyCoder
2026-05-19 02:04:32 +08:00
parent 09319c20a9
commit 702e969deb
9 changed files with 361 additions and 9 deletions
+25 -2
View File
@@ -4,6 +4,7 @@ const KIRO_DESKTOP_AUTHORIZE_LISTENER_SENTINEL = 'data-multipage-kiro-desktop-au
const KIRO_DESKTOP_ALLOW_TEXT_PATTERN = /allow access|authorize|continue|allow|允许访问|授权|继续/i;
const KIRO_DESKTOP_LOADING_TEXT_PATTERN = /loading|redirecting|please wait|加载中|跳转中|请稍候/i;
const KIRO_DESKTOP_CLOUDFRONT_403_TEXT_PATTERN = /403 error|the request could not be satisfied|generated by cloudfront/i;
const KIRO_DESKTOP_AWS_REQUEST_ERROR_TEXT_PATTERN = /sorry,\s*there was an error processing your request\.?\s*please try again\.?|抱歉,处理您的请求时出错。请重试。?/i;
const KIRO_DESKTOP_EMAIL_INPUT_SELECTOR = [
'input[placeholder="username@example.com"]',
@@ -94,8 +95,30 @@ function findDesktopActionButton(options = {}) {
return pool[0] || null;
}
function isKiroDesktopAuthHost(hostname = '') {
const normalized = String(hostname || '').trim().toLowerCase();
return normalized === 'view.awsapps.com'
|| normalized === 'login.awsapps.com'
|| normalized === 'profile.aws.amazon.com'
|| normalized === 'profile.aws'
|| normalized.endsWith('.profile.aws.amazon.com')
|| normalized.endsWith('.profile.aws')
|| normalized === 'signin.aws.amazon.com'
|| normalized === 'signin.aws'
|| normalized.endsWith('.signin.aws.amazon.com')
|| normalized.endsWith('.signin.aws');
}
function detectDesktopFatalState(pageText = '', currentUrl = '', pageTitle = '') {
const combinedText = `${pageTitle} ${pageText}`.replace(/\s+/g, ' ').trim();
const isKiroAuthHost = isKiroDesktopAuthHost(location.hostname || '');
if (isKiroAuthHost && KIRO_DESKTOP_AWS_REQUEST_ERROR_TEXT_PATTERN.test(combinedText)) {
return {
state: 'proxy_error_page',
url: currentUrl,
fatalMessage: 'Kiro 桌面授权页出现 AWS 请求异常,通常是当前代理 IP 或出口区域异常,请先切换代理后再重试。',
};
}
if (KIRO_DESKTOP_CLOUDFRONT_403_TEXT_PATTERN.test(combinedText)) {
return {
state: 'cloudfront_403_page',
@@ -204,8 +227,8 @@ function detectKiroDesktopAuthorizeState() {
async function getCurrentDesktopAuthorizeState() {
const detected = detectKiroDesktopAuthorizeState();
if (detected.state === 'cloudfront_403_page') {
throw new Error(detected.fatalMessage || 'Kiro 桌面授权页出现 403。');
if (detected.state === 'cloudfront_403_page' || detected.state === 'proxy_error_page') {
throw new Error(detected.fatalMessage || 'Kiro 桌面授权页出现代理异常。');
}
if (detected.state === 'callback_error') {
throw new Error(`Kiro 桌面授权回调失败:${detected.error || 'unknown_error'}`);