Hi everyone! ![]()
I’d like to share a small project I’ve been working on: owebview, a set of OCaml bindings for webview.
What is webview?
webview is a tiny, cross-platform library for building desktop GUIs using the operating system’s built-in web engine — WebKit on macOS, WebKitGTK on Linux, and WebView2 on Windows. Instead of shipping a whole browser like Electron, you reuse the system one, so your apps stay small. You create a window, point it at some HTML (or a URL), and you can call back and forth between the page’s JavaScript and your host language.
The gap owebview fills
What makes webview really appealing is its ecosystem: it already has bindings in a lot of languages — Go (the reference one), Rust, Python, C#, Nim, Zig, and many more. As far as I could tell, though, there wasn’t one for OCaml.
owebview is an attempt to fill that gap: a thin binding that lets you drive webview directly from OCaml, with a native bridge between the page’s JavaScript and your OCaml functions.
What it looks like
A complete app is about ten lines:
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.set_html w
{|<!doctype html>
<html><body style="font-family: system-ui; text-align: center">
<h1>Hello from OCaml 👋</h1>
</body></html>|};
Webview.run w;
Webview.destroy w
And you can expose OCaml functions to the page — here window.add(a, b)
returns a JavaScript Promise resolved from OCaml:
Webview.bind w "add" (fun id req ->
let result =
match Scanf.sscanf_opt req "[%d,%d]" (fun a b -> a + b) with
| Some n -> string_of_int n
| None -> "null"
in
Webview.return w id ~error:false ~result)
Try it
# Run the bundled example
git clone https://github.com/korkorran/owebview.git
cd owebview
dune exec examples/hellowv.exe
# Or pin it into your own project
opam pin add owebview https://github.com/korkorran/owebview.git
Then just add (libraries owebview.webview) to your dune file. The webview.h header is vendored, and the platform-specific C++ flags are detected at build time (via pkg-config on Linux), so there’s nothing to wire up by hand.
Honest status & a request
This is a compact binding / starting point, not a complete library yet:
some pieces (unbind, dispatch, full binding memory management) are intentionally left out for now.
It’s also developed and tested mainly on macOS. I’d love feedback from people running it on Linux distributions — does it compile, do the opam depexts resolve, does the webkit2gtk-4.1 backend behave on your distro?
Issues and PRs are very welcome.
Repository: GitHub - korkorran/owebview: Ocaml binding to the webview library · GitHub
Thanks for reading — happy to hear thoughts, suggestions, and especially Linux build reports!
