forked from EliasPereirah/OrionChat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsandbox.html
38 lines (37 loc) · 1.18 KB
/
sandbox.html
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
30
31
32
33
34
35
36
37
38
<!DOCTYPE html>
<html lang="en">
<head>
<title>Sandbox</title>
</head>
<body>
<script>
const originalConsoleLog = console.log;
console.log = function(...args) {
window.parent.postMessage({ type: 'log', args: Array.from(args) }, window.location.origin);
originalConsoleLog.apply(console, args); // Keeps log in iframe console
};
async function asyncEval(code) {
return new Promise((resolve, reject) => {
try {
const result = eval(code);
resolve(result);
} catch (error) {
reject(error);
}
});
}
window.onmessage = async (event) => {
if (event.origin === window.location.origin) {
try {
const result = await asyncEval(event.data.code);
window.parent.postMessage(result, window.location.origin);
} catch (error) {
window.parent.postMessage({ error: error.message }, window.location.origin);
}
} else {
console.error('Message received from untrusted source:', event.origin);
}
};
</script>
</body>
</html>