feat: 浏览器自动化操作开发

This commit is contained in:
DEV_DSW
2026-03-03 17:05:13 +08:00
parent d99f1dd98e
commit 20e825215f
18 changed files with 495 additions and 68 deletions

View File

@@ -0,0 +1,38 @@
import { EventEmitter } from 'events';
import { spawn } from 'child_process';
import log from 'electron-log';
export class executeScriptService extends EventEmitter {
// 执行脚本
async executeScript(scriptPath: string, options: object): Promise<{ success: boolean; message?: string; error?: string }> {
try {
const child = spawn('node', [scriptPath], {
env: {
...process.env,
...options,
}
});
child.stdout.on('data', (data: Buffer) => {
log.info(`stdout: ${data.toString()}`);
});
child.stderr.on('data', (data: Buffer) => {
log.info(`stderr: ${data.toString()}`);
});
child.on('close', (code: number) => {
log.info(`子进程退出,退出码 ${code}`);
});
return { success: true, message: 'Node 脚本执行中' };
} catch (error) {
return { success: false, message: '运行 Node 脚本时出错' };
}
}
}