mirror of
https://github.com/foxhui/WebAI2API.git
synced 2026-06-16 21:03:59 +08:00
feat: 修改监听跳转的逻辑为任何时候被触发都执行自动登录
This commit is contained in:
+15
-1
@@ -174,6 +174,7 @@ function getPersistentFingerprint(filePath) {
|
||||
* @param {string} options.productName - 产品名称(用于日志)
|
||||
* @param {boolean} [options.reuseExistingTab=false] - 是否复用已有特定域名的 tab
|
||||
* @param {Function} [options.waitInputValidator] - 自定义输入框等待验证函数
|
||||
* @param {Function} [options.navigationHandler] - 全局导航处理器,用于自动处理登录等跳转
|
||||
* @returns {Promise<{browser: object, page: object, client: object}>}
|
||||
*/
|
||||
export async function initBrowserBase(config, options) {
|
||||
@@ -181,7 +182,8 @@ export async function initBrowserBase(config, options) {
|
||||
userDataDir,
|
||||
targetUrl,
|
||||
productName,
|
||||
waitInputValidator = null
|
||||
waitInputValidator = null,
|
||||
navigationHandler = null
|
||||
} = options;
|
||||
|
||||
// 检测登录模式和 Xvfb 模式
|
||||
@@ -275,6 +277,18 @@ export async function initBrowserBase(config, options) {
|
||||
await page.setViewportSize(camoufoxLaunchOptions.viewport);
|
||||
}
|
||||
|
||||
// 注册全局导航处理器(用于自动处理登录等跳转)
|
||||
if (navigationHandler) {
|
||||
page.on('framenavigated', async () => {
|
||||
try {
|
||||
await navigationHandler(page);
|
||||
} catch (e) {
|
||||
logger.warn('浏览器', `全局导航处理器出错: ${e.message}`);
|
||||
}
|
||||
});
|
||||
logger.debug('浏览器', '已注册全局导航处理器');
|
||||
}
|
||||
|
||||
// 登录模式挂起逻辑
|
||||
if (isLoginMode) {
|
||||
// 尝试导航到目标页面方便用户登录
|
||||
|
||||
Reference in New Issue
Block a user