-
Notifications
You must be signed in to change notification settings - Fork 1
/
exec.js
29 lines (27 loc) · 982 Bytes
/
exec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const MessageFrom = {
Content: 0,
Web: 1
};
window.addEventListener('message', function (ev) {
if (ev.data.from === MessageFrom.Content) {
const task = ev.data.payload?.task;
if (task) {
try {
const result = eval(task.expression);
const messageData = {
from: MessageFrom.Web,
payload: { task: { id: task.id, result: result, success: true } },
};
window.postMessage(messageData, '*');
} catch (error) {
const messageData = {
from: MessageFrom.Web,
payload: { task: { id: task.id, error: error.message, success: false } },
};
window.postMessage(messageData, '*');
console.error('Execution error:', error);
}
}
}
});
window.postMessage({ from: MessageFrom.Web, payload: { status: 'ready' } }, '*');