Yes, you can run this in the browser thanks to WebAssembly.
This should not be used by heavy modules, because QuickJS is slower than V8, and you completely avoid all browser optimizations.
A good example of usage, would be specific algorithms that you want to protect from public eye. Since you have direct access to the host and DOM, you can use available data and modify it inside a "protected" sandbox.
npm install byteweb
yarn add byteweb
The usage is pretty straight forward.
bytecode returns an
Uint8Array which you can convert into base64 and distribute protected and evaluate later on.
You can invoke code or get data from the host using
Known issues and limitations
- You don't have direct access to the host, you have to use
host.run(code)inside the sandbox.
- Strings are visible, you can use gnirt or terser for better protection.
Bytenode - Inspiration