No description
Find a file
XXIV a5eef0bbff
Merge pull request #16 from DownloadableFox/main
Update from deprecrated WebKitGTK dependency to 4.1
2025-12-27 15:59:08 +03:00
.github Update package installation commands in CI workflow 2025-12-27 15:25:40 +03:00
examples add dispatch example 2025-12-06 02:14:12 +03:00
external/WebView2 remove copy of webview in favor of downloading it on the fly 2025-01-21 02:04:25 +03:00
src update api 2025-12-06 02:10:30 +03:00
.gitattributes vendor webview 2023-10-25 14:57:12 +03:00
.gitignore support zig 0.13.0 2024-06-15 17:13:04 +02:00
build.zig now using webkit2gtk4.1 2025-12-26 18:35:47 -05:00
build.zig.zon update zig version to 0.14 2025-07-21 19:17:55 +03:00
LICENSE Initial commit 2023-09-01 16:19:26 +03:00
README.md update api 2025-12-06 02:10:30 +03:00

webview-zig

Zig binding for a tiny cross-platform webview library to build modern cross-platform GUIs.

Requirements

Usage

zig fetch --save https://github.com/thechampagne/webview-zig/archive/refs/heads/main.tar.gz

build.zig.zon:

.{
    .dependencies = .{
        .webview = .{
            .url = "https://github.com/thechampagne/webview-zig/archive/refs/heads/main.tar.gz" ,
          //.hash = "12208586373679a455aa8ef874112c93c1613196f60137878d90ce9d2ae8fb9cd511",
        },
    },
}

build.zig:

const webview = b.dependency("webview", .{
    .target = target,
    .optimize = optimize,
});
exe.root_module.addImport("webview", webview.module("webview"));
exe.linkLibrary(webview.artifact("webviewStatic")); // or "webviewShared" for shared library
// exe.linkSystemLibrary("webview"); to link with installed prebuilt library without building

API

const WebView = struct {

    const WebViewVersionInfo = struct {
        version: struct {
            major: c_uint,
            minor: c_uint,
            patch: c_uint,
        },
        version_number: [32]c_char,
        pre_release: [48]c_char,
        build_metadata: [48]c_char,
    };

    const DispatchCallback = *const fn (?*anyopaque, ?*anyopaque) callconv(.c) void;

    const BindCallback = *const fn ([*:0]const u8, [*:0]const u8, ?*anyopaque) callconv(.c) void;

    const WindowSizeHint = enum(c_uint) {
        none,
        min,
        max,
        fixed
    };

    const NativeHandle = enum(c_uint) {
        ui_window,
        ui_widget,
        browser_controller
    };

    const WebViewError = error {
        MissingDependency,
        Canceled,
        InvalidState,
        InvalidArgument,
        Unspecified,
        Duplicate,
        NotFound,
    };

    fn create(debug: bool, window: ?*anyopaque) WebView;

    fn run(self: WebView) WebViewError!void;

    fn terminate(self: WebView) WebViewError!void;
    
    fn dispatch(self: WebView, func: DispatchCallback, arg: ?*anyopaque) WebViewError!void;
    
    fn getWindow(self: WebView) ?*anyopaque;

    fn getNativeHandle(self: WebView, kind: NativeHandle) ?*anyopaque;
    
    fn setTitle(self: WebView, title: [:0]const u8) WebViewError!void;
    
    fn setSize(self: WebView, width: i32, height: i32, hint: WindowSizeHint) WebViewError!void;
    
    fn navigate(self: WebView, url: [:0]const u8) WebViewError!void;
    
    fn setHtml(self: WebView, html: [:0]const u8) WebViewError!void;
    
    fn init(self: WebView, js: [:0]const u8) WebViewError!void;
    
    fn eval(self: WebView, js: [:0]const u8) WebViewError!void;
    
    fn bind(self: WebView, name: [:0]const u8, func: BindCallback, arg: ?*anyopaque) WebViewError!void;
    
    fn unbind(self: WebView, name: [:0]const u8) WebViewError!void;
    
    fn ret(self: WebView ,seq: [:0]const u8, status: i32, result: [:0]const u8) WebViewError!void;
    
    fn version() *const WebViewVersionInfo;

    fn destroy(self: WebView) WebViewError!void;
}

References

License

This repo is released under the MIT License.

Third party code: