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

Update app.js

Browse files
Files changed (1) hide show
  1. app.js +5 -6
app.js CHANGED
@@ -2145,26 +2145,25 @@ app.get('/ask', async (req, res) => {
2145
 
2146
  app.post("/playwright", async (req, res) => {
2147
  const { code } = req.body;
2148
- if (!code) return res.status(400).send("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.join(" ")) }
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) output.push(String(result));
2163
 
2164
- const parsedOutput = JSON.stringify(output.join("\n"));
2165
- res.send(parsedOutput);
2166
  } catch (error) {
2167
- res.status(500).send(JSON.stringify(error.message));
2168
  }
2169
  });
2170
 
 
2145
 
2146
  app.post("/playwright", async (req, res) => {
2147
  const { code } = req.body;
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
  }
2168
  });
2169