This version of the module is deprecated: This package is deprecated. moonbit-community/proton should be preferred.

    justjavac/proton/webview does not have a README file

    BindingHandle

    #external
    pub type BindingHandle

    Opaque binding handle returned by the native webview wrapper.

    CStr

    #external
    pub type CStr

    Opaque C string pointer received from the native webview callback.

    NativeHandleKind

    pub(all) enum NativeHandleKind {
    Window
    Widget
    Browser
    } derive(
    Debug
    )

    Native handle kind. The actual type depends on the backend.

    SizeHint

    pub(all) enum SizeHint {
    None
    Min
    Max
    Fixed
    } derive(
    Debug
    )

    Window size hints

    Webview

    type Webview

    An instance of a webview window.

    Example:

    let webview = @webview.Webview::new(debug=1)
    webview.set_title("My Webview")
    webview.set_size(800, 600, @webview.SizeHint::None)
    webview.set_html("<html><body><h1>Hello, World!</h1></body></html>")
    webview.dispatch(fn() { webview.terminate() })
    webview.run()

    Webview::bind

    fn Webview::bind(self : Webview, name : String, callback : (Bytes, Bytes) -> Unit) -> Unit

    Binds a function pointer to a new global JavaScript function.

    Internally, JS glue code is injected to create the JS function by the given name. The callback function is passed a request identifier, a request string and a user-provided argument. The request string is a JSON array of the arguments passed to the JS function.

    Parameters:
    • name - The name of the JavaScript function to bind.
    • callback - The function to be invoked when the JS function is called.
    • arg - An optional user-provided argument passed to the callback function.

    Returns:
    • WEBVIEW_ERROR_DUPLICATE - A binding already exists with the specified name.

    Webview::destroy

    fn Webview::destroy(self : Webview) -> Unit

    Destroys the webview and closes the window. It is safe to call this function from another background thread.

    Webview::dispatch

    fn Webview::dispatch(self : Webview, callback : () -> Unit) -> Unit

    Schedules a function to be invoked on the thread with the run/event loop.

    Since library functions generally do not have thread safety guarantees, this function can be used to schedule code to execute on the main/GUI thread and thereby make that execution safe in multi-threaded applications.

    Parameters:
    • callback - The function to be invoked.
    • arg - An optional argument passed along to the callback function.

    Webview::eval

    fn Webview::eval(self : Webview, js : String) -> Unit

    Evaluates arbitrary JavaScript code.

    Use bindings if you need to communicate the result of the evaluation.

    Parameters:
    • js - The JavaScript code to evaluate.

    Webview::get_handle

    fn Webview::get_handle(self : Webview) -> Webview_t

    Returns the internal webview handle of the webview instance. This handle is the raw pointer used by the compiled native backend.

    Webview::get_native_handle

    fn Webview::get_native_handle(self : Webview, kind : NativeHandleKind) -> Int64

    Get a native handle of choice.

    Parameters:
    • kind - The kind of handle to retrieve.

    Webview::get_window

    fn Webview::get_window(self : Webview) -> Int64

    Returns the native handle of the window associated with the webview instance. The handle can be a GtkWindow pointer (GTK), NSWindow pointer (Cocoa) or HWND (Win32).

    Webview::has_binding

    fn Webview::has_binding(self : Webview, name : String) -> Bool

    Returns whether a JavaScript binding with this name has been installed. Higher-level runtimes can use this to avoid rebinding helper functions under the same global JavaScript name.

    Webview::init

    fn Webview::init(self : Webview, js : String) -> Unit

    Injects JavaScript code to be executed immediately upon loading a page. The code will be executed before window.onload.

    Parameters:
    • js - The JavaScript code to inject.

    Webview::navigate

    fn Webview::navigate(self : Webview, url : String) -> Unit

    Navigates webview to the given URL. URL may be a properly encoded data URI.

    Parameters:
    • url - The URL to navigate to.

    Example:
    let webview = @webview.Webview::new()
    webview.navigate("https://www.example.com")
    webview.navigate("data:text/html,<h1>Hello, World!</h1>")
    webview.navigate("data:text/html;base64,PGgxPkhlbGxvPC9oMT4=")
    webview.dispatch(fn() { webview.terminate() })
    webview.run()

    Webview::new

    fn Webview::new(debug? : Int) -> Webview

    Creates a new webview instance from a webview handle.

    Parameters:
    • debug - If set to 1, enables debugging mode which provides additional logging.

    Webview::register_destroy_hook

    fn Webview::register_destroy_hook(self : Webview, hook_name : String, hook : () -> Unit) -> Unit

    Registers a named callback that will run before the webview is destroyed.

    Hook names must be unique within the webview so internal runtimes and extensions can safely manage their own cleanup handlers.

    Webview::response

    fn Webview::response(self : Webview, id : String, status : Int, result : String) -> Unit

    Responds to a binding call from the JS side.

    This function is safe to call from another thread.

    Parameters:
    • id - The identifier of the binding call. Pass along the value received in the binding handler (see webview.bind()).
    • status - A status of zero tells the JS side that the binding call was successful; any other value indicates an error.
    • result - The result of the binding call to be returned to the JS side. This must either be a valid JSON value or an empty string for the primitive JS value undefined.

    Webview::run

    fn Webview::run(self : Webview) -> Unit

    Runs the main loop until it's terminated. Once the loop exits, the webview destroys itself and executes registered cleanup hooks.

    Webview::runtime_handle_id

    fn Webview::runtime_handle_id(self : Webview) -> Int64

    Returns a stable integer token for the native webview handle.

    This is primarily intended for native runtime integrations that need to refer back to the owning webview from C stubs.

    Webview::set_html

    fn Webview::set_html(self : Webview, html : String) -> Unit

    Load HTML content into the webview.

    Parameters:
    • html - The HTML content to load.

    Example:
    let webview = @webview.Webview::new()
    webview.set_html("<html><body><h1>Hello, World!</h1></body></html>")
    webview.dispatch(fn() { webview.terminate() })
    webview.run()

    Webview::set_size

    fn Webview::set_size(self : Webview, width : Int, height : Int, hints : SizeHint) -> Unit

    Updates the size of the native window.

    Remarks:
    • Using WEBVIEW_HINT_MAX for setting the maximum window size is not supported with GTK 4 because X11-specific functions such as gtk_window_set_geometry_hints were removed. This option has no effect when using GTK 4.
    • GTK 4 can set a default/initial window size if done early enough; otherwise, this function has no effect. GTK 4 (unlike 3) can't resize a window after it has been set up.

    Parameters:
    • width - The new width of the window.
    • height - The new height of the window.
    • hints - Hints for the window size.

    Webview::set_title

    fn Webview::set_title(self : Webview, title : String) -> Unit

    Updates the title of the native window.

    Parameters:
    • title - The new title.

    Webview::terminate

    fn Webview::terminate(self : Webview) -> Unit

    Stops the main event loop. It is safe to call this function from another background thread.

    Webview::unbind

    fn Webview::unbind(self : Webview, name : String) -> Unit

    Removes a binding created with webview.bind().

    Parameters:
    • name - The name of the JavaScript function to unbind.

    Returns:
    • WEBVIEW_ERROR_NOT_FOUND - No binding exists with the specified name.

    Webview::unregister_destroy_hook

    fn Webview::unregister_destroy_hook(self : Webview, hook_name : String) -> Unit

    Removes a previously registered destroy hook by name. Missing hook names are ignored so independent runtimes can unregister defensively during cleanup.

    Webview_t

    #external
    pub type Webview_t

    typedef void *webview_t;

    backend_available

    fn backend_available() -> Bool

    Returns whether the compiled browser backend can create native windows.

    On Windows, install CEF with proton cef setup and build the CEF subprocess helper before creating native windows.

    backend_id

    fn backend_id() -> String

    Returns the compiled browser backend id.

    webview_bind

    fn webview_bind(webview : Webview_t, name : Bytes, call_closure : FuncRef[(CStr, CStr, (Bytes, Bytes) -> Unit) -> Unit], closure : (Bytes, Bytes) -> Unit) -> BindingHandle

    Wrapper around webview_bind that stores the owned MoonBit closure inside an opaque native binding record and returns that record as a handle for later unbind/cleanup.

    webview_create

    fn webview_create(debug : Int, window : Int64) -> Webview_t

    extern webview_t webview_create(int debug, void *window);

    webview_destroy

    fn webview_destroy(webview : Webview_t) -> Int

    extern void webview_destroy(webview_t w);

    webview_dispatch

    fn webview_dispatch(webview : Webview_t, call_closure : FuncRef[(Webview_t, (Webview_t) -> Unit) -> Unit], closure : () -> Unit) -> Int

    extern void webview_dispatch(webview_t w, void (*fn)(webview_t w, void *arg), void *arg);

    webview_eval

    fn webview_eval(webview : Webview_t, js : Bytes) -> Int

    extern void webview_eval(webview_t w, const char *js);

    webview_get_native_handle

    fn webview_get_native_handle(webview : Webview_t, kind : NativeHandleKind) -> Int64

    extern void *webview_get_native_handle(webview_t w, webview_native_handle_kind_t kind);

    webview_get_window

    fn webview_get_window(webview : Webview_t) -> Int64

    extern void *webview_get_window(webview_t w);

    webview_init

    fn webview_init(webview : Webview_t, js : Bytes) -> Int

    extern void webview_init(webview_t w, const char *js);

    webview_navigate

    fn webview_navigate(webview : Webview_t, url : Bytes) -> Int

    extern void webview_navigate(webview_t w, const char *url);

    webview_return

    fn webview_return(webview : Webview_t, seq : Bytes, status : Int, result : Bytes) -> Int

    extern void webview_return(webview_t w, const char *seq, int status, const char *result);

    webview_run

    fn webview_run(webview : Webview_t) -> Int

    extern void webview_run(webview_t w);

    webview_set_html

    fn webview_set_html(webview : Webview_t, html : Bytes) -> Int

    extern void webview_set_html(webview_t w, const char *html);

    webview_set_size

    fn webview_set_size(webview : Webview_t, width : Int, height : Int, hint : SizeHint) -> Int

    extern void webview_set_size(webview_t w, int width, int height, webview_hint_t hints);

    webview_set_title

    fn webview_set_title(webview : Webview_t, title : Bytes) -> Int

    extern void webview_set_title(webview_t w, const char *title);

    webview_terminate

    fn webview_terminate(webview : Webview_t) -> Int

    extern void webview_terminate(webview_t w);

    webview_unbind

    fn webview_unbind(webview : Webview_t, name : Bytes, binding : BindingHandle) -> Int

    Wrapper around webview_unbind that also releases the opaque native binding handle returned by webview_bind.