From c5e9ff17da774046ad1293b9a2feaf12ecc60883 Mon Sep 17 00:00:00 2001 From: foxhui Date: Sun, 7 Dec 2025 01:53:53 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=B8=A6=E6=8D=A2?= =?UTF-8?q?=E8=A1=8C=E7=AC=A6=E7=9A=84=E6=8F=90=E7=A4=BA=E8=AF=8D=E8=A7=A6?= =?UTF-8?q?=E5=8F=91=E5=9B=9E=E8=BD=A6=E5=AF=BC=E8=87=B4=E6=8F=90=E5=89=8D?= =?UTF-8?q?=E5=8F=91=E9=80=81=E7=9A=84=E9=97=AE=E9=A2=98=20(closes=20#2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/browser/utils.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/browser/utils.js b/lib/browser/utils.js index 6978f79..9e04b13 100644 --- a/lib/browser/utils.js +++ b/lib/browser/utils.js @@ -169,6 +169,26 @@ export async function humanType(page, target, text) { // 短文本:保持拟人化逐字输入 for (let i = 0; i < text.length; i++) { const char = text[i]; + const nextChar = text[i + 1]; + + // 处理换行符 (避免触发发送) + if (char === '\r' && nextChar === '\n') { + // Windows 换行符 (\r\n) + await page.keyboard.down('Shift'); + await page.keyboard.press('Enter'); + await page.keyboard.up('Shift'); + i++; // 跳过 \n + await sleep(30, 100); + continue; + } else if (char === '\n' || char === '\r') { + // Unix/Mac 换行符 (\n 或 \r) + await page.keyboard.down('Shift'); + await page.keyboard.press('Enter'); + await page.keyboard.up('Shift'); + await sleep(30, 100); + continue; + } + // 模拟错字 (5% 概率) if (Math.random() < 0.05) { await page.keyboard.type('x', { delay: random(50, 150) });