# noVNC plugin

The noVNC plugin adds a virtual desktop to an instance.
You use the desktop in a browser through [noVNC](https://novnc.com), and a program drives it through the plugin endpoint.
The plugin brings its own root filesystem for the desktop, so the image of the instance needs no desktop software.

| Image | Content |
|-------|---------|
| `plugins/novnc:latest` | A desktop with a terminal, approximately 210 MiB. |
| `plugins/novnc:firefox-latest` | A desktop with a terminal and the Extended Support Release of Firefox, approximately 510 MiB, for an instance with at least 2 GiB of memory. |

The plugin serves the desktop on the destination port of its first [plugin service](/plugins#plugin-services):

```bash
unikraft api /v1/instances --metro fra \
  '{
    "name": "my-desktop",
    "image": "official/alpine:latest",
    "memory_mb": 2048,
    "scale_to_zero": { "policy": "on", "stateful": true, "cooldown_time_ms": 5000 },
    "plugins": [
      {
        "name": "novnc",
        "image": "plugins/novnc:firefox-latest",
        "config": { "password": "<a long random password>", "width": 1280, "height": 800 },
        "services": [
          { "port": 443, "destination_port": 6080, "handlers": ["tls", "http"] }
        ]
      }
    ]
  }'
```

Open `https://novnc-<uuid>.api.fra.unikraft.cloud/` in a browser, and log in with the user `novnc` and the `password` of the configuration.
With stateful [scale-to-zero](/features/scale-to-zero), the instance sleeps while nobody uses the desktop, and wakes with its windows still open.

:::caution
Always set a `password`.
Without one, anyone who knows the address can control the desktop.
:::

The plugin takes these keys in `config`, all optional:

| Key | Default | Description |
|-----|---------|-------------|
| `password` | None | Password of the desktop, without which the desktop has no authentication |
| `user` | `novnc` | User name for HTTP basic authentication, without a `:` |
| `width`, `height` | `1024`, `768` | Initial size of the screen, at most 2560 × 1600 |
| `host_view` | `false` | `true` shows the files and mounts of the instance in the desktop, and runs the desktop programs as `root` |
| `launchers` | None | Panel buttons, each with a `name`, an `exec` command, and an optional `icon` |
| `autostart` | None | Shell commands that the desktop starts when it's ready |

The desktop accepts the password in these ways:

| Method | Use |
|--------|-----|
| HTTP basic authentication with `user` and `password` | The login dialog of the browser, or a program, for example `curl -u 'novnc:<password>'` |
| The `token` query parameter | A link that opens the desktop without a login dialog, a WebSocket to `/websockify`, or a frame on a page of another site |
| A session cookie | A browser after it opens a link with `token`, until the desktop restarts |

For example, this link opens the desktop:

```text
https://novnc-<uuid>.api.fra.unikraft.cloud/?token=<URL-encoded password>&autoconnect=true
```

In a browser, the plugin then sets a session cookie, and removes the token from the address.
The first address still contains the password, so the browser history and the logs of a proxy can keep it.
Treat a link with `token` like the password.

A page of another site can show the desktop in a frame only with the token in the address of the frame, for example `vnc.html?token=<URL-encoded password>&autoconnect=true`.
Thus, that page contains the password.

A program drives the desktop through the plugin endpoint, `/v1/instances/<uuid>/plugins/novnc`.
The [API reference](/api/plugins/novnc) describes each request.
Positions are in pixels from the top-left corner of the screen:

| Request | Body | Description |
|---------|------|-------------|
| `GET /screen` | None | Returns the `width` and `height` of the screen. |
| `PUT /screen` | `{"width": 1280, "height": 800}` | Resizes the screen, and keeps the windows open. |
| `POST /pointer/move` | `{"x": 512, "y": 384}` | Moves the pointer. |
| `POST /pointer/click` | `{"x": 512, "y": 384, "button": "left", "count": 2}` | Presses and releases a mouse button: `x` and `y` are optional, `button` is `left`, `middle`, or `right`, and `count` is 1 to 10. |

```bash
unikraft api /v1/instances/<uuid>/plugins/novnc/screen -X PUT --metro fra \
  '{"width": 1280, "height": 800}'
```

## Learn more

* [Plugins](/plugins): how plugins load, and how plugin services work.
* [noVNC plugin API reference](/api/plugins/novnc): every request of the plugin.
* [Remote desktops](/use-cases/remote-desktops): run a desktop on Unikraft Cloud.
* [Scale-to-zero](/features/scale-to-zero): how an idle desktop sleeps and wakes.
