feat: 删除冗余代码,并修复可能出现的BUG

This commit is contained in:
foxhui
2025-12-09 19:46:13 +08:00
Unverified
parent e13c7092af
commit 801eb74b24
11 changed files with 1005 additions and 944 deletions
+8 -17
View File
@@ -250,19 +250,10 @@ export async function humanType(page, target, text) {
await page.keyboard.press('Backspace');
await sleep(100, 300);
// 4. 瞬间粘贴全部文本
if (typeof target === 'string') {
await page.evaluate(({ sel, content }) => {
const input = document.querySelector(sel);
input.focus();
document.execCommand('insertText', false, content);
}, { sel: target, content: text });
} else {
await page.evaluate(({ el, content }) => {
el.focus();
document.execCommand('insertText', false, content);
}, { el: target, content: text });
}
// 4. 瞬间粘贴全部文本 (始终使用已获取的 ElementHandle,支持 Shadow DOM)
await page.evaluate((content) => {
document.execCommand('insertText', false, content);
}, text);
}
}
@@ -326,7 +317,7 @@ export async function pasteImages(page, target, filePaths, options = {}) {
await sleep(500, 1000);
try {
logger.info('浏览器', '正在深度扫描文件上传控件...');
logger.debug('浏览器', '正在深度扫描文件上传控件...');
const fileInputs = await findAllFileInputs(page);
if (fileInputs.length === 0) {
@@ -348,7 +339,7 @@ export async function pasteImages(page, target, filePaths, options = {}) {
// 使用 Playwright 原生上传 (绕过所有事件拦截)
await handle.setInputFiles(filePaths);
uploaded = true;
logger.info('浏览器', '已通过原生控件注入文件');
logger.debug('浏览器', '已通过原生控件提交图片');
break; // 只要有一个成功就停止
} catch (e) {
// 忽略不可操作的 input (比如被禁用的)
@@ -391,12 +382,12 @@ export async function pasteImages(page, target, filePaths, options = {}) {
page.on('response', onResponse);
});
logger.info('浏览器', `文件已注入,正在等待上传确认...`);
logger.info('浏览器', `已提交图片, 正在等待上传确认...`);
await uploadPromise;
logger.info('浏览器', `所有图片上传完成`);
} else {
// 默认行为: 等待上传预览出现
logger.info('浏览器', `文件已注入,等待预览生成...`);
logger.info('浏览器', `已提交图片, 等待预览生成...`);
await sleep(2000, 4000);
}