wudysoft commited on
Commit
6b960f6
·
verified ·
1 Parent(s): 8e02ac7

Update app.js

Browse files
Files changed (1) hide show
  1. app.js +5 -12
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 { VM } from "vm2";
 
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 vm = new VM({
2153
- sandbox: {
2154
- playwright: { chromium },
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) {