Skip to content

WasiWorker for the web #297

@olanod

Description

@olanod

Perhaps this belongs more in the web standards repositories, perhaps in both.
At first it might seem that WASI is all about running WebAssembly outside of the web and staying as far from the browser as possible but I see a lot of potential in browsers being the go to WASI runtime, the discoverability of the web is a great way to distribute and install WASI based applications and both worlds can benefit a lot from each other.

A WasiWorker could have would have a similar API as the other types of workers

let worker = new WasiWorker('app.wasi', { type: 'background', ... otherOpts });
worker.addEventListener('message', e =>  {});
worker.postMessage('foobar');
// or 
navigator.wasiWorker.register('app.wasi', {...opts});

The options object could have several interesting possibilities like specity the kind of worker, maybe is a background type that is installed in a similar way to service workers and can live as a system service? maybe a onetime/simple worker that executes a task and returns? in that case maybe the register function only compiles it and then several instances can be fired later with different context data.
Other options would include the capabilities to request access to the file system, network sockets, etc. another interesting option can be something like a virtual file system.

new WasiWorker({
    vfs: {
        '/dev/camera_feed': new ReadableStream({}),
        '/smiling_face.jpg': new WritableStream({}),
        stdout: consoleWriterStream,
    }
    ...opts,
})

The virtual filesystem I think is already a good way to communicate with the WASI process but it can also communicate in a web worker like fashion if an interface types API for the onmessage/postMessage or broadcast API is formalized. Such interface can also include other callbacks to control the life cycle of the app like service workers do.

Would love to hear opinions :) I personally think it would be the ultimate marriage, UIs still developed with web technologies at the reach of a https://my.app and leaving the business logic and heavy lifting to a headless WASI service or set of services that can access the file system, hardware and network in a more traditional but secure way. For the decentralized web use case for example, no need to do hacks trying to get webrtc in a service worker, a performant p2p node that would run fine in any other WASI runtime could be spawned on the web and work as expected because it was explicitly granted the right set of permissions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions