Spaces:
No application file
No application file
| const { exec } = require('child_process'); | |
| const fs = require('fs'); | |
| const path = require('path'); | |
| const { randomUUID } = require('crypto'); | |
| const executePlaywright = async (userCode) => { | |
| return new Promise((resolve) => { | |
| const scriptName = `playwright_script_${randomUUID()}.mjs`; | |
| const scriptPath = path.join(__dirname, scriptName); | |
| // Simpan kode ke file sementara | |
| fs.writeFileSync(scriptPath, userCode); | |
| // Jalankan kode dengan node | |
| exec(`node ${scriptPath}`, { timeout: 30000 }, (error, stdout, stderr) => { | |
| // Hapus file setelah eksekusi | |
| fs.unlinkSync(scriptPath); | |
| if (error) { | |
| return resolve({ success: false, error: stderr || error.message }); | |
| } | |
| resolve({ success: true, output: stdout }); | |
| }); | |
| }); | |
| }; | |
| module.exports = { executePlaywright }; |