package owebview

  1. Overview
  2. Docs
OCaml bindings for the webview library

Install

dune-project
 Dependency

Authors

Maintainers

Sources

0.1.0.tar.gz
md5=96958382fcfef04cc489a87b392abd65
sha512=0494c253643890138099fb14023476d4fef95299449c118301461efa0d2e316bf37a326a76bcf8d29512cdb621c144d06deb76ac5e22adeab76f9fae8a443d24

doc/index.html

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.