package owebview

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Owebview

A thin OCaml binding to webview: open a native window backed by the operating system's web engine, load HTML/CSS/JS, and bridge JavaScript with OCaml — no Electron, no bundler.

Quickstart

A whole application 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 "<h1>Hello from OCaml</h1>";
    Webview.run w;
    Webview.destroy w

Call OCaml from the page and answer the JavaScript promise:

  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)

API

The whole binding is the Webview module. A tour of it:

Native dependencies

webview uses the system web engine, so its native libraries are needed:

  • macOS: WebKit / Cocoa, provided by the system.
  • Linux: gtk+-3.0 and webkit2gtk-4.1 (-dev packages).
  • Windows: the WebView2 runtime (ships with Windows 10/11).

The platform-specific compile and link flags are detected automatically at build time, so there is nothing to tweak by hand.