Update app.js
Browse files
app.js
CHANGED
|
@@ -2143,7 +2143,7 @@ app.get('/ask', async (req, res) => {
|
|
| 2143 |
}
|
| 2144 |
});
|
| 2145 |
|
| 2146 |
-
app.post("/playwright", async (req, res) => {
|
| 2147 |
const { code } = req.body;
|
| 2148 |
|
| 2149 |
if (!code) {
|
|
@@ -2153,33 +2153,58 @@ app.post("/playwright", async (req, res) => {
|
|
| 2153 |
try {
|
| 2154 |
let output = "";
|
| 2155 |
|
| 2156 |
-
|
| 2157 |
-
|
| 2158 |
-
|
| 2159 |
-
console: {
|
| 2160 |
-
log: (...args) => {
|
| 2161 |
-
output += args.map(a => String(a)).join(" ") + "\n";
|
| 2162 |
-
}
|
| 2163 |
-
}
|
| 2164 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2165 |
require: {
|
| 2166 |
external: ["playwright"],
|
| 2167 |
builtin: [],
|
| 2168 |
},
|
| 2169 |
});
|
| 2170 |
|
| 2171 |
-
|
| 2172 |
-
|
| 2173 |
-
|
| 2174 |
-
|
| 2175 |
-
|
| 2176 |
-
|
| 2177 |
-
|
| 2178 |
-
|
| 2179 |
-
|
| 2180 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2181 |
|
| 2182 |
-
await vm.run(wrappedScript, import.meta.url);
|
| 2183 |
res.json({ output: output.trim() });
|
| 2184 |
} catch (error) {
|
| 2185 |
res.status(500).json({ output: error.message });
|
|
|
|
| 2143 |
}
|
| 2144 |
});
|
| 2145 |
|
| 2146 |
+
app.post("/playwright/v1", async (req, res) => {
|
| 2147 |
const { code } = req.body;
|
| 2148 |
|
| 2149 |
if (!code) {
|
|
|
|
| 2153 |
try {
|
| 2154 |
let output = "";
|
| 2155 |
|
| 2156 |
+
const sandboxConsole = {
|
| 2157 |
+
log: (...args) => {
|
| 2158 |
+
output += args.map(arg => String(arg)).join(" ") + "\n";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2159 |
},
|
| 2160 |
+
};
|
| 2161 |
+
|
| 2162 |
+
const vm = new NodeVM({
|
| 2163 |
+
sandbox: { console: sandboxConsole },
|
| 2164 |
require: {
|
| 2165 |
external: ["playwright"],
|
| 2166 |
builtin: [],
|
| 2167 |
},
|
| 2168 |
});
|
| 2169 |
|
| 2170 |
+
await vm.run(code, import.meta.url);
|
| 2171 |
+
|
| 2172 |
+
res.json({ output: output.trim() });
|
| 2173 |
+
} catch (error) {
|
| 2174 |
+
res.status(500).json({ output: error.message });
|
| 2175 |
+
}
|
| 2176 |
+
});
|
| 2177 |
+
|
| 2178 |
+
app.post("/playwright/v2", async (req, res) => {
|
| 2179 |
+
const { code } = req.body;
|
| 2180 |
+
|
| 2181 |
+
if (!code) {
|
| 2182 |
+
return res.status(400).json({ output: "code is required" });
|
| 2183 |
+
}
|
| 2184 |
+
|
| 2185 |
+
try {
|
| 2186 |
+
let output = "";
|
| 2187 |
+
|
| 2188 |
+
const originalConsoleLog = console.log;
|
| 2189 |
+
console.log = (...args) => {
|
| 2190 |
+
output += args.map(arg => String(arg)).join(" ") + "\n";
|
| 2191 |
+
originalConsoleLog(...args);
|
| 2192 |
+
};
|
| 2193 |
+
|
| 2194 |
+
await (async () => {
|
| 2195 |
+
try {
|
| 2196 |
+
eval(`
|
| 2197 |
+
(async () => {
|
| 2198 |
+
${code}
|
| 2199 |
+
})();
|
| 2200 |
+
`);
|
| 2201 |
+
} catch (err) {
|
| 2202 |
+
console.log("Error:", err.message);
|
| 2203 |
+
}
|
| 2204 |
+
})();
|
| 2205 |
+
|
| 2206 |
+
console.log = originalConsoleLog;
|
| 2207 |
|
|
|
|
| 2208 |
res.json({ output: output.trim() });
|
| 2209 |
} catch (error) {
|
| 2210 |
res.status(500).json({ output: error.message });
|