wudysoft commited on
Commit
d9aca22
·
verified ·
1 Parent(s): f57a1a5

Update app.js

Browse files
Files changed (1) hide show
  1. app.js +2 -10
app.js CHANGED
@@ -2148,20 +2148,12 @@ app.post("/playwright", async (req, res) => {
2148
  if (!code) return res.status(400).json({ output: "code is required" });
2149
 
2150
  try {
2151
- let output = [];
2152
  const vm = new NodeVM({
2153
- sandbox: {
2154
- output,
2155
- console: { log: (...args) => output.push(...args.map(arg => typeof arg === "object" ? JSON.stringify(arg, null, 2) : String(arg))) }
2156
- },
2157
  require: { external: ["playwright"], builtin: [] },
2158
  });
2159
 
2160
- const wrappedCode = `(async () => { ${code} })();`;
2161
- const result = await vm.run(wrappedCode, import.meta.url);
2162
- if (result !== undefined) output.push(typeof result === "object" ? JSON.stringify(result, null, 2) : String(result));
2163
-
2164
- res.json({ output: output.length ? output.join("\n") : "No output captured" });
2165
  } catch (error) {
2166
  res.status(500).json({ output: error.message });
2167
  }
 
2148
  if (!code) return res.status(400).json({ output: "code is required" });
2149
 
2150
  try {
 
2151
  const vm = new NodeVM({
 
 
 
 
2152
  require: { external: ["playwright"], builtin: [] },
2153
  });
2154
 
2155
+ const functionInSandbox = vm.run(`module.exports = async (callback) => { ${code} };`, import.meta.url);
2156
+ functionInSandbox((output) => res.json({ output }));
 
 
 
2157
  } catch (error) {
2158
  res.status(500).json({ output: error.message });
2159
  }