Using scratch4js in the browser
scratch4js runs unchanged in the browser — it has no Node-only dependencies. The only difference is where the bytes come from and go to.
Loading from a file input
Project.load accepts an ArrayBuffer or
Uint8Array, which is exactly what a <input type="file"> gives you:
Saving to a download
save() returns a Uint8Array. Wrap it in a Blob
and trigger a download:
Loading over the network
Using the UMD build via a <script> tag
For a no-bundler setup, load the self-contained UMD bundle (jszip is inlined) and
use the global scratch4js:
A note on bytes
Anywhere the API mentions "bytes" — Project.load, addCostume, addSound,
costume/sound .data — a Uint8Array or ArrayBuffer works in the browser just
as a Buffer does in Node. Inputs are normalised to Uint8Array internally, and
outputs are always Uint8Array.