An embedded web rendering engine.
Powered by webview. All the power of web technologies in your app. No Electron, no bundler: create a window, drop in some HTML, and you have an app.
| Rainfall (D3.js) | Geometry shapes (three.js) | Timer |
![]() |
![]() |
![]() |
dune exec examples/d3/d3.exe |
dune exec examples/three/three.exe |
dune exec examples/timer/timer_posix.exe |
A complete app demonstrating Owebview feature : Sun notes. Packages for Debian, Fedora, macOS, Windows available for download.
Please refer to the tutorial
You can also check the documentation
Build a tiny native desktop window with a web UI, straight from OCaml —
Here's the whole thing:
let () =
let w = Webview.create () in
Webview.set_title w "My first owebview app";
Webview.set_size w ~width:480 ~height:320 Webview.Hint_none;
Webview.bind w "random" (fun id req ->
Printf.printf "binding called <random>: id=%s req=%s\n%!" id req;
let result = string_of_int (Random.int 100)
in
Webview.return w id ~error:false ~result);
Webview.set_html w
{|<!doctype html>
<html>
<body style="font-family: system-ui; text-align: center">
<h1>Hello from OCaml 👋</h1>
<p>Click the button to get a random number:</p>
<button id="btn">Get random number</button>
<p id="result"></p>
<script>
const btn = document.getElementById("btn");
const result = document.getElementById("result");
btn.addEventListener("click", () => {
window.random().then((n) => {
result.textContent = `Random number: ${n}`;
});
});
</script>
</body>
</html>|};
Webview.run w;
Webview.destroy wOnce HTML rendering works, the fun part is the OCaml ↔ JavaScript bridge: Webview.bind w random (...) expose window.random() to the page; the result is a JS Promise. All the computation of random numbers is done by the OCaml back-end. While random number generation can be done in JavaScript, it gives an example of how to call native functions from the window.
If your machine is on Windows, you must install the Microsoft Webview2 package before any OPAM installation, :
nuget install Microsoft.Web.WebView2Otherwise, on unix system, all the dependancies are installed via OPAM.
opam install owebviewThen depend on it from your dune file:
(executable
(name main)
(libraries owebview owebview.desktop))The Owebview package is divided in two seperate libraries :
Webview, which contains webview lifecycle functions.owebview.desktop the companion library for the native desktop integration, in the Webview_desktop module.
Webview_desktop.Locate_assets : locating your on-disk assets (finds your web/ directory relative to the executable, whatever the working directory — beside the binary in a build tree or a platform package, in <prefix>/share/<package> after an opam install),Webview_desktop.Icon : setting a dock icon in a dev environnement (can be ignored in production releases)Webview_desktop.Dialog : the system's own modal dialogsWebview_desktop.Menu : the application window native menuClone the repo and launch one of the bundled example, for instance hellowv:
git clone https://github.com/korkorran/Owebview.git
cd Owebview
nuget install Microsoft.Web.WebView2 # on windows only
opam install . --deps-onlydune build
dune exec examples/hellowv/hellowv.exe # a basic application
dune exec examples/timer/timer_posix.exe # a timer with threads
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
opam install brr # you will need brr to compile this example
dune build
dune exec examples/hellowv_ml/hellowv.exe # full OCaml applicationYou can see the full list in the examples/ folder.
webview uses the system web engine, so you need its native libraries:
gtk+-3.0 and webkit2gtk-4.1 (the -dev packages). They come from the conf-gtk3-webkit opam package, so opam install will offer to install them for your distribution.nuget install Microsoft.Web.WebView2) and the WebView2.h header is picked up automatically from the NuGet cache (or set MICROSOFT_WEB_WEBVIEW2 to the package directory). At run time the WebView2 Runtime must be present — it ships with Windows 10/11.The platform-specific compile/link flags are detected automatically at build time — via pkg-config on Linux, and from the NuGet cache on Windows — so there's nothing to tweak by hand.
Feedback is very welcome! Reports about building and running it on Linux distributions are especially valuable.
If you give it a try on Linux, please open an issue with your distribution, what worked and what didn't (build logs welcome). Pull requests improving cross-platform support are happily accepted.
MIT.