Hi everyone,
I’m happy to announce the first release of Owebview, OCaml bindings to webview. It means an embedded web rendering engine in your OCaml apps. It is now available on opam:
opam install owebview
Owebview opens a native window backed by the operating system’s own web engine — WebKit on macOS, WebKitGTK on Linux, WebView2 on Windows — and lets you drive it from OCaml. No Electron, no bundler, no packaged browser: a single executable and some HTML.
You can find a blog post about why Owebview is a solution for your OCaml GUIs.
An example window with the three.js library
Native dependencies
The system web engine, and nothing else:
- macOS — WebKit / Cocoa, already part of the system. Nothing to install.
- Linux —
gtk+-3.0andwebkit2gtk-4.1, pulled in by theconf-gtk3-webkitopam package (published alongside this release), soopam installresolves the depexts for your distribution. - Windows — the WebView2 runtime ships with Windows 10 and 11; the SDK headers are located through the NuGet cache at build time (
nuget install Microsoft.Web.WebView2).
The webview header itself is vendored, so nothing is fetched at build time, and the platform compile/link flags are detected by a dune-configurator script.
Examples
The repository ships several runnable examples:
dune exec examples/hellowv/hellowv.exe # bindings, assets, Dock icon
dune exec examples/timer/timer_posix.exe # threads + dispatch
dune exec examples/timer/timer_lwt.exe # the same, driven by Lwt
dune exec examples/d3/d3.exe # a D3.js chart
dune exec examples/three/three.exe # WebGL via three.js
dune exec examples/js_of_ocaml/hellowv.exe # frontend written in OCaml too
The last one is worth a look if you like the idea of one language end to end: the page’s logic is written with Brr and compiled by js_of_ocaml, so both sides of the bridge are OCaml.
Tutorial
There is a six-step tutorial that builds up from a first window to a full application: on-disk assets, the JS ↔ OCaml bridge, an asynchronous backend with Lwt, a 100% OCaml frontend, and the platform details of application icons.
Design notes
This is a thin binding, deliberately. It stays close to the C API and leaves higher-level conveniences to the caller — in particular, binding arguments and results are exchanged as JSON text, and choosing a JSON library is up to you.
Feedback wanted, especially on Linux
Owebview has been tested on macOS, Windows, Fedora, Ubuntu.
Reports about building and running it on others Linux distributions would be particularly valuable: does it compile, do the depexts resolve, does the webkit2gtk-4.1 backend behave as expected on your distro, and how does the Dock icon story go on your desktop environment? Windows reports are welcome too.
If you are interested in this library, please email me at my address frederic.ln.lang@gmail.com.
- Repository — https://github.com/korkorran/Owebview
- Documentation — https://korkorran.github.io/Owebview
- Issues — https://github.com/korkorran/Owebview/issues
- License — MIT
Special thanks to @Chimrod for his contribution in this release.
Happy hacking!
