fix: 修复 Gemini 图片懒加载导致等待超时

This commit is contained in:
foxhui
2025-12-27 01:58:10 +08:00
Unverified
parent d84c235c64
commit c88c34aa4a
4 changed files with 34 additions and 16 deletions
+5
View File
@@ -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
+9 -2
View File
@@ -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;
+1 -1
View File
@@ -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) {
+19 -13
View File
@@ -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) {