2022-01-31 20:52:13 +00:00
<!DOCTYPE html>
< html lang = "en" style = "height:100%;" >
2023-05-08 14:58:46 +00:00
< meta property = "og:image" content = "https://webvm.io/assets/reddit.png" / >
2022-01-31 20:52:13 +00:00
< head >
< meta charset = "utf-8" >
2023-05-08 15:31:40 +00:00
< meta name = "viewport" content = "width=1100, initial-scale=1.0" >
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" / >
2023-05-08 14:58:46 +00:00
< meta property = "og:image" content = "https://webvm.io/assets/social.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." >
2023-05-08 14:58:46 +00:00
< meta name = "twitter:image" content = "https://webvm.io/assets/social.png" / >
2022-10-06 10:57:28 +00:00
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" >
2023-05-17 10:30:30 +00:00
< link rel = "stylesheet" href = "https://cdnjs.cloudflare.com/ajax/libs/github-fork-ribbon-css/0.2.3/gh-fork-ribbon.min.css" / >
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" / >
2023-05-17 10:30:30 +00:00
< style > . github-fork-ribbon : before { background-color : #ea1e69 ; } < / style >
2023-05-08 14:58:46 +00:00
<!-- Serviceworker script that adds the COI and CORS headers to the response headers in cases where the server does not support it. -->
< script src = "serviceWorker.js" > < / script >
2022-10-05 10:19:55 +00:00
< script src = "./xterm/xterm.js" > < / script >
< script src = "./xterm/xterm-addon-fit.js" > < / script >
2024-07-08 09:51:49 +00:00
< script src = "./xterm/xterm-addon-web-links.js" > < / script >
2023-05-16 14:50:00 +00:00
< script src = "network.js" > < / script >
2023-09-28 12:16:50 +00:00
< script defer data-domain = "webvm.io" src = "https://plausible.leaningtech.com/js/script.js" > < / 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%;" >
2023-05-17 15:13:21 +00:00
< a class = "github-fork-ribbon right-bottom" href = "https://github.com/leaningtech/webvm/" target = "_blank" data-ribbon = "Fork me on GitHub" title = "Fork me on GitHub" > Fork me on GitHub< / a >
2023-05-08 13:39:26 +00:00
< div >
< div style = "padding-top: 0.7em;padding-bottom: 0.7em;font-size: 0.3em; font-weight: 200;vertical-align:center;height: 120px;" >
< div style = "margin-left: 20px; height: 100%; display: flex; align-items: center; justify-content: space-between;" >
< pre style = "font-family: monospace; font-weight: 600; font-size: large; color: #ad7fa8;" >
__ __ _ __ ____ __
\ \ / /__| |_\ \ / / \/ |
\ \/\/ / -_) '_ \ V /| |\/| |
\_/\_/\___|_.__/\_/ |_| |_|
< / pre >
< div style = "height:100%;display: flex; flex-direction: column;justify-content: space-between;" >
< div style = "padding-top: 0.7em;font-size: 0.3em; font-weight: 200;vertical-align:center;height:50px;" >
< div style = "margin-right: 10px; margin-left: 20px; height: 100%; display: flex; align-items: center; justify-content: flex-end;gap: 50px;" >
< div style = "padding-top: 0.7em;font-size: 0.3em; font-weight: 200;vertical-align:center;" >
< a href = "https://leaningtech.com" style = "text-decoration: none; height: 100%;" target = "_blank" >
< div style = "color: white; font-family: montserrat; font-weight: 400; font-size: large; height: 100%; display: flex; align-items: center;" >
< span > Made with ❤ ️ by < / span >
< img src = "assets/leaningtech.png" height = "40px" style = "margin-left: 5px;" >
< / div >
< / a >
< / div >
< / div >
< / div >
< div style = "padding-top: 0.7em;font-size: 0.3em; font-weight: 200;vertical-align:center;height:50px;" >
< div style = "margin-right: 10px; margin-left: 20px; height: 100%; display: flex; align-items: center; justify-content: flex-end;gap: 50px;" >
2023-05-15 17:01:19 +00:00
< div style = "color: white; font-family: montserrat; font-weight: 400; font-size: large; height: 100%; display: flex; align-items: center;" >
< span > CPU < / span >
< span id = "cpuactivity" style = "margin-left: 7px;" > 🟢 < / span >
< / div >
< div style = "color: white; font-family: montserrat; font-weight: 400; font-size: large; height: 100%; display: flex; align-items: center;" >
< span > HDD < / span >
< span id = "hddactivity" style = "margin-left: 7px;" > 🟢 < / span >
< / div >
2023-05-30 10:35:59 +00:00
< a id = "loginLink" style = "user-select: text ;text-decoration: none; height: 100%;" >
< div style = "color: white; font-family: montserrat; font-weight: 400; font-size: large; height: 100%; display: flex; align-items: center;" >
< div style = "position: relative;" >
< span style = "cursor: pointer" id = "networkStatus" > Connect via Tailscale < / span >
< span style = "cursor: pointer; position: absolute; right: 0px; visibility: hidden;" id = "ipCopied" > Copied! < / span >
< / div >
< img src = "assets/tailscale.svg" height = "35px" style = "margin-left: 7px;" >
< / div >
< / a >
2023-05-09 09:45:06 +00:00
< a href = "https://discord.gg/yTNZgySKGa" style = "text-decoration: none; height: 100%;" target = "_blank" >
2023-05-08 13:39:26 +00:00
< div style = "color: white; font-family: montserrat; font-weight: 400; font-size: large; height: 100%; display: flex; align-items: center;" >
2023-05-08 14:23:08 +00:00
< span > Join Discord < / span >
2023-05-17 09:23:21 +00:00
< img src = "assets/discord-mark-blue.svg" height = "35px" style = "margin-left: 7px;" >
2023-05-08 13:39:26 +00:00
< / div >
< / a >
2023-05-09 09:45:06 +00:00
< a href = "https://github.com/leaningtech/webvm/issues" style = "text-decoration: none; height: 100%;" target = "_blank" >
2023-05-08 13:39:26 +00:00
< div style = "color: white; font-family: montserrat; font-weight: 400; font-size: large; height: 100%; display: flex; align-items: center;" >
2023-05-08 14:23:08 +00:00
< span > GitHub Issues < / span >
2023-05-17 09:23:21 +00:00
< img src = "assets/github-mark-white.svg" height = "35px" style = "margin-left: 5px;" >
2023-05-08 13:39:26 +00:00
< / div >
< / a >
< / div >
< / div >
< / div >
2022-09-07 15:46:56 +00:00
< / div >
< / div >
2023-05-08 13:39:26 +00:00
< / div >
2022-09-07 15:46:56 +00:00
< div style = "flex-grow:0; flex-shrink: 0; height:1px; width: 100%; background-color: white;" >
< / div >
2023-05-17 15:04:04 +00:00
< main style = "display: flex; flex-direction: row; justify-content: space-between; margin: 5px; 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 = {
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
"| |",
2023-05-22 13:08:34 +00:00
"| [NEW!] Your own WebVM with custom images via Dockerfile: |",
2022-10-05 14:11:51 +00:00
"| |",
2023-05-22 13:08:34 +00:00
"| " + underline + "https://leaningtech.com/mini-webvm-your-linux-box-from-dockerfile-via-wasm" + normal +" |",
2022-10-05 14:11:51 +00:00
"| |",
"+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+",
2022-01-31 20:52:13 +00:00
"",
2023-05-16 09:57:17 +00:00
" Welcome to WebVM. 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 ()
{
2023-12-15 15:44:11 +00:00
const isCustom = window.location.hostname !== "webvm.io";
const isSecureContext = window.isSecureContext;
2022-01-31 20:52:13 +00:00
const text = [
"",
"",
color + "CheerpX could not start" + normal,
"",
2023-12-15 15:44:11 +00:00
"CheerpX uses SharedArrayBuffer, which is not available right now.",
2022-01-31 20:52:13 +00:00
"",
2023-12-15 15:44:11 +00:00
!isSecureContext & & " - This page is not in a secure context. Serve over HTTPS or WSS.",
!isSecureContext & & " " + underline + "https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts" + noral,
isCustom & & " - The document is not cross-origin isolated.",
isCustom & & " " + underline + "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer#security_requirements" + normal,
" - Your browser might not support SharedArrayBuffer.",
" Since 2022, all major browsers support this feature.",
" " + underline + "https://caniuse.com/sharedarraybuffer" + normal,
].filter(Boolean);
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);
2024-07-08 09:51:49 +00:00
var linkAddon = new WebLinksAddon.WebLinksAddon();
term.loadAddon(linkAddon);
2022-01-31 20:52:13 +00:00
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);
2024-07-04 14:53:20 +00:00
function hddCallback(state)
{
var h = document.getElementById("hddactivity");
if(state == "ready")
h.textContent = "\u{1F7E2}";
else
h.textContent = "\u{1F7E0}";
}
function cpuCallback(state)
{
var h = document.getElementById("cpuactivity");
if(state == "ready")
h.textContent = "\u{1F7E2}";
else
h.textContent = "\u{1F7E0}";
}
2022-01-31 20:52:13 +00:00
//Actual CheerpX and bash specific logic
2022-02-01 07:57:32 +00:00
function runBash()
2022-01-31 20:52:13 +00:00
{
2023-05-22 12:19:39 +00:00
// cmd, cwd, args and env are replaced by the Github actions workflow.
2023-05-22 15:18:28 +00:00
var cmd = CMD;
var args = ARGS;
var env = ENV;
var cwd = CWD;
// Reasonable defaults for local deployments
2023-05-23 07:10:03 +00:00
// var cmd = "/bin/bash";
// var args = ["--login"];
// var env = ["HOME=/home/user", "TERM=xterm", "USER=user", "SHELL=/bin/bash", "EDITOR=vim", "LANG=en_US.UTF-8", "LC_ALL=C"];
// var cwd = "/home/user";
2022-02-01 07:57:32 +00:00
const structure = {
2023-05-22 15:18:28 +00:00
cmd: cmd,
args: args,
env: env,
cwd: cwd
2022-02-01 07:57:32 +00:00
}
2022-01-31 20:52:13 +00:00
if (typeof SharedArrayBuffer === "undefined")
{
printOnTerm.printError(printOnTerm.getSharedArrayBufferMissingMessage());
return;
}
2023-05-16 14:50:00 +00:00
let networkInterface = setupNetworkInterface();
2022-01-31 20:52:13 +00:00
async function runTest(cx)
{
2024-07-04 14:53:50 +00:00
var processCount = 0;
function handleProcessCreated()
{
processCount++;
plausible(`Process started: ${processCount}`);
if(processCount == 5)
{
// Make sure no further event is reported
cx.unregisterCallback("processCreated", handleProcessCreated);
}
}
cx.registerCallback("processCreated", handleProcessCreated);
2024-07-04 14:53:20 +00:00
cx.registerCallback("cpuActivity", cpuCallback);
cx.registerCallback("diskActivity", hddCallback);
2023-05-16 14:50:00 +00:00
registerNetworkLogin(cx, networkInterface);
2022-01-31 20:52:13 +00:00
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);
2023-05-22 12:19:39 +00:00
var opts = {env:structure.env, cwd:structure.cwd, uid: 1000, gid: 1000};
2022-01-31 20:52:13 +00:00
while (true)
{
await cxLogAndRun(cx, structure.cmd, structure.args, opts);
}
}
function failCallback(err)
{
printOnTerm.printError(printOnTerm.getErrorMessage(err));
}
2023-05-16 09:58:53 +00:00
// The device url and type are replaced by Github Actions.
2024-07-04 14:53:20 +00:00
CheerpXApp.create({devices:[{type:DEVICE_TYPE,url:IMAGE_URL,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: networkInterface}).then(runTest, failCallback);
2022-01-31 20:52:13 +00:00
}
function initialMessage()
{
printOnTerm.printMessage(printOnTerm.getAsciiText());
console.log("Welcome. We appreciate curiosity, but be warned that keeping the DevTools open causes significant performance degradation and crashes.");
}
initialMessage();
2023-05-16 09:57:17 +00:00
async function loadCX()
{
// Find the latest build
var r = await fetch("https://cheerpxdemos.leaningtech.com/publicdeploy/LATEST.txt");
var url = await r.text();
url = url.trim();
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = url;
script.addEventListener("load", runBash, false);
document.head.appendChild(script);
}
loadCX();
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 >