An online WebAssembly Terminal to run WASI modules directly on your browser
Just last week we released Wasmer-JS, a collection of open-source installable packages for running WASI modules in Node and the browser.
📣 Today, with the back-to-back announcement, we are excited to announce WebAssembly.sh.
WebAssembly.sh is an open-source and installable Progressive Web App (PWA) terminal fully powered by WebAssembly and Wasmer-JS, that uses the WebAssembly Package Manager and local files to run server-side Wasm WASI modules in a shell-like interface 🖥
We are stoked to share WebAssembly.sh, because we feel like it has a lot to offer for a variety of use cases:
- WebAssembly.sh is a sandboxed way to quickly test or try a program that compiles to WASI without installing the binary on your local machine. 🏖️
- Developers writing WASI modules can use WebAssembly.sh to debug and test them in the browser! 🛠️
- People who want to have some fun can run Python with rustpython, get some colorful output with lolcat, or make a cow talk with cowsay 😂
- And much more! 🤩
The goals of WASI go far beyond CLI-styled applications. However, the current API supports them and we are excited to introduce these use cases today for the community!
Let’s take a step back, and see how we can use WebAssembly.sh. 🤔
Let’s take a quick walkthrough of WebAssembly.sh.
On first load (~200KB) you will be greeted with a welcome message. But behind the scenes, all of the PWA magic happens. The service worker will be installed, and now WebAssembly.sh will work offline. 🤯
You will also notice WebAssembly.sh can be installed natively either through the “Add to HomeScreen” on mobile, or the install icon in the URL bar on Desktop browsers. All of this functionality can be confirmed and investigated through your browser’s developers tool. In particular we used Chrome’s Lighthouse Audit to help us build for / enable the PWA features in WebAssembly.sh. 💡
Let’s get started running some commands!
When WebAssembly.sh tries to run a command, first it will check if the WASI-compiled module is already installed and cached.
If not, WebAssembly.sh will default to searching on WAPM to then download and run that module. ⚡
quickjs, and then you should be able to start using the engine!
Next, let’s upload and run our own custom WASI modules. For this, we can use the package manager for WebAssembly.sh,
️WAPM on WebAssembly.sh, is a command to manage Wasm Modules. It is intended to behave similar to the native WAPM Package Manager. Using the command
wapm upload , a file upload dialog will show up, allowing you to upload your own
.wasm file to be installed as a command. For example, if we install
wapm upload , then you can run the command
mywasi to run the Wasm / WASI module.
Wapm also supports other functions such as:
wapm install to manually install a package and/or a package version from Wapm,
wapm list to list all available commands, and
wapm uninstall to delete a command installed by Wapm. Another nice feature is that the commands installed by Wapm are saved to IndexedDB using idb-keyval so that installed modules work between sessions, and even work offline! 📦
We can also get Wasm modules to work with one another! Similar to a Unix environment, WebAssembly.sh supports piping. It uses Comlink in the background, to spin up multiple workers and passed standard input and standard output between them. Using the example we mentioned earlier in the article, we can run
cowsay WebAssembly | lolcat , and we get a colorful cowsay shown in our terminal! 🐄🌈
With that short introduction, you should be able to hit the ground running with WebAssembly.sh! 🏃
We are super excited to see how people use WebAssembly.sh, and we hope you enjoy using it as much as we did making it. 😄