rm: 移除操作完毕后模拟移开鼠标的步骤

This commit is contained in:
foxhui
2026-01-19 03:44:06 +08:00
Unverified
parent 85be113b40
commit 33345db391
22 changed files with 35 additions and 117 deletions
+6
View File
@@ -5,6 +5,12 @@ 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.8] - 2026-01-19
### 🔄 Changed
- **操作流程**
- 操作完成后不再模拟移开鼠标的步骤,加快响应速度减少故障概率
## [3.4.8] - 2026-01-18
### 🔄 Changed
+1 -5
View File
@@ -10,7 +10,6 @@ import {
} from '../engine/utils.js';
import {
normalizePageError,
moveMouseAway,
waitForInput,
gotoWithCheck,
waitApiResponse,
@@ -176,10 +175,7 @@ async function generate(context, prompt, imgPaths, modelId, meta = {}) {
logger.error('适配器', '生成任务失败', { ...meta, error: err.message });
return { error: `生成任务失败: ${err.message}` };
} finally {
// 任务结束,将鼠标移至安全区域
await moveMouseAway(page);
}
} finally { }
}
/**
+2 -7
View File
@@ -10,10 +10,8 @@ import {
} from '../engine/utils.js';
import {
normalizePageError,
moveMouseAway,
waitForInput,
gotoWithCheck,
waitApiResponse
gotoWithCheck
} from '../utils/index.js';
import { logger } from '../../utils/logger.js';
@@ -248,10 +246,7 @@ async function generate(context, prompt, imgPaths, modelId, meta = {}) {
logger.error('适配器', '生成任务失败', { ...meta, error: err.message });
return { error: `生成任务失败: ${err.message}` };
} finally {
// 任务结束,将鼠标移至安全区域
await moveMouseAway(page);
}
} finally { }
}
/**
+1 -5
View File
@@ -9,7 +9,6 @@ import {
} from '../engine/utils.js';
import {
normalizePageError,
moveMouseAway,
waitForInput,
gotoWithCheck
} from '../utils/index.js';
@@ -264,10 +263,7 @@ async function generate(context, prompt, imgPaths, modelId, meta = {}) {
if (pageError) return pageError;
logger.error('适配器', '生成任务失败', { ...meta, error: err.message });
return { error: `生成任务失败: ${err.message}` };
} finally {
// 任务结束,将鼠标移至安全区域
await moveMouseAway(page);
}
} finally { }
}
/**
+1 -4
View File
@@ -10,7 +10,6 @@ import {
} from '../engine/utils.js';
import {
normalizePageError,
moveMouseAway,
waitForInput,
gotoWithCheck,
useContextDownload
@@ -155,9 +154,7 @@ async function generate(context, prompt, imgPaths, modelId, meta = {}) {
logger.error('适配器', '生成任务失败', { ...meta, error: err.message });
return { error: `生成任务失败: ${err.message}` };
} finally {
await moveMouseAway(page);
}
} finally { }
}
/**
+1 -4
View File
@@ -10,7 +10,6 @@ import {
} from '../engine/utils.js';
import {
normalizePageError,
moveMouseAway,
waitForInput,
gotoWithCheck
} from '../utils/index.js';
@@ -160,9 +159,7 @@ async function generate(context, prompt, imgPaths, modelId, meta = {}) {
logger.error('适配器', '生成任务失败', { ...meta, error: err.message });
return { error: `生成任务失败: ${err.message}` };
} finally {
await moveMouseAway(page);
}
} finally { }
}
/**
+1 -5
View File
@@ -11,7 +11,6 @@ import {
import {
normalizePageError,
normalizeHttpError,
moveMouseAway,
waitForInput,
gotoWithCheck,
waitApiResponse,
@@ -195,10 +194,7 @@ async function generate(context, prompt, imgPaths, modelId, meta = {}) {
logger.error('适配器', '生成任务失败', { ...meta, error: err.message });
return { error: `生成任务失败: ${err.message}` };
} finally {
// 任务结束,将鼠标移至安全区域
await moveMouseAway(page);
}
} finally { }
}
/**
-3
View File
@@ -12,7 +12,6 @@ import {
normalizePageError,
normalizeHttpError,
waitApiResponse,
moveMouseAway,
waitForPageAuth,
lockPageAuth,
unlockPageAuth,
@@ -259,8 +258,6 @@ async function generate(context, prompt, imgPaths, modelId, meta = {}) {
} finally {
// 清理拦截器
await page.unroute('**/*').catch(() => { });
// 任务结束,将鼠标移至安全区域
await moveMouseAway(page);
}
}
-3
View File
@@ -12,7 +12,6 @@ import {
normalizePageError,
normalizeHttpError,
waitApiResponse,
moveMouseAway,
waitForPageAuth,
lockPageAuth,
unlockPageAuth,
@@ -286,8 +285,6 @@ async function generate(context, prompt, imgPaths, modelId, meta = {}) {
} finally {
// 清理拦截器
await page.unroute('**/*').catch(() => { });
// 任务结束,将鼠标移至安全区域
await moveMouseAway(page);
}
}
+1 -4
View File
@@ -11,7 +11,6 @@ import {
import {
normalizePageError,
normalizeHttpError,
moveMouseAway,
waitForInput,
gotoWithCheck,
waitApiResponse
@@ -205,9 +204,7 @@ async function generate(context, prompt, imgPaths, modelId, meta = {}) {
logger.error('适配器', '生成任务失败', { ...meta, error: err.message });
return { error: `生成任务失败: ${err.message}` };
} finally {
await moveMouseAway(page);
}
} finally { }
}
/**
+1 -5
View File
@@ -10,7 +10,6 @@ import {
} from '../engine/utils.js';
import {
normalizePageError,
moveMouseAway,
waitForInput,
gotoWithCheck,
waitApiResponse,
@@ -234,10 +233,7 @@ async function generate(context, prompt, imgPaths, modelId, meta = {}) {
logger.error('适配器', '生成任务失败', { ...meta, error: err.message });
return { error: `生成任务失败: ${err.message}` };
} finally {
// 任务结束,将鼠标移至安全区域
await moveMouseAway(page);
}
} finally { }
}
/**
+1 -5
View File
@@ -12,7 +12,6 @@ import {
waitApiResponse,
normalizePageError,
normalizeHttpError,
moveMouseAway,
waitForInput,
gotoWithCheck,
useContextDownload
@@ -163,10 +162,7 @@ async function generate(context, prompt, imgPaths, modelId, meta = {}) {
logger.error('适配器', '生成任务失败', { ...meta, error: err.message });
return { error: `生成任务失败: ${err.message}` };
} finally {
// 任务结束,将鼠标移至安全区域
await moveMouseAway(page);
}
} finally { }
}
/**
+1 -5
View File
@@ -12,7 +12,6 @@ import {
waitApiResponse,
normalizePageError,
normalizeHttpError,
moveMouseAway,
waitForInput,
gotoWithCheck
} from '../utils/index.js';
@@ -158,10 +157,7 @@ async function generate(context, prompt, imgPaths, modelId, meta = {}) {
logger.error('适配器', '生成任务失败', { ...meta, error: err.message });
return { error: `生成任务失败: ${err.message}` };
} finally {
// 任务结束,将鼠标移至安全区域
await moveMouseAway(page);
}
} finally { }
}
/**
+1 -5
View File
@@ -12,7 +12,6 @@ import {
waitApiResponse,
normalizePageError,
normalizeHttpError,
moveMouseAway,
waitForInput,
gotoWithCheck
} from '../utils/index.js';
@@ -126,10 +125,7 @@ async function generate(context, prompt, imgPaths, modelId, meta = {}) {
logger.error('适配器', '生成任务失败', { ...meta, error: err.message });
return { error: `生成任务失败: ${err.message}` };
} finally {
// 任务结束,将鼠标移至安全区域
await moveMouseAway(page);
}
} finally { }
}
/**
+1 -5
View File
@@ -10,7 +10,6 @@ import {
} from '../engine/utils.js';
import {
normalizePageError,
moveMouseAway,
waitForInput,
gotoWithCheck,
useContextDownload
@@ -217,10 +216,7 @@ async function generate(context, prompt, imgPaths, modelId, meta = {}) {
logger.error('适配器', '生成任务失败', { ...meta, error: err.message });
return { error: `生成任务失败: ${err.message}` };
} finally {
// 任务结束,将鼠标移至安全区域
await moveMouseAway(page);
}
} finally { }
}
/**
+12 -17
View File
@@ -11,8 +11,7 @@
import { sleep } from '../engine/utils.js';
import {
gotoWithCheck,
normalizePageError,
moveMouseAway,
normalizePageError
} from '../utils/index.js';
import { clickTurnstile } from '../utils/CloudflareBypass.js';
import { logger } from '../../utils/logger.js';
@@ -138,18 +137,16 @@ async function generate(context, prompt, imgPaths, modelId, meta = {}) {
const { url, type } = modelConfig;
// 根据模型 ID 和类型分发处理
if (modelId === 'cloudflare-turnstile') {
// Turnstile 验证特殊处理
return await handleTurnstile(page, meta);
} else if (modelId === 'ping0') {
// ping0.cc 需要 Cloudflare 验证
return await handlePing0(page, url, meta);
} else if (type === 'text') {
// text 类型返回页面文本
return await handleTextPage(page, url, meta);
} else {
// 其他 image 类型截屏返回
return await handleImagePage(page, url, meta);
switch (modelId) {
case 'cloudflare-turnstile':
return await handleTurnstile(page, meta);
case 'ping0':
return await handlePing0(page, url, meta);
default:
// 根据类型分发
return type === 'text'
? await handleTextPage(page, url, meta)
: await handleImagePage(page, url, meta);
}
} catch (err) {
@@ -158,9 +155,7 @@ async function generate(context, prompt, imgPaths, modelId, meta = {}) {
logger.error('适配器', '任务失败', { ...meta, error: err.message });
return { error: `任务失败: ${err.message}` };
} finally {
await moveMouseAway(page);
}
} finally { }
}
/**
+1 -5
View File
@@ -12,7 +12,6 @@ import {
normalizePageError,
normalizeHttpError,
waitApiResponse,
moveMouseAway,
useContextDownload,
waitForPageAuth,
lockPageAuth,
@@ -377,10 +376,7 @@ async function generate(context, prompt, imgPaths, modelId, meta = {}) {
logger.error('适配器', '生成任务失败', { ...meta, error: err.message });
return { error: `生成任务失败: ${err.message}` };
} finally {
// 任务结束,将鼠标移至安全区域
await moveMouseAway(page);
}
} finally { }
}
/**
+1 -5
View File
@@ -12,7 +12,6 @@ import {
normalizePageError,
normalizeHttpError,
waitApiResponse,
moveMouseAway,
waitForPageAuth,
lockPageAuth,
unlockPageAuth,
@@ -338,10 +337,7 @@ async function generate(context, prompt, imgPaths, modelId, meta = {}) {
logger.error('适配器', '生成任务失败', { ...meta, error: err.message });
return { error: `生成任务失败: ${err.message}` };
} finally {
// 任务结束,将鼠标移至安全区域
await moveMouseAway(page);
}
} finally { }
}
/**
-3
View File
@@ -12,7 +12,6 @@ import {
normalizePageError,
normalizeHttpError,
waitApiResponse,
moveMouseAway,
waitForInput,
gotoWithCheck
} from '../utils/index.js';
@@ -227,8 +226,6 @@ async function generate(context, prompt, imgPaths, modelId, meta = {}) {
} finally {
// 清理拦截器
await page.unroute('**/*').catch(() => { });
// 任务结束,将鼠标移至安全区域
await moveMouseAway(page);
}
}
+2 -2
View File
@@ -637,8 +637,8 @@ export async function uploadFilesViaChooser(page, triggerTarget, filePaths, opti
page.on('response', onResponse);
});
// 设置等待 filechooser 事件(在点击之前)
const fileChooserPromise = page.waitForEvent('filechooser');
// 设置等待 filechooser 事件(在点击之前,带超时保护
const fileChooserPromise = page.waitForEvent('filechooser', { timeout: 30000 });
// 点击触发按钮(支持单击或双击)
const clickCount = clickAction === 'dblclick' ? 2 : 1;
-2
View File
@@ -7,7 +7,6 @@
* - waitForPageAuth/lockPageAuth/unlockPageAuth: 页面认证锁机制
* - waitForInput: 等待输入框出现(自动等待认证完成)
* - gotoWithCheck: 导航到 URL 并检测 HTTP 错误
* - moveMouseAway: 任务完成后移开鼠标
* - waitApiResponse: 等待 API 响应(带页面关闭监听)
*
* - 错误处理 (error.js):
@@ -29,7 +28,6 @@ export {
waitForInput,
gotoWithCheck,
tryGotoWithCheck,
moveMouseAway,
waitApiResponse,
scrollToElement,
} from './page.js';
-18
View File
@@ -146,24 +146,6 @@ export async function tryGotoWithCheck(page, url, options = {}) {
}
}
/**
* 任务完成后移开鼠标(拟人化行为)
* @param {import('playwright-core').Page} page - Playwright 页面对象
*/
export async function moveMouseAway(page) {
if (!page.cursor) return;
try {
const vp = await getRealViewport(page);
await page.cursor.moveTo({
x: clamp(vp.safeWidth * random(0.85, 0.95), 0, vp.safeWidth),
y: clamp(vp.height * random(0.3, 0.7), 0, vp.safeHeight)
});
} catch (e) {
// 忽略鼠标移动失败
}
}
/**
* 等待元素出现并滚动到可视范围
* @param {import('playwright-core').Page} page - Playwright 页面对象