Owebview – Crafting Your Own Cross-Platform GUI App with Web Rendering
SPEAKERS
ABSTRACT
OCaml has several ways to put a window on screen. This workshop takes the one that costs the least and gives the most back: let the operating system's own web engine do the rendering, and keep every line you write in OCaml.
owebview wraps the webview C library — a native window hosting WKWebView on
macOS, WebKitGTK on Linux or WebView2 on Windows. Over two hours we will start
from a template that already builds and already opens a window, and end with a
desktop application you can install on your own machine, built entirely in OCaml
on both sides of the window.
No prior experience with C bindings, with JavaScript, or with front-end frameworks is assumed. If you can write OCaml and use dune, you can follow.
What we will build
A game: Conway's Game of Life. A grid you can draw on, a generation loop you can start and stop, and what turns a demo into an application — saving a game to a file and opening it again.
The board and the rules live in the page; the native side only touches the disk. That split is the point, and it is the one most owebview applications end up with.
Outline
1 · The template (~15 min) Build it, open the window, and see what is already there — including where the binary looks for its page, which comes back in the last segment.
2 · The back end (~25 min) The native side has one job: writing a game to disk and reading it back. Two functions exposed to the page, and that is where we meet the bridge — what can cross it, why every call is asynchronous, and how a JSON library turns it into something you would willingly call from typed code.
3 · Making it a desktop application (~25 min)
A window is not yet an application. With owebview.desktop: a native menu bar
whose items are OCaml closures with keyboard shortcuts, the system's own
dialogs so that saving and opening ask the user where, and an application icon
for the dock or the taskbar.
4 · The page in OCaml, with vdom (~30 min) Compile the page with js_of_ocaml and drive it with a virtual-DOM library, in the Elm style. The game lives here: the board, the rules and the generation loop, with the grid as a pure function of the board rather than a thing you mutate. From here on both sides are OCaml and the JavaScript disappears.
5 · Putting it in somebody's hands (~15 min)
Two routes. opam install of your own project, which everyone in the room can
do in a couple of minutes, and which raises the question of where the assets
went. Then the platform's own installer, for the machine you brought, with the
scripts to take home. OCaml does not cross-compile, so everyone ships for their
own platform: this is where the room's differences become the lesson.
The remaining time is deliberate slack: setups differ, and segments 2 and 5 are where they show.
Prerequisites
- OCaml 4.14 or later, opam and dune, on a laptop you can install software on.
- Linux: Fedora 43/44, Debian 12 or Ubuntu 22.04 at the earliest.
- macOS: nothing beyond the Xcode command line tools
- Windows: a mingw-w64 toolchain and the WebView2 SDK headers
(
nuget install Microsoft.Web.WebView2).
The template and its setup instructions will be published ahead of time.
What you will take away
- A game you can play, install and hand to somebody, written entirely in OCaml and running on your own machine.
- A clear picture of how an OCaml process and a web view talk to each other, and what that costs.
- What
owebview.desktopprovides — menus, dialogs, application icon, asset location — and when you reach for each. - Both ways to ship the result: an opam-installable project, and the packaging scripts for all four platform installers, ready to reuse.
Reference material
This workshop is the hands-on companion to the talk Owebview — cross-platform desktop apps in OCaml, with a web UI; either stands on its own.