Update app.js
Browse files
app.js
CHANGED
|
@@ -8,7 +8,8 @@ import fetch from 'node-fetch';
|
|
| 8 |
import sharp from 'sharp';
|
| 9 |
import { spawn } from 'child_process';
|
| 10 |
import path from 'path';
|
| 11 |
-
import {
|
|
|
|
| 12 |
|
| 13 |
import EventEmitter from 'events';
|
| 14 |
import WebSocket from 'ws';
|
|
@@ -2149,17 +2150,9 @@ app.post("/playwright", async (req, res) => {
|
|
| 2149 |
if (!code) return res.status(400).json({ error: "Kode tidak boleh kosong" });
|
| 2150 |
|
| 2151 |
try {
|
| 2152 |
-
const
|
| 2153 |
-
|
| 2154 |
-
|
| 2155 |
-
},
|
| 2156 |
-
});
|
| 2157 |
-
|
| 2158 |
-
const result = await vm.run(`
|
| 2159 |
-
(async () => {
|
| 2160 |
-
${code}
|
| 2161 |
-
})();
|
| 2162 |
-
`);
|
| 2163 |
|
| 2164 |
res.json({ output: result });
|
| 2165 |
} catch (error) {
|
|
|
|
| 8 |
import sharp from 'sharp';
|
| 9 |
import { spawn } from 'child_process';
|
| 10 |
import path from 'path';
|
| 11 |
+
import { createRequire } from "module";
|
| 12 |
+
const require = createRequire(import.meta.url);
|
| 13 |
|
| 14 |
import EventEmitter from 'events';
|
| 15 |
import WebSocket from 'ws';
|
|
|
|
| 2150 |
if (!code) return res.status(400).json({ error: "Kode tidak boleh kosong" });
|
| 2151 |
|
| 2152 |
try {
|
| 2153 |
+
const executeCode = new Function("require", "importModule", "playwright", `return (async () => { ${code} })();`);
|
| 2154 |
+
|
| 2155 |
+
const result = await executeCode(require, async (mod) => import(mod), { chromium });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2156 |
|
| 2157 |
res.json({ output: result });
|
| 2158 |
} catch (error) {
|