fix: 修复 Gemini Business 自动续登监听被多次触发的问题

This commit is contained in:
foxhui
2025-12-11 02:03:10 +08:00
Unverified
parent bdf0a1412b
commit db6e3cd86c
+10
View File
@@ -17,6 +17,9 @@ import { logger } from '../../utils/logger.js';
// Gemini Biz 输入框选择器
const INPUT_SELECTOR = 'ucs-prosemirror-editor .ProseMirror';
// 防止重复处理登录的锁
let isHandlingAuth = false;
/**
* 处理账户选择页面跳转
* @param {import('puppeteer').Page} page
@@ -24,9 +27,13 @@ const INPUT_SELECTOR = 'ucs-prosemirror-editor .ProseMirror';
* @returns {Promise<boolean>} 是否处理了跳转
*/
async function handleAccountChooser(page) {
// 防止重复处理
if (isHandlingAuth) return false;
try {
const currentUrl = page.url();
if (currentUrl.includes('auth.business.gemini.google/account-chooser')) {
isHandlingAuth = true;
logger.info('适配器', '[登录器] 检测到账户选择页面,尝试自动确认...');
// 尝试查找提交按钮 (通常是标准的 button[type="submit"])
@@ -58,13 +65,16 @@ async function handleAccountChooser(page) {
// 额外缓冲时间,确保页面完全加载
await sleep(2000, 3000);
isHandlingAuth = false;
return true;
} else {
logger.warn('适配器', '[登录器] 未找到确认按钮 button[type="submit"]');
isHandlingAuth = false;
}
}
} catch (err) {
logger.warn('适配器', `[登录器] 处理账户选择页面失败: ${err.message}`);
isHandlingAuth = false;
}
return false;
}