playground: add ability to run code

This commit is contained in:
2024-11-23 10:21:09 -08:00
parent affae1fecf
commit dda0bf6fb9
3 changed files with 128 additions and 9 deletions

View File

@@ -0,0 +1,29 @@
<html>
<head>
<script>
realLog = console.log
messages = []
console.log = (...args) => {
messages.push(args.join(' '))
realLog(...args)
}
window.addEventListener('message', (ev) => {
realLog('got', ev)
let {cmd, src} = ev.data
if (cmd === 'exec') {
try {
eval(src)
} catch (e) {
console.log(e)
}
}
window.parent.postMessage({messages}, '*')
messages = []
})
realLog('IFRAME INITIALIZED')
</script>
</head>
<body>
</body>
</html>