# Linux in a browser: the phone's desktop on any computer's screen LinuxOnDroid → Settings → **Open in a browser**. The phone then serves its Linux desktop to any browser on the same network, and a laptop becomes Linux's screen, keyboard and mouse with nothing installed on it: no app, no extension, no account. The picture is the phone's **hardware H.264**, the same stream the desktop app gets over adb (usb-desktop.md): Xvnc's pixels raw over loopback, one GL draw into the phone's video encoder, H.264 down a WebSocket, decoded on the computer's GPU by WebCodecs and drawn the moment it leaves the decoder. No video element, no jitter buffer, no player. The pointer is the computer's own, in the shape Xvnc sends, so it moves at the screen's rate whatever the video does. Linux's sound comes down the same connection and plays in the browser. What a person does: 1. **Phone:** LinuxOnDroid → ⋮ → Settings → Linux on a computer → *Open in a browser*. The card shows two numbered steps: the address (`192.168.1.20:7443`) and a six-digit code. 2. **Computer:** type the address. The page offers the secure connection first, and the browser warns once that it is not private (the phone signs its own); *Advanced*, then *Continue*. A browser that offers no way past that warning (a managed laptop's may not) can come back and choose *Continue without encryption*. 3. Type the code. Linux fills the window at the window's size. **Low**, **Medium** and **High** are at the top. This record exists for the same reason the others do: several choices below look arbitrary until you know what was measured, or what a browser refuses. ## Shape | Piece | File | What it owns | | --- | --- | --- | | Vocabulary | `LinuxBrowser.java` | the switch, the code, the browsers let in (hashed), the state line, the phone's addresses; files in `files/browser/`, read by both processes | | The certificate | `LinuxBrowserCert.java` | made by the phone, in DER; kept, with its key, until a month before it runs out | | The door | `LinuxBrowserServer.java` | one port for both schemes, the page, `/pair`, `/forget`, `/stream`, who may ask and for how long | | A look at the first byte | `LinuxBrowserPeek.java` | `recv(MSG_PEEK)`: TLS or plain HTTP, without taking it | | The picture | `LinuxStream.java` | `serve` (a browser's session), `quality` (live), telling a browser it was replaced, the browser's sound on and off | | The sound | `LinuxStreamAudio.java` | the guest's sound tap, read for a browser and shaped for its quality: PCM as it is, smaller PCM (downmixed, low-pass filtered, every second or third frame), or into an encoder; long silence not sent | | Its Opus | `LinuxStreamOpus.java` | the phone's own Opus encoder (MediaCodec, Android 10 on), for Low and Medium | | The phone's speaker | `LinuxAudio.java` | `hold`: quiet while a browser watches, the tap let go | | The encoder | `LinuxStreamEncoder.java` | a picture smaller than the desktop, for Low; a browser's key frames only when asked | | The bitrate | `LinuxStreamRate.java` | how late frames arrive, from the page's arrival times: cut the moment a queue stands | | The microphone | `LinuxStreamMic.java` | a browser's microphone into a pipe Linux's PulseAudio reads as "Browser microphone" | | The handshake | `LinuxStreamSocket.java` | `accept`: the WebSocket upgrade without the loopback rules | | The service | `LinuxService.java` | listening while the switch is on, the notification, starting the desktop as the switch goes on | | Coming back | `RemoteResumeReceiver.java` | a boot or an update | | The card | `LinuxSettingsActivity.java` | LinuxOnDroid only; the desktop build has the desktop app | | The page | `assets/linux/browser/` | `index.html`, `viewer.css`, `viewer.js`, `h264.js`, `keysym.js`, `icon.svg`; `mse.js`, the picture over plain http; `video-worker.js`, the socket, the decoder and the canvas off the page's thread; `touch.js`, fingers; `mic-worklet.js`, the microphone | | Linux's files | `LinuxFiles.java` | `/fs/`: listing, sending (resumable, and many small files to a request), bringing back (ranges, ZIP), the Trash, tickets; Linux's paths, its links followed as Linux follows them | | Their pictures | `LinuxFilesThumbs.java` | small pictures of photos (HEIC too), videos, songs' covers and PDFs, with Android's decoders | | Files, the page | `files.js`, `files.css`, `transfer.js`, `peek.js`, `fileicons.js` | the file manager, the transfers and their panel, Quick look, kinds and icons | | Check | `test/linux-browser-test.mjs`, `test/linux-browser/` | the server on a JVM and the page in a real browser; `--device`: the same on a phone (`--throttle`: through a slow link, the bitrate's two rules side by side); `RateCheck.java`: the bitrate's rules on simulated links | | Measure | `test/linux-browser-latency.mjs` | how late frames are drawn, end to end, decoded on the page's thread or in the worker, the page idle or busy | | Check, Files | `test/linux-files-test.mjs` | the same server over a stand-in Linux, from Node and in a browser window | ## Why this picture, and not another Every browser route to a remote desktop that exists was weighed against what the desktop app already measured on the cable: 45–55 fps at 2560×1440, 12–15 ms in the encoder (usb-desktop.md, "Verified"). - **noVNC**, the phone's own window: Xvnc compresses every change into JPEG and zlib on the phone's CPU, which is also drawing the desktop, and the page undoes it in JavaScript. Fine for a terminal; a scrolling page shows it. - **WebRTC**: a jitter buffer and congestion control built for lossy networks, added delay on a LAN; when this project showed the Web viewer's WebRTC in the desktop app's window, it was visibly laggier than a raw socket. `vnrit`, the nearest thing on GitHub (an X11 desktop to a browser, Android's MediaCodec on Termux), is WebRTC through GStreamer, 24 fps and 500 kb/s by default. - **Media Source Extensions** (H.264 into a `