feat: 自动登录增加适配器名称

This commit is contained in:
foxhui
2025-12-15 16:57:40 +08:00
parent 09806cda16
commit 6eb8229ae3
2 changed files with 14 additions and 14 deletions
+7 -7
View File
@@ -39,7 +39,7 @@ async function handleAccountChooser(page) {
const currentUrl = page.url(); const currentUrl = page.url();
if (currentUrl.includes('auth.business.gemini.google/account-chooser')) { if (currentUrl.includes('auth.business.gemini.google/account-chooser')) {
lockPageAuth(page); lockPageAuth(page);
logger.info('适配器', '[登录器] 检测到账户选择页面,尝试自动确认...'); logger.info('适配器', '[登录器(gemini_biz)] 检测到账户选择页面,尝试自动确认...');
// 尝试查找提交按钮 (通常是标准的 button[type="submit"]) // 尝试查找提交按钮 (通常是标准的 button[type="submit"])
const submitBtn = await page.$('button[type="submit"]'); const submitBtn = await page.$('button[type="submit"]');
@@ -49,11 +49,11 @@ async function handleAccountChooser(page) {
await sleep(300, 500); await sleep(300, 500);
// 使用 safeClick 模拟人类点击行为 // 使用 safeClick 模拟人类点击行为
logger.info('适配器', '[登录器] 正在点击确认按钮...'); logger.info('适配器', '[登录器(gemini_biz)] 正在点击确认按钮...');
await safeClick(page, submitBtn, { bias: 'button' }); await safeClick(page, submitBtn, { bias: 'button' });
// 点击后等待跳转回目标页面 // 点击后等待跳转回目标页面
logger.info('适配器', '[登录器] 等待跳转回目标页面...'); logger.info('适配器', '[登录器(gemini_biz)] 等待跳转回目标页面...');
try { try {
await page.waitForFunction(() => { await page.waitForFunction(() => {
const href = window.location.href; const href = window.location.href;
@@ -62,10 +62,10 @@ async function handleAccountChooser(page) {
href.includes('business.gemini.google'); href.includes('business.gemini.google');
}, { timeout: 60000, polling: 1000 }); }, { timeout: 60000, polling: 1000 });
logger.info('适配器', `[登录器] 已跳转回目标页面`); logger.info('适配器', `[登录器(gemini_biz)] 已跳转回目标页面`);
} catch (timeoutErr) { } catch (timeoutErr) {
const finalUrl = page.url(); const finalUrl = page.url();
logger.warn('适配器', `[登录器] 等待跳转回目标页面超时,尝试继续... 当前URL: ${finalUrl}`); logger.warn('适配器', `[登录器(gemini_biz)] 等待跳转回目标页面超时,尝试继续... 当前URL: ${finalUrl}`);
} }
// 额外缓冲时间,确保页面完全加载 // 额外缓冲时间,确保页面完全加载
@@ -74,14 +74,14 @@ async function handleAccountChooser(page) {
return true; return true;
} else { } else {
// 按钮还没加载出来,保持锁,等待下次检查 // 按钮还没加载出来,保持锁,等待下次检查
logger.debug('适配器', '[登录器] 按钮尚未加载,等待中...'); logger.debug('适配器', '[登录器(gemini_biz)] 按钮尚未加载,等待中...');
await sleep(500, 1000); await sleep(500, 1000);
unlockPageAuth(page); // 释放锁让下次尝试 unlockPageAuth(page); // 释放锁让下次尝试
return true; // 返回 true 表示"仍在处理中" return true; // 返回 true 表示"仍在处理中"
} }
} }
} catch (err) { } catch (err) {
logger.warn('适配器', `[登录器] 处理账户选择页面失败: ${err.message}`); logger.warn('适配器', `[登录器(gemini_biz)] 处理账户选择页面失败: ${err.message}`);
unlockPageAuth(page); unlockPageAuth(page);
} }
return false; return false;
+7 -7
View File
@@ -43,18 +43,18 @@ async function handleDiscordAuth(page) {
// 1. 检查是否在 zai.is/auth 页面 // 1. 检查是否在 zai.is/auth 页面
if (currentUrl.includes('zai.is/auth')) { if (currentUrl.includes('zai.is/auth')) {
lockPageAuth(page); lockPageAuth(page);
logger.info('适配器', '[登录器] 检测到登录页面,正在处理 Discord 登录...'); logger.info('适配器', '[登录器(zai_is)] 检测到登录页面,正在处理 Discord 登录...');
try { try {
// 等待页面加载完成,点击唯一的 button 标签 // 等待页面加载完成,点击唯一的 button 标签
await page.waitForSelector('button', { timeout: 30000 }); await page.waitForSelector('button', { timeout: 30000 });
await sleep(1000, 1500); await sleep(1000, 1500);
await safeClick(page, 'button', { bias: 'button' }); await safeClick(page, 'button', { bias: 'button' });
logger.info('适配器', '[登录器] 已点击登录按钮,等待跳转到 Discord...'); logger.info('适配器', '[登录器(zai_is)] 已点击登录按钮,等待跳转到 Discord...');
// 2. 等待跳转到 Discord OAuth2 授权页面 // 2. 等待跳转到 Discord OAuth2 授权页面
await page.waitForURL(url => url.href.includes('discord.com/oauth2/authorize'), { timeout: 60000 }); await page.waitForURL(url => url.href.includes('discord.com/oauth2/authorize'), { timeout: 60000 });
logger.info('适配器', '[登录器] 已到达 Discord 授权页面'); logger.info('适配器', '[登录器(zai_is)] 已到达 Discord 授权页面');
await sleep(2000, 3000); await sleep(2000, 3000);
// 3. 使用鼠标滚轮滚动 main 元素,直到授权按钮可用 // 3. 使用鼠标滚轮滚动 main 元素,直到授权按钮可用
@@ -66,7 +66,7 @@ async function handleDiscordAuth(page) {
if (authorizeBtn) { if (authorizeBtn) {
const isDisabled = await authorizeBtn.evaluate(el => el.disabled).catch(() => true); const isDisabled = await authorizeBtn.evaluate(el => el.disabled).catch(() => true);
if (!isDisabled) { if (!isDisabled) {
logger.info('适配器', '[登录器] 授权按钮已可用,正在点击...'); logger.info('适配器', '[登录器(zai_is)] 授权按钮已可用,正在点击...');
await sleep(500, 1000); await sleep(500, 1000);
await safeClick(page, authorizeBtn, { bias: 'button' }); await safeClick(page, authorizeBtn, { bias: 'button' });
break; break;
@@ -86,7 +86,7 @@ async function handleDiscordAuth(page) {
} }
// 4. 等待跳转回 zai.is (不包含 auth 和 discord) // 4. 等待跳转回 zai.is (不包含 auth 和 discord)
logger.info('适配器', '[登录器] 等待跳转回目标页面...'); logger.info('适配器', '[登录器(zai_is)] 等待跳转回目标页面...');
await page.waitForURL(url => { await page.waitForURL(url => {
const href = url.href; const href = url.href;
return href.includes('zai.is') && return href.includes('zai.is') &&
@@ -94,12 +94,12 @@ async function handleDiscordAuth(page) {
!href.includes('discord.com'); !href.includes('discord.com');
}, { timeout: 60000 }); }, { timeout: 60000 });
logger.info('适配器', '[登录器] Discord 登录完成'); logger.info('适配器', '[登录器(zai_is)] Discord 登录完成');
await sleep(2000, 3000); await sleep(2000, 3000);
unlockPageAuth(page); unlockPageAuth(page);
return true; return true;
} catch (err) { } catch (err) {
logger.warn('适配器', `[登录器] Discord 登录处理失败: ${err.message}`); logger.warn('适配器', `[登录器(zai_is)] Discord 登录处理失败: ${err.message}`);
unlockPageAuth(page); unlockPageAuth(page);
} }
} }