This commit is contained in:
Timothy J. Baek 2024-10-07 22:53:36 -07:00
parent 9bd5567552
commit 457360dae7

View File

@ -200,9 +200,16 @@
eventConfirmationTitle = data.title; eventConfirmationTitle = data.title;
eventConfirmationMessage = data.message; eventConfirmationMessage = data.message;
} else if (type === 'execute') { } else if (type === 'execute') {
eventCallback = cb;
try { try {
// Use Function constructor to evaluate code in a safer way // Use Function constructor to evaluate code in a safer way
new Function(data.code)(); const asyncFunction = new Function(`return (async () => { ${data.code} })()`);
const result = await asyncFunction(); // Await the result of the async function
if (cb) {
cb(result);
}
} catch (error) { } catch (error) {
console.error('Error executing code:', error); console.error('Error executing code:', error);
} }