diff --git a/CHANGELOG.md b/CHANGELOG.md index b52a065..1490fda 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [3.4.3] - 2025-12-26 + +### 🐛 Fixed +- **Gemini**:修复因懒加载导致的等待图片超时问题 + ## [3.4.2] - 2025-12-25 ### 🔄 Changed diff --git a/src/backend/adapter/gemini.js b/src/backend/adapter/gemini.js index ae4454c..e83c120 100644 --- a/src/backend/adapter/gemini.js +++ b/src/backend/adapter/gemini.js @@ -14,7 +14,8 @@ import { moveMouseAway, waitForInput, gotoWithCheck, - waitApiResponse + waitApiResponse, + scrollToElement } from '../utils/index.js'; import { logger } from '../../utils/logger.js'; @@ -163,13 +164,19 @@ async function generate(context, prompt, imgPaths, modelId, meta = {}) { let imageResponse; try { - imageResponse = await waitApiResponse(page, { + // 先启动监听器,再滚动触发懒加载,避免错过请求 + const imageResponsePromise = waitApiResponse(page, { urlMatch: 'googleusercontent.com/rd-gg-dl', urlContains: '=s1024-rj', method: 'GET', timeout: 60000, meta }); + + // 等待图片元素出现并滚动到可视范围,触发懒加载 + await scrollToElement(page, 'model-response', { timeout: 20000 }); + + imageResponse = await imageResponsePromise; } catch (e) { const pageError = normalizePageError(e, meta); if (pageError) return pageError; diff --git a/src/backend/adapter/gemini_biz.js b/src/backend/adapter/gemini_biz.js index f3dc74b..49e0574 100644 --- a/src/backend/adapter/gemini_biz.js +++ b/src/backend/adapter/gemini_biz.js @@ -239,7 +239,7 @@ async function generate(context, prompt, imgPaths, modelId, meta = {}) { }); // 等待图片元素出现并滚动到可视范围,触发懒加载 - await scrollToElement(page, 'ucs-markdown-image', { timeout: 10000 }); + await scrollToElement(page, 'ucs-markdown-image', { timeout: 20000 }); imageResponse = await imageResponsePromise; } catch (e) { diff --git a/src/backend/pool/Worker.js b/src/backend/pool/Worker.js index 4e4aee3..f609386 100644 --- a/src/backend/pool/Worker.js +++ b/src/backend/pool/Worker.js @@ -58,21 +58,27 @@ export class Worker { targetUrl = registry.getTargetUrl(this.type, this.globalConfig, this.workerConfig) || 'about:blank'; } - // 收集导航处理器 - const handlers = []; - const typesToHandle = this.type === 'merge' ? this.mergeTypes : [this.type]; - for (const type of typesToHandle) { - const typeHandlers = registry.getNavigationHandlers(type); - handlers.push(...typeHandlers); - } + // 登录模式下不注册导航处理器,避免自动登录干预用户操作 + const isLoginMode = process.argv.some(arg => arg.startsWith('-login')); + let navigationHandler = null; - const navigationHandler = handlers.length > 0 - ? async (page) => { - for (const handler of handlers) { - try { await handler(page); } catch (e) { /* ignore */ } - } + if (!isLoginMode) { + // 收集导航处理器 + const handlers = []; + const typesToHandle = this.type === 'merge' ? this.mergeTypes : [this.type]; + for (const type of typesToHandle) { + const typeHandlers = registry.getNavigationHandlers(type); + handlers.push(...typeHandlers); } - : null; + + navigationHandler = handlers.length > 0 + ? async (page) => { + for (const handler of handlers) { + try { await handler(page); } catch (e) { /* ignore */ } + } + } + : null; + } logger.info('工作池', `[${this.name}] 正在初始化浏览器...`); if (this.proxyConfig) {