Dev.to WebDev 🛠 Dev 👁 0 📖 5 min read

How We Built Browser-Based Remote Desktop for Windows PCs

Most remote-support tools make you install a viewer app before you can help anyone. We wanted the opposite: an IT admin opens a dashboard in a browser tab, clicks a device, and sees its screen — no client software, no VP

Most remote-support tools make you install a viewer app before you can help anyone. We wanted the opposite: an IT admin opens a dashboard in a browser tab, clicks a device, and sees its screen — no client software, no VPN, no port forwarding on the customer's network. This post is a walkthrough of how we built that for OniConnect, our RMM (remote monitoring and management) platform, and the trade-offs we hit along the way.

The pieces

There are three moving parts:

  1. A Windows agent (C#, .NET Framework) installed on each managed PC. It runs as a Windows service, enrolls itself with the server, sends heartbeats and telemetry, and — when asked — captures the screen and injects mouse/keyboard input.
  2. A PHP backend that owns accounts, device inventory, sessions, and authorization. It never touches screen frames.
  3. A small Node.js relay that sits between the agent and the browser and does nothing but forward frames. Keeping the relay dumb and separate from the PHP app turned out to be one of our better decisions: screen traffic is high-volume and latency-sensitive, and we didn't want it competing with web requests.

The browser viewer is plain HTML/JS with a <canvas> and a WebSocket. That's it — no plugins, no WebRTC (yet), no native app.

How a session actually works

When an admin clicks "Remote connect" on a device, the flow is:

  1. The backend checks entitlements (plan, role, device online via a recent heartbeat) and, for full-control sessions, requires a step-up authenticator code. Remote control of someone's PC is exactly the kind of action that should never be one stolen session cookie away.
  2. The backend creates a short-lived session token and tells the agent (over its existing outbound connection) that a viewer wants in.
  3. The agent opens a WebSocket to the relay and announces the session. The browser opens its own WebSocket to the same relay with the token. The relay pairs them.
  4. The agent starts sending screen frames as binary WebSocket messages. The browser sends back small JSON control messages: INPUT (mouse move/click, key events), PING, and END_SESSION. The relay understands a handful of message types — SESSION_ACCEPT, SESSION_REJECT, SESSION_END, and the rest — and forwards everything else untouched.

Two design choices worth calling out:

The agent always dials out. Managed PCs live behind NATs, firewalls, and hotel Wi-Fi. The agent initiates every connection, so nothing needs to be opened on the customer's network. The agent tries port 443 first (looks like ordinary HTTPS traffic, survives most corporate proxies) and falls back to a dedicated port if 443 is blocked.

The relay never interprets frames. It routes by session ID and forwards bytes. That keeps it fast, keeps the PHP app out of the hot path, and means we can scale or restart the relay without touching account logic.

Screen capture and the first-frame problem

On the agent side, we capture the desktop using GDI (BitBlt on the desktop DC), encode frames, and stream them. Software encoding has a hard ceiling — we are honest with ourselves that this is a support tool, not a gaming stream. What matters for support work is not 60 FPS; it's that the picture is legible and input feels responsive.

The metric we obsessed over was time to first frame. Early versions took ~26 seconds from clicking "Start" to seeing the desktop. That's an eternity when someone is waiting on the phone. The fixes were unglamorous: don't wait for a full keyframe negotiation before sending something, send the first capture immediately on session accept, and keep the agent's capture loop warm so it isn't cold-starting GDI handles on demand. The goal we set: the first frame should appear essentially as soon as the admin presses Start.

Input goes the other way: the browser translates canvas mouse events into device coordinates (accounting for scaling), sends them as INPUT messages, and the agent replays them with SendInput. Keyboard handling needs care with layout differences, but for support work it's manageable.

The console session gotcha

One Windows-specific trap cost us real debugging time: remote sessions attach to the console session only. If a PC is being accessed over RDP and nobody is logged in at the physical console, capture fails with the equivalent of "no active console session." Our workaround for headless/RDP-only boxes is to move the session to the console (query session, then tscon <id> /dest:console) before connecting. If you're building anything similar on Windows, decide early how you'll handle session 0 isolation and RDP-only machines — it will bite you otherwise.

Security notes

A few things we built in from the start:

  • Agent requests are HMAC-signed, so a leaked enrollment token alone isn't enough to impersonate a device.
  • Step-up verification (authenticator code) is required before full-control remote sessions, run-command, shutdown/restart, and other destructive actions.
  • Sessions are short-lived and audited: idle and absolute timeouts, and every remote session start/end is written to an audit log.
  • No shell in the relay. The relay protocol deliberately has no terminal/PTY message type. Remote command execution exists in the product, but it goes through the backend's command queue with its own authorization — not through the screen-streaming path.

What we'd do differently

  • WebRTC is the obvious next step for lower latency and adaptive bitrate, but it adds NAT-traversal complexity (TURN servers, ICE) that a plain WebSocket relay avoids. For a small team, "works everywhere on 443" beat "lowest possible latency."
  • Differential frame encoding (only sending changed regions) would cut bandwidth a lot on mostly-static desktops. It's on the list.
  • We'd write the agent's capture loop with backpressure from day one: if the network is slow, drop frames instead of queueing them, or input latency snowballs.

If you're building remote support tooling, the boring architecture — outbound-only agent, dumb relay, browser viewer — gets you surprisingly far, and it works on locked-down networks where fancier stacks fall over.

OniConnect is an RMM for solo IT admins and small MSPs: monitoring, device health checks with one-click repairs, Windows/program updates, and browser-based remote access, priced per device from $0.50. There's a free 3-day trial at oniconnect.mooo.com.

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.