From 26988d3de828f35da6d2d6112107b840824ce166 Mon Sep 17 00:00:00 2001 From: dengqichen Date: Wed, 19 Nov 2025 15:53:06 +0800 Subject: [PATCH] dasdasd --- src/shared/logger.js | 10 +++++++-- .../actions/click-action.js | 22 +++++++++---------- .../actions/fill-form-action.js | 20 +++++++++++------ .../automation-framework/core/base-action.js | 18 +++++++-------- 4 files changed, 41 insertions(+), 29 deletions(-) diff --git a/src/shared/logger.js b/src/shared/logger.js index 0982dd3..9374803 100644 --- a/src/shared/logger.js +++ b/src/shared/logger.js @@ -1,5 +1,9 @@ /** * Logger - 统一日志工具 + * + * 修复 Windows 乱码问题: + * - 统一使用 console.log (输出到 stdout) + * - 避免 console.error/warn (输出到 stderr,Windows 下编码不同) */ const logger = { @@ -19,16 +23,18 @@ const logger = { /** * 错误日志 + * 注意:统一使用 console.log 而非 console.error,避免 Windows stderr 编码问题 */ error(tool, message) { - console.error(`[${tool}] ✗ ERROR: ${message}`); + console.log(`[${tool}] ✗ ERROR: ${message}`); }, /** * 警告日志 + * 注意:统一使用 console.log 而非 console.warn,避免 Windows stderr 编码问题 */ warn(tool, message) { - console.warn(`[${tool}] ⚠ WARNING: ${message}`); + console.log(`[${tool}] ⚠ WARNING: ${message}`); }, /** diff --git a/src/tools/automation-framework/actions/click-action.js b/src/tools/automation-framework/actions/click-action.js index 9099dd9..037ab60 100644 --- a/src/tools/automation-framework/actions/click-action.js +++ b/src/tools/automation-framework/actions/click-action.js @@ -200,30 +200,30 @@ class ClickAction extends BaseAction { const targetX = box.x + box.width / 2; const targetY = box.y + box.height / 2; - // 第一段移动:先移动到附近(模拟人眼定位) + // 第一段移动:先移动到附近(模拟人眼定位)- 更慢 const nearX = targetX + this.randomInt(-50, 50); const nearY = targetY + this.randomInt(-50, 50); - const steps1 = this.randomInt(10, 20); + const steps1 = this.randomInt(15, 30); // 增加步数,移动更慢 this.log('debug', `移动鼠标到附近: (${nearX.toFixed(0)}, ${nearY.toFixed(0)})`); - await this.page.mouse.move(nearX, nearY, { steps: Math.floor(steps1 / 2) }); - await this.randomDelay(50, 150); + await this.page.mouse.move(nearX, nearY, { steps: steps1 }); + await this.randomDelay(150, 400); // 增加延迟 - // 第二段移动:移动到目标位置 + // 第二段移动:移动到目标位置 - 更慢 this.log('debug', `移动鼠标到目标: (${targetX.toFixed(0)}, ${targetY.toFixed(0)})`); - await this.page.mouse.move(targetX, targetY, { steps: Math.floor(steps1 / 2) }); + await this.page.mouse.move(targetX, targetY, { steps: this.randomInt(10, 20) }); - // 短暂停顿(模拟人类反应) - await this.randomDelay(50, 200); + // 短暂停顿(模拟人类反应和确认)- 增加延迟 + await this.randomDelay(200, 500); // 点击(使用 down + up,而不是 click) this.log('debug', '执行点击 (mouse down + up)...'); await this.page.mouse.down(); - await this.randomDelay(50, 120); + await this.randomDelay(80, 180); // 增加按压时间 await this.page.mouse.up(); - // 点击后延迟(参考旧框架) - await this.randomDelay(1000, 2000); + // 点击后延迟(等待页面响应)- 增加延迟 + await this.randomDelay(1200, 2500); this.log('info', '✓ 人类行为点击完成'); diff --git a/src/tools/automation-framework/actions/fill-form-action.js b/src/tools/automation-framework/actions/fill-form-action.js index 17c518a..6d63ff9 100644 --- a/src/tools/automation-framework/actions/fill-form-action.js +++ b/src/tools/automation-framework/actions/fill-form-action.js @@ -133,19 +133,25 @@ class FillFormAction extends BaseAction { } /** - * 模拟人类输入 + * 模拟人类输入(更慢、更真实) */ async typeHumanLike(element, text) { - for (const char of text) { + for (let i = 0; i < text.length; i++) { + const char = text[i]; + + // 每个字符延迟 100-250ms(更慢) await element.type(char, { - delay: Math.random() * 100 + 50 // 50-150ms 随机延迟 + delay: Math.random() * 150 + 100 }); + + // 每输入3-5个字符,随机停顿一下(模拟思考或调整手指) + if (i > 0 && i % (Math.floor(Math.random() * 3) + 3) === 0) { + await new Promise(resolve => setTimeout(resolve, Math.random() * 800 + 300)); + } } - // 随机暂停 - if (Math.random() > 0.7) { - await new Promise(resolve => setTimeout(resolve, Math.random() * 500 + 200)); - } + // 输入完成后,短暂停顿(模拟检查输入) + await new Promise(resolve => setTimeout(resolve, Math.random() * 500 + 300)); } /** diff --git a/src/tools/automation-framework/core/base-action.js b/src/tools/automation-framework/core/base-action.js index aa8e57b..73772e0 100644 --- a/src/tools/automation-framework/core/base-action.js +++ b/src/tools/automation-framework/core/base-action.js @@ -119,7 +119,7 @@ class BaseAction { } /** - * 人类行为延迟工具方法 + * 人类行为延迟工具方法(模拟真实用户操作节奏) */ // 随机延迟 @@ -128,24 +128,24 @@ class BaseAction { await new Promise(resolve => setTimeout(resolve, delay)); } - // 阅读页面延迟(1-3秒) + // 阅读页面延迟(2-5秒)- 模拟用户查看页面内容 async readPageDelay() { - await this.randomDelay(1000, 3000); + await this.randomDelay(2000, 5000); } - // 思考延迟(500-1500ms) + // 思考延迟(1-2.5秒)- 模拟填写表单后的思考 async thinkDelay() { - await this.randomDelay(500, 1500); + await this.randomDelay(1000, 2500); } - // 短暂停顿(200-500ms) + // 短暂停顿(300-800ms)- 模拟操作间的自然停顿 async pauseDelay() { - await this.randomDelay(200, 500); + await this.randomDelay(300, 800); } - // 步骤间延迟(1-2秒) + // 步骤间延迟(1.5-3秒)- 模拟步骤之间的过渡 async stepDelay() { - await this.randomDelay(1000, 2000); + await this.randomDelay(1500, 3000); } }