I'm building a website similar to CodePen, focused exclusively on JavaScript, but I'm planning to create my own APIs. The key thing is that I want the code execution environment to be free from any browser-dependent features like the DOM or fetch. It's somewhat like Scratch but for JavaScript. I'm struggling with the implementation of running JavaScript in this setup. Any suggestions on how to achieve this?
4 Answers
Consider using the `sandbox` attribute on the iframe. It could be exactly what you need to limit access and run JavaScript safely!
You might want to look into a WebAssembly-JS engine like QuickJS. Some web tools use similar methods to implement plugins securely and could fit your needs perfectly.
Have you thought about using a web worker? You can specify exactly what features you want to expose to it. Alternatively, wrapping your JavaScript execution in an iframe could work too!
Maybe you should try searching 'javascript interpreter in javascript' before posting. There's actually quite a few projects out there that might be what you're looking for.
Hey, no need to be rude! The guy's just asking for help here. That's what forums are for, right?