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) });