Unix in the Browser Tab

1
Unix in the Browser Tab

Programs written to run on conventional operating systems
typically depend on OS abstractions like processes, pipes,
signals, sockets, and a shared file system. Compiling
programs into JavaScript, asm.js, or
WebAssembly with tools like
Emscripten
or GopherJS
isn’t enough to successfully run many programs client-side,
as browsers present a non-traditional runtime environment
that lacks OS functionality. Porting these applications to
the web currently requires extensive rewriting or paying to
host significant portions of code in the cloud.

Browsix is our answer to these challenges, featuring:


Processes

Unmodified C, C++, Go, and Node.js programs run as
processes on Web Workers, executing in-parallel with
the main browser thread – no need to worry about
long-running computations blocking event-handling or
page rendering.

Kernel + System Calls

By working at the lowest levels of abstraction, Browsix
provides shared resources to multiple language
runtimes, just as traditional operating systems enable
running programs written in a host of languages.

Scalability

By enabling a large class of programs (including legacy
codebases) to run in-browser, Browsix can free you from
the chore of sandboxing and load-balancing programs
server-side.

Terminal

A Unix terminal exposing the dash POSIX shell lets
developers compose functionality and inspect Browsix state
in a familiar way. (view source)

LaTeX Editor

In-browser editor that runs pdflatex and bibtex to
generate PDFs. Required (view source)

Meme Generator

Client/server web application written in JavaScript and Go.
The Go server blits text over images using off-the-shelf
libraries and runs unmodified under Browsix. 30 LoC policy
in client chooses to route requests to cloud or to
in-browser server process. (view source)

Browsix is a framework that bridges the considerable gap
between conventional operating systems and the browser,
enabling unmodified programs expecting a Unix-like
environment to run directly in the browser. Browsix does
this by mapping low-level Unix primitives, like processes and
system calls, onto existing browser APIs, like
Web Workers
and postMessage.

Browsix brings all of these abstractions into unmodified browsers,
and is isolated and secured to the same extent any normal web
page is: at the level of the browser tab.

To use Browsix, client-side JavaScript code creates an
instance of a Browsix kernel (which involves telling it how
to initialize the filesystem), and then asks the kernel to
start or kill processes. Users can also perform HTTP
requests to a given Browsix TCP port, and register callbacks
a number of events, like when a process has written to
standard out or standard error, for when processes exit, and
for when ports are ready.

OS Abstractions

  • Processes are built on top of Web Workers, letting
    applications run in parallel and spawn
    subprocesses. System calls include fork, spawn, exec, and
    wait.

  • Signals with kill(2) and signal handlers.

  • Shared Filesystem accessible from multiple processes.

  • Pipes are supported with pipe(2) enabling developers to compose processes into pipelines.

  • Sockets include support for TCP socket servers and clients, making it possible to run applications like databases and HTTP servers together with their clients in the browser.

Browsix comprises two core parts:

  1. A kernel written in TypeScript that makes core Unix
    features (including pipes, concurrent processes, signals,
    sockets, and a shared file system) available to web
    applications.

  2. Extended JavaScript runtimes for C, C++, Go, and
    Node.js that support running programs written in these
    languages as processes in the browser.

We will soon have more push-button instructions for
integrating Browsix into your project. For now, check out
GitHub for more details.



Join the pack! Join 8000+ others registered users, and get chat, make groups, post updates and make friends around the world!
www.knowasiak.com/register/
Read More

Leave a Reply

2 thoughts on “Unix in the Browser Tab

  1. Aditya avatar

    Wow I'm literally implementing this right now!!

    I was stuck at parents for xmas and I picked Tannenbaum “distributed systems” and “Modern operating systems”, which gave me an idea of running a "kernel" on a browser. It was more of an academic exercise than anything else, but my intention was to have a the following:

    Being able to unload and reload javascript. The initial idea was to write the website inside the website, but at the core level it requires having something akin to process isolation for javascript. It also requires the dom to be isolated.

    Implementing 9p2000, and share resources across browsers. I’ve been reading about the ideas of plan 9 and i would like to implement something that allows me to connect point to point to other browsers and mount their FS into mine so we can share resources.

    One of the cool results that I got was that since the dom is not directly changed (each process/worker has its own partial dom and every time that it changes it a delta is sent back to the main thread for sync) it allows javascript to be running somewhere else (another browser, back end server) and sync’ed back (much like vadaain, but more agnostic).

    Most of the code was inspired by the linux kernel (which gave me a reason to go learn its internals) and is kinda nasty at some points but is written in typescript as some of you have already mentioned. Someone might find it interesting even if just for the educational purpose of it

    https://github.com/intigos/possimpible

  2. Aditya avatar

    Why not "stream" an image of an actual OS (say, linux) to the browser? Has anyone pulled that off yet? (Kind of like rendering services for example, the client is just for user interaction, everything else is streamed from server where all the computation happens)