index.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. <!DOCTYPE html>
  2. <html lang="en" style="height:100%;">
  3. <meta property="og:image" content="https://webvm.io/assets/reddit.png"/>
  4. <head>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=1100, initial-scale=1.0">
  7. <title>WebVM - Linux virtualization in WebAssembly</title>
  8. <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.">
  9. <meta name="keywords" content="WebVM, Virtual Machine, CheerpX, x86 virtualization, WebAssembly, Tailscale, JIT">
  10. <meta property="og:title" content="WebVM - Linux virtualization in WebAssembly" />
  11. <meta property="og:type" content="website" />
  12. <meta property="og:site_name" content="WebVM"/>
  13. <meta property="og:image" content="https://webvm.io/assets/social.png" />
  14. <meta name="twitter:card" content="summary_large_image" />
  15. <meta name="twitter:site" content="@leaningtech" />
  16. <meta name="twitter:title" content="WebVM - Linux virtualization in WebAssembly" />
  17. <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.">
  18. <meta name="twitter:image" content="https://webvm.io/assets/social.png" />
  19. <!-- Apple iOS web clip compatibility tags -->
  20. <meta name="application-name" content="WebVM" />
  21. <meta name="apple-mobile-web-app-title" content="WebVM" />
  22. <meta name="apple-mobile-web-app-capable" content="yes" />
  23. <meta name="mobile-web-app-capable" content="yes" />
  24. <meta name="apple-mobile-web-app-status-bar-style" content="black" />
  25. <link rel="shortcut icon" href="./tower.ico">
  26. <link rel="preconnect" href="https://fonts.googleapis.com">
  27. <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  28. <link rel="stylesheet" id="us-fonts-css" href="https://fonts.googleapis.com/css?family=Montserrat%3A300%2C400%2C500%2C600%2C700&amp;display=swap&amp;ver=6.0.2" media="all">
  29. <link rel="stylesheet" href="./xterm/xterm.css" />
  30. <link rel="stylesheet" href="./scrollbar.css" />
  31. <!-- Serviceworker script that adds the COI and CORS headers to the response headers in cases where the server does not support it. -->
  32. <script src="serviceWorker.js"></script>
  33. <script src="./xterm/xterm.js"></script>
  34. <script src="./xterm/xterm-addon-fit.js"></script>
  35. <script src="network.js"></script>
  36. </head>
  37. <body style="margin:0;height:100%;background:black;color:white;overflow:hidden; display:flex; flex-direction: column; justify-content: space-between; height: 100%;">
  38. <div>
  39. <div style="padding-top: 0.7em;padding-bottom: 0.7em;font-size: 0.3em; font-weight: 200;vertical-align:center;height: 120px;">
  40. <div style="margin-left: 20px; height: 100%; display: flex; align-items: center; justify-content: space-between;">
  41. <pre style="font-family: monospace; font-weight: 600; font-size: large; color: #ad7fa8;">
  42. __ __ _ __ ____ __
  43. \ \ / /__| |_\ \ / / \/ |
  44. \ \/\/ / -_) '_ \ V /| |\/| |
  45. \_/\_/\___|_.__/\_/ |_| |_|
  46. </pre>
  47. <div style="height:100%;display: flex; flex-direction: column;justify-content: space-between;">
  48. <div style="padding-top: 0.7em;font-size: 0.3em; font-weight: 200;vertical-align:center;height:50px;">
  49. <div style="margin-right: 10px; margin-left: 20px; height: 100%; display: flex; align-items: center; justify-content: flex-end;gap: 50px;">
  50. <div style="padding-top: 0.7em;font-size: 0.3em; font-weight: 200;vertical-align:center;">
  51. <a href="https://leaningtech.com" style="text-decoration: none; height: 100%;" target="_blank">
  52. <div style="color: white; font-family: montserrat; font-weight: 400; font-size: large; height: 100%; display: flex; align-items: center;">
  53. <span>Made with &#10084;&#65039; by </span>
  54. <img src="assets/leaningtech.png" height="40px" style="margin-left: 5px;">
  55. </div>
  56. </a>
  57. </div>
  58. </div>
  59. </div>
  60. <div style="padding-top: 0.7em;font-size: 0.3em; font-weight: 200;vertical-align:center;height:50px;">
  61. <div style="margin-right: 10px; margin-left: 20px; height: 100%; display: flex; align-items: center; justify-content: flex-end;gap: 50px;">
  62. <div style="color: white; font-family: montserrat; font-weight: 400; font-size: large; height: 100%; display: flex; align-items: center;">
  63. <span>CPU </span>
  64. <span id="cpuactivity" style="margin-left: 7px;">&#x1F7E2;</span>
  65. </div>
  66. <div style="color: white; font-family: montserrat; font-weight: 400; font-size: large; height: 100%; display: flex; align-items: center;">
  67. <span>HDD </span>
  68. <span id="hddactivity" style="margin-left: 7px;">&#x1F7E2;</span>
  69. </div>
  70. <a id="loginLink" style="text-decoration: none; height: 100%; cursor:not-allowed;">
  71. <div style="color: white; font-family: montserrat; font-weight: 400; font-size: large; height: 100%; display: flex; align-items: center;">
  72. <span id="networkStatus">Connect via Tailscale </span>
  73. <img src="assets/tailscale.svg" height="40px" style="margin-left: 7px;">
  74. </div>
  75. </a>
  76. <a href="https://discord.gg/yTNZgySKGa" style="text-decoration: none; height: 100%;" target="_blank">
  77. <div style="color: white; font-family: montserrat; font-weight: 400; font-size: large; height: 100%; display: flex; align-items: center;">
  78. <span>Join Discord </span>
  79. <img src="assets/discord-mark-blue.svg" height="40px" style="margin-left: 7px;">
  80. </div>
  81. </a>
  82. <a href="https://github.com/leaningtech/webvm/issues" style="text-decoration: none; height: 100%;" target="_blank">
  83. <div style="color: white; font-family: montserrat; font-weight: 400; font-size: large; height: 100%; display: flex; align-items: center;">
  84. <span>GitHub Issues </span>
  85. <img src="assets/github-mark-white.svg" height="40px" style="margin-left: 5px;">
  86. </div>
  87. </a>
  88. </div>
  89. </div>
  90. </div>
  91. </div>
  92. </div>
  93. </div>
  94. <div style="flex-grow:0; flex-shrink: 0; height:1px; width: 100%; background-color: white;">
  95. </div>
  96. <main style="display: flex; flex-direction: row; justify-content: space-between; margin:0; height:100%;">
  97. <div style="flex-grow:1; height:100%;display:inline-block;margin:0;" class="scrollbar" id="console">
  98. </div>
  99. </main>
  100. <script>
  101. //Utility namespace to group all functionality related to printing (both error and non error) messages
  102. const color= "\x1b[1;35m";
  103. const bold= "\x1b[1;37m";
  104. const underline= "\x1b[94;4m";
  105. const normal= "\x1b[0m";
  106. var printOnTerm = {
  107. getAsciiTitle: function ()
  108. {
  109. var title = [
  110. color + " __ __ _ __ ____ __ " + normal,
  111. color + " \\ \\ / /__| |_\\ \\ / / \\/ | " + normal,
  112. color + " \\ \\/\\/ / -_) '_ \\ V /| |\\/| | " + normal,
  113. color + " \\_/\\_/\\___|_.__/\\_/ |_| |_| " + normal,
  114. ];
  115. return title;
  116. },
  117. getAsciiText: function ()
  118. {
  119. var text = [
  120. "+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+",
  121. "| |",
  122. "| WebVM is a server-less virtual Linux environment running fully client-side |",
  123. "| in HTML5/WebAssembly. |",
  124. "| |",
  125. "| WebVM is powered by the CheerpX virtualization engine, which enables safe, |",
  126. "| sandboxed client-side execution of x86 binaries on any browser. |",
  127. "| |",
  128. "| CheerpX includes an x86-to-WebAssembly JIT compiler, a virtual block-based |",
  129. "| file system, and a Linux syscall emulator. |",
  130. "| |",
  131. "| [NEW!] WebVM now supports full TCP and UDP networking via Tailscale! |",
  132. "| Click on 'Tailscale Login' to enable it. Read the announcement: |",
  133. "| |",
  134. "| " + underline + "https://leaningtech.com/webvm-virtual-machine-with-networking-via-tailscale" + normal +" |",
  135. "| |",
  136. "+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+",
  137. "",
  138. " Welcome to WebVM. If unsure, try these examples:",
  139. "",
  140. " python3 examples/python3/fibonacci.py ",
  141. " gcc -o helloworld examples/c/helloworld.c && ./helloworld",
  142. " objdump -d ./helloworld | less -M",
  143. " vim examples/c/helloworld.c",
  144. " curl --max-time 15 parrot.live # requires networking",
  145. "",
  146. ];
  147. return text;
  148. },
  149. getSharedArrayBufferMissingMessage: function ()
  150. {
  151. const text = [
  152. "",
  153. "",
  154. color + "CheerpX could not start" + normal,
  155. "",
  156. "CheerpX depends on JavaScript's SharedArrayBuffer, that your browser",
  157. " does not support.",
  158. "",
  159. "SharedArrayBuffer is currently enabled by default on recent",
  160. " versions of Chrome, Edge, Firefox and Safari.",
  161. "",
  162. "",
  163. "Give it a try from another browser!",
  164. ]
  165. return text;
  166. },
  167. getErrorMessage: function (error_message)
  168. {
  169. const text = [
  170. "",
  171. "",
  172. color + "CheerpX could not start" + normal,
  173. "",
  174. "CheerpX internal error message is:",
  175. error_message,
  176. "",
  177. "",
  178. "CheerpX is expected to work with recent desktop versions of Chrome, Edge, Firefox and Safari",
  179. "",
  180. "",
  181. "Give it a try from a desktop version / another browser!",
  182. ]
  183. return text;
  184. },
  185. printMessage: function (text) {
  186. for (var i=0; i<text.length; i++)
  187. {
  188. term.write(text[i]);
  189. term.write('\n');
  190. }
  191. },
  192. printError: function (message)
  193. {
  194. this.printMessage(message);
  195. term.write("\n\n");
  196. function writeCustom(something)
  197. {
  198. term.write(something);
  199. }
  200. },
  201. };
  202. var consoleDiv = document.getElementById("console");
  203. //xterm.js related logic
  204. var term = new Terminal({cursorBlink:true,convertEol:true, fontFamily:"monospace", fontWeight: 400, fontWeightBold: 700});
  205. var fitAddon = new FitAddon.FitAddon();
  206. term.loadAddon(fitAddon);
  207. term.open(consoleDiv);
  208. term.scrollToTop();
  209. fitAddon.fit();
  210. window.addEventListener("resize", function(ev){fitAddon.fit();}, false);
  211. term.focus();
  212. var cxReadFunc = null;
  213. function writeData(buf)
  214. {
  215. term.write(new Uint8Array(buf));
  216. }
  217. function readData(str)
  218. {
  219. if(cxReadFunc == null)
  220. return;
  221. for(var i=0;i<str.length;i++)
  222. cxReadFunc(str.charCodeAt(i));
  223. }
  224. term.onData(readData);
  225. //Actual CheerpX and bash specific logic
  226. function runBash()
  227. {
  228. const structure = {
  229. name: "bash",
  230. cmd: "/bin/bash",
  231. args: ["--login"],
  232. env: ["HOME=/home/user", "TERM=xterm", "USER=user", "SHELL=/bin/bash", "EDITOR=vim", "LANG=en_US.UTF-8", "LC_ALL=C"],
  233. expectedPrompt: ">",
  234. versionOpt: "--version",
  235. comment_line: "#",
  236. description_line: "The original Bourne Again SHell",
  237. }
  238. if (typeof SharedArrayBuffer === "undefined")
  239. {
  240. printOnTerm.printError(printOnTerm.getSharedArrayBufferMissingMessage());
  241. return;
  242. }
  243. let networkInterface = setupNetworkInterface();
  244. async function runTest(cx)
  245. {
  246. registerNetworkLogin(cx, networkInterface);
  247. term.scrollToBottom();
  248. async function cxLogAndRun(cheerpx, cmd, args, env)
  249. {
  250. await cheerpx.run(cmd, args, env);
  251. printOnTerm.printMessage(" ");
  252. }
  253. cxReadFunc = cx.setCustomConsole(writeData, term.cols, term.rows);
  254. function preventDefaults (e) {
  255. e.preventDefault()
  256. e.stopPropagation()
  257. }
  258. consoleDiv.addEventListener("dragover", preventDefaults, false);
  259. consoleDiv.addEventListener("dragenter", preventDefaults, false);
  260. consoleDiv.addEventListener("dragleave", preventDefaults, false);
  261. consoleDiv.addEventListener("drop", preventDefaults, false);
  262. // The variables uid and gid are replaced by Github Actions.
  263. var opts = {env:structure.env, cwd:"/home/user", uid: UID, gid: GID};
  264. while (true)
  265. {
  266. await cxLogAndRun(cx, structure.cmd, structure.args, opts);
  267. }
  268. }
  269. function failCallback(err)
  270. {
  271. printOnTerm.printError(printOnTerm.getErrorMessage(err));
  272. }
  273. function devCallback(state)
  274. {
  275. var h = document.getElementById("hddactivity");
  276. if(state == "ready")
  277. h.textContent = "\u{1F7E2}";
  278. else
  279. h.textContent = "\u{1F7E0}";
  280. }
  281. function cpuCallback(state)
  282. {
  283. var h = document.getElementById("cpuactivity");
  284. if(state == "ready")
  285. h.textContent = "\u{1F7E2}";
  286. else
  287. h.textContent = "\u{1F7E0}";
  288. }
  289. // The device url and type are replaced by Github Actions.
  290. 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, activityInterface: {cpu: cpuCallback, dev: devCallback}}).then(runTest, failCallback);
  291. }
  292. function initialMessage()
  293. {
  294. printOnTerm.printMessage([""]);
  295. printOnTerm.printMessage(printOnTerm.getAsciiText());
  296. term.registerLinkMatcher(/https:\/\/leaningtech.com\/webvm-virtual-machine-with-networking-via-tailscale/, function(mouseEvent, matchedString) {
  297. window.open(matchedString, "_blank")
  298. });
  299. console.log("Welcome. We appreciate curiosity, but be warned that keeping the DevTools open causes significant performance degradation and crashes.");
  300. }
  301. initialMessage();
  302. async function loadCX()
  303. {
  304. // Find the latest build
  305. var r = await fetch("https://cheerpxdemos.leaningtech.com/publicdeploy/LATEST.txt");
  306. var url = await r.text();
  307. url = url.trim();
  308. var script = document.createElement('script');
  309. script.type = 'text/javascript';
  310. script.src = url;
  311. script.addEventListener("load", runBash, false);
  312. document.head.appendChild(script);
  313. }
  314. loadCX();
  315. </script>
  316. <!-- Google tag (gtag.js) -->
  317. <script defer src="https://www.googletagmanager.com/gtag/js?id=G-818T3Y0PEY"></script>
  318. <script defer>
  319. window.dataLayer = window.dataLayer || [];
  320. function gtag(){dataLayer.push(arguments);}
  321. gtag('js', new Date());
  322. gtag('config', 'G-818T3Y0PEY');
  323. </script>
  324. </body>
  325. </html>