2022-01-31 20:52:13 +00:00
<!DOCTYPE html>
< html lang = "en" style = "height:100%;" >
< head >
< meta charset = "utf-8" >
2022-10-06 10:26:31 +00:00
< title > WebVM - Linux virtualization in WebAssembly< / title >
2022-01-31 20:52:13 +00:00
2022-10-06 10:57:28 +00:00
< meta name = "description" content = "Server-less virtual machine, networking included, running browser-side in HTML5/WebAssembly. Code in any programming language inside this Linux terminal." >
2022-10-04 11:17:36 +00:00
< meta name = "keywords" content = "WebVM, Virtual Machine, CheerpX, x86 virtualization, WebAssembly, Tailscale, JIT" >
2022-10-06 10:26:31 +00:00
< meta property = "og:title" content = "WebVM - Linux virtualization in WebAssembly" / >
2022-01-31 20:52:13 +00:00
< meta property = "og:type" content = "website" / >
< meta property = "og:site_name" content = "WebVM" / >
< meta property = "og:url" content = "/" >
2022-10-06 10:57:28 +00:00
< meta property = "og:image" content = "https://webvm.io/assets/welcome_to_WebVM_.png" / >
2022-10-06 10:26:31 +00:00
< meta name = "twitter:card" content = "summary_large_image" / >
2022-01-31 20:52:13 +00:00
< meta name = "twitter:site" content = "@leaningtech" / >
2022-10-06 10:26:31 +00:00
< meta name = "twitter:title" content = "WebVM - Linux virtualization in WebAssembly" / >
2022-10-06 10:57:28 +00:00
< meta name = "twitter:description" content = "Server-less virtual machine, networking included, running browser-side in HTML5/WebAssembly. Code in any programming language inside this Linux terminal." >
< meta name = "twitter:image" content = "https://webvm.io/assets/welcome_to_WebVM_.png" / >
2022-02-01 22:22:23 +00:00
<!-- Apple iOS web clip compatibility tags -->
< meta name = "application-name" content = "WebVM" / >
< meta name = "apple-mobile-web-app-title" content = "WebVM" / >
< meta name = "apple-mobile-web-app-capable" content = "yes" / >
< meta name = "mobile-web-app-capable" content = "yes" / >
< meta name = "apple-mobile-web-app-status-bar-style" content = "black" / >
2022-01-31 20:52:13 +00:00
2022-10-05 10:45:33 +00:00
< link rel = "shortcut icon" href = "./tower.ico" >
2022-10-04 12:27:16 +00:00
< link rel = "preconnect" href = "https://fonts.googleapis.com" >
< link rel = "preconnect" href = "https://fonts.gstatic.com" crossorigin >
2022-09-29 20:38:16 +00:00
< link rel = "stylesheet" id = "us-fonts-css" href = "https://fonts.googleapis.com/css?family=Montserrat%3A300%2C400%2C500%2C600%2C700&display=swap&ver=6.0.2" media = "all" >
2022-08-01 15:44:15 +00:00
< link rel = "stylesheet" href = "./xterm/xterm.css" / >
2022-10-03 10:07:50 +00:00
< link rel = "stylesheet" href = "./scrollbar.css" / >
2022-09-23 08:42:11 +00:00
< script >
2022-11-02 13:45:36 +00:00
window.networkInterface = { bind: null, connect: null, listen: null, ready: false };
2022-09-23 08:42:11 +00:00
< / script >
2022-10-05 10:19:55 +00:00
< script src = "./xterm/xterm.js" > < / script >
< script src = "./xterm/xterm-addon-fit.js" > < / script >
< script defer type = "module" >
2022-09-29 15:35:55 +00:00
import { State } from "/tun/tailscale_tun.js";
import { autoConf } from "/tun/tailscale_tun_auto.js";
2022-09-07 15:46:56 +00:00
2022-09-30 10:20:27 +00:00
let resolveLogin = null;
let loginPromise = new Promise((f,r) => {
resolveLogin = f;
});
2022-10-05 09:02:53 +00:00
const loginElem = document.getElementById("loginLink");
const statusElem = document.getElementById("networkStatus");
2022-09-29 15:35:55 +00:00
const loginUrlCb = (url) => {
2022-10-05 09:02:53 +00:00
loginElem.href = url;
loginElem.target = "_blank";
statusElem.innerHTML = "Tailscale Login";
2022-09-30 10:20:27 +00:00
resolveLogin(url);
2022-09-07 15:46:56 +00:00
};
2022-09-29 15:35:55 +00:00
const stateUpdateCb = (state) => {
switch(state)
{
case State.NeedsLogin:
{
break;
}
case State.Running:
{
2022-10-05 09:02:53 +00:00
loginElem.href = "https://login.tailscale.com/admin/machines";
2022-09-29 15:35:55 +00:00
break;
}
case State.Starting:
{
break;
}
case State.Stopped:
{
break;
}
case State.NoState:
{
break;
}
}
2022-09-07 15:46:56 +00:00
};
2022-09-29 15:35:55 +00:00
const netmapUpdateCb = (map) => {
const ip = map.self.addresses[0];
2022-10-05 09:02:53 +00:00
statusElem.innerHTML = "IP: "+ip;
2022-09-07 15:46:56 +00:00
};
2022-09-30 10:20:27 +00:00
const { listen, connect, bind, up } = await autoConf({
2022-09-29 15:35:55 +00:00
loginUrlCb,
stateUpdateCb,
netmapUpdateCb,
});
2022-09-23 08:42:11 +00:00
window.networkInterface.bind = bind;
window.networkInterface.connect = connect;
window.networkInterface.listen = listen;
2022-11-02 13:45:36 +00:00
window.networkInterface.ready = true;
2022-10-05 09:02:53 +00:00
loginElem.style.cursor = "pointer";
statusElem.style.color = "white";
2022-10-05 10:25:47 +00:00
loginElem.onclick = () => {
2022-10-05 09:02:53 +00:00
loginElem.onclick = null;
statusElem.innerHTML = "Downloading network code...";
2022-09-30 10:20:27 +00:00
const w = window.open("login.html", "_blank");
2022-10-05 11:52:14 +00:00
async function waitLogin() {
await up();
2022-10-05 12:01:54 +00:00
statusElem.innerHTML = "Starting login...";
2022-10-05 11:52:14 +00:00
const url = await loginPromise;
2022-10-05 12:42:14 +00:00
w.location.href = url;
2022-10-05 11:52:14 +00:00
}
waitLogin();
2022-09-30 10:20:27 +00:00
};
2022-08-01 15:44:15 +00:00
< / script >
2022-01-31 20:52:13 +00:00
< / head >
2022-09-07 15:46:56 +00:00
< body style = "margin:0;height:100%;background:black;color:white;overflow:hidden; display:flex; flex-direction: column; justify-content: space-between; height: 100%;" >
< header style = "flex-grow:0; flex-srink: 0;height:80px; width: 100%; margin: 2px 0 2px 0;" >
< div style = "display: flex; flex-direction: row; justify-content: space-between; width: 100%;" >
< div style = "display: flex; flex-direction: row;" >
2022-10-04 12:17:21 +00:00
< a href = "https://leaningtech.com/" target = "_blank" >
< img src = "./assets/leaningtech.png" style = "margin-left: 10px; height: 60px; margin-top: 10px;" >
< / a >
2022-09-07 15:46:56 +00:00
< / div >
< div style = "display: flex; flex-direction: row; justify-content: space-before;" >
< li style = " margin-right: 50px; height: 100%; display: flex; align-items: center;" >
2022-10-04 13:31:47 +00:00
< a href = "https://discord.leaningtech.com" target = "_blank" style = "text-decoration: none" >
2022-10-04 12:17:21 +00:00
< div style = "color: white; font-family: montserrat; font-weight: 700; font-size: large;" > Discord< / div >
2022-09-19 07:06:12 +00:00
< / a >
< / li >
< li style = " margin-right: 50px; height: 100%; display: flex; align-items: center;" >
2022-10-04 13:31:47 +00:00
< a href = "https://github.com/leaningtech/webvm" target = "_blank" style = "text-decoration: none" >
2022-10-04 12:17:21 +00:00
< div style = "color: white; font-family: montserrat; font-weight: 700; font-size: large;" > Github< / div >
2022-09-07 15:46:56 +00:00
< / a >
< / li >
< li style = " margin-right: 50px; height: 100%; display: flex; align-items: center;" >
2022-10-05 09:02:53 +00:00
< a id = "loginLink" style = "text-decoration: none; cursor:not-allowed;" >
< div id = "networkStatus" style = "color: grey; font-family: montserrat; font-weight: 700; font-size: large;" > Tailscale Login< / div >
2022-09-07 15:46:56 +00:00
< / a >
< / li >
< / div >
< / div >
< / header >
< div style = "flex-grow:0; flex-shrink: 0; height:1px; width: 100%; background-color: white;" >
< / div >
< main style = "display: flex; flex-direction: row; justify-content: space-between; margin:0; height:100%;" >
2022-10-03 10:07:50 +00:00
< div style = "flex-grow:1; height:100%;display:inline-block;margin:0;" class = "scrollbar" id = "console" >
2022-01-31 20:52:13 +00:00
< / div >
< / main >
< script >
//Utility namespace to group all functionality related to printing (both error and non error) messages
const color= "\x1b[1;35m";
const bold= "\x1b[1;37m";
const underline= "\x1b[94;4m";
const normal= "\x1b[0m";
var printOnTerm = {
2022-10-03 12:33:49 +00:00
getAsciiTitle: function ()
{
var title = [
color + " __ __ _ __ ____ __ " + normal,
color + " \\ \\ / /__| |_\\ \\ / / \\/ | " + normal,
color + " \\ \\/\\/ / -_) '_ \\ V /| |\\/| | " + normal,
color + " \\_/\\_/\\___|_.__/\\_/ |_| |_| " + normal,
];
return title;
},
2022-01-31 20:52:13 +00:00
getAsciiText: function ()
{
var text = [
2022-10-05 14:11:51 +00:00
"+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+",
"| |",
"| WebVM is a server-less virtual Linux environment running fully client-side |",
"| in HTML5/WebAssembly. |",
"| |",
"| WebVM is powered by the CheerpX virtualization engine, which enables safe, |",
"| sandboxed client-side execution of x86 binaries on any browser. |",
"| |",
"| CheerpX includes an x86-to-WebAssembly JIT compiler, a virtual block-based |",
2022-10-06 09:46:48 +00:00
"| file system, and a Linux syscall emulator. |",
2022-10-05 14:11:51 +00:00
"| |",
2022-10-06 09:46:48 +00:00
"| [NEW!] WebVM now supports full TCP and UDP networking via Tailscale! |",
"| Click on 'Tailscale Login' to enable it. Read the announcement: |",
2022-10-05 14:11:51 +00:00
"| |",
"| " + underline + "https://leaningtech.com/webvm-virtual-machine-with-networking-via-tailscale" + normal +" |",
"| |",
"+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+",
2022-01-31 20:52:13 +00:00
"",
2022-07-21 09:34:52 +00:00
" Welcome to WebVM (build CX_VERSION). If unsure, try these examples:",
2022-02-01 11:39:46 +00:00
"",
2022-10-03 12:33:49 +00:00
" python3 examples/python3/fibonacci.py ",
" gcc -o helloworld examples/c/helloworld.c & & ./helloworld",
" objdump -d ./helloworld | less -M",
" vim examples/c/helloworld.c",
2022-10-04 12:26:14 +00:00
" curl --max-time 15 parrot.live # requires networking",
2022-01-31 20:52:13 +00:00
"",
];
return text;
},
getSharedArrayBufferMissingMessage: function ()
{
const text = [
"",
"",
color + "CheerpX could not start" + normal,
"",
"CheerpX depends on JavaScript's SharedArrayBuffer, that your browser",
" does not support.",
"",
"SharedArrayBuffer is currently enabled by default on recent",
2022-02-01 11:39:46 +00:00
" versions of Chrome, Edge, Firefox and Safari.",
2022-01-31 20:52:13 +00:00
"",
"",
2022-02-01 11:39:46 +00:00
"Give it a try from another browser!",
2022-01-31 20:52:13 +00:00
]
return text;
},
getErrorMessage: function (error_message)
{
const text = [
"",
"",
color + "CheerpX could not start" + normal,
"",
"CheerpX internal error message is:",
error_message,
"",
"",
2022-02-01 12:32:10 +00:00
"CheerpX is expected to work with recent desktop versions of Chrome, Edge, Firefox and Safari",
2022-01-31 20:52:13 +00:00
"",
"",
"Give it a try from a desktop version / another browser!",
]
return text;
},
printMessage: function (text) {
for (var i=0; i< text.length ; i + + )
{
term.write(text[i]);
term.write('\n');
}
},
printError: function (message)
{
this.printMessage(message);
term.write("\n\n");
function writeCustom(something)
{
term.write(something);
}
},
};
var consoleDiv = document.getElementById("console");
//xterm.js related logic
2022-10-04 12:27:16 +00:00
var term = new Terminal({cursorBlink:true,convertEol:true, fontFamily:"monospace", fontWeight: 400, fontWeightBold: 700});
2022-01-31 20:52:13 +00:00
var fitAddon = new FitAddon.FitAddon();
term.loadAddon(fitAddon);
term.open(consoleDiv);
term.scrollToTop();
fitAddon.fit();
window.addEventListener("resize", function(ev){fitAddon.fit();}, false);
term.focus();
var cxReadFunc = null;
function writeData(buf)
{
term.write(new Uint8Array(buf));
}
function readData(str)
{
if(cxReadFunc == null)
return;
for(var i=0;i< str.length ; i + + )
cxReadFunc(str.charCodeAt(i));
}
term.onData(readData);
//Actual CheerpX and bash specific logic
2022-02-01 07:57:32 +00:00
function runBash()
2022-01-31 20:52:13 +00:00
{
2022-02-01 07:57:32 +00:00
const structure = {
name: "bash",
cmd: "/bin/bash",
args: ["--login"],
env: ["HOME=/home/user", "TERM=xterm", "USER=user", "SHELL=/bin/bash", "EDITOR=vim", "LANG=en_US.UTF-8", "LC_ALL=C"],
expectedPrompt: ">",
versionOpt: "--version",
comment_line: "#",
description_line: "The original Bourne Again SHell",
}
2022-01-31 20:52:13 +00:00
if (typeof SharedArrayBuffer === "undefined")
{
printOnTerm.printError(printOnTerm.getSharedArrayBufferMissingMessage());
return;
}
async function runTest(cx)
{
term.scrollToBottom();
async function cxLogAndRun(cheerpx, cmd, args, env)
{
await cheerpx.run(cmd, args, env);
printOnTerm.printMessage(" ");
}
cxReadFunc = cx.setCustomConsole(writeData, term.cols, term.rows);
function preventDefaults (e) {
e.preventDefault()
e.stopPropagation()
}
consoleDiv.addEventListener("dragover", preventDefaults, false);
consoleDiv.addEventListener("dragenter", preventDefaults, false);
consoleDiv.addEventListener("dragleave", preventDefaults, false);
consoleDiv.addEventListener("drop", preventDefaults, false);
var opts = {env:structure.env, cwd:"/home/user"};
while (true)
{
await cxLogAndRun(cx, structure.cmd, structure.args, opts);
}
}
function failCallback(err)
{
printOnTerm.printError(printOnTerm.getErrorMessage(err));
}
2022-10-04 12:17:36 +00:00
CheerpXApp.create({devices:[{type:"block",url:"https://disks.leaningtech.com/webvm_20221004.ext2",name:"block1"}],mounts:[{type:"ext2",dev:"block1",path:"/"},{type:"cheerpOS",dev:"/app",path:"/app"},{type:"cheerpOS",dev:"/str",path:"/data"},{type:"devs",dev:"",path:"/dev"}], networkInterface}).then(runTest, failCallback);
2022-01-31 20:52:13 +00:00
}
function initialMessage()
{
2022-10-03 12:33:49 +00:00
printOnTerm.printMessage(printOnTerm.getAsciiTitle());
2022-10-05 14:11:51 +00:00
printOnTerm.printMessage([""]);
2022-01-31 20:52:13 +00:00
printOnTerm.printMessage(printOnTerm.getAsciiText());
2022-10-05 14:11:51 +00:00
term.registerLinkMatcher(/https:\/\/leaningtech.com\/webvm-virtual-machine-with-networking-via-tailscale/, function(mouseEvent, matchedString) {
2022-10-03 15:21:09 +00:00
window.open(matchedString, "_blank")
});
2022-01-31 20:52:13 +00:00
console.log("Welcome. We appreciate curiosity, but be warned that keeping the DevTools open causes significant performance degradation and crashes.");
}
initialMessage();
2022-02-01 07:57:32 +00:00
var script = document.createElement('script');
script.type = 'text/javascript';
2022-07-21 09:34:52 +00:00
var cxFile = "https://cheerpxdemos.leaningtech.com/publicdeploy/CX_VERSION/cx.js";
2022-02-01 07:57:32 +00:00
script.src = cxFile;
script.addEventListener("load", runBash, false);
document.head.appendChild(script);
2022-01-31 20:52:13 +00:00
< / script >
2022-10-05 10:19:55 +00:00
<!-- Google tag (gtag.js) -->
< script defer src = "https://www.googletagmanager.com/gtag/js?id=G-818T3Y0PEY" > < / script >
< script defer >
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-818T3Y0PEY');
< / script >
2022-01-31 20:52:13 +00:00
< / body >
< / html >