Home

Awesome

webview-bun

bun bindings for webview

Webview is a tiny cross-platform library to make web-based GUIs for desktop applications.

Installation

Platforms supported:

<details> <summary>Click here for instructions on linux</summary> Install the <a href="https://webkitgtk.org/">webkit</a> dependency.

Debian-based systems:

Fedora-based systems:

Arch-based systems:

yay -S webkit2gtk

</details> <details> <summary>Click here for instructions on windows</summary> Must have the <a href="https://developer.microsoft.com/en-us/microsoft-edge/webview2/">WebView2 runtime</a> installed on the system for any version of Windows before Windows 11. </details>
bun i webview-bun

Example

import { Webview } from "webview-bun";

const html = `
<html>
    <body>
        <h1>Hello from bun v${Bun.version} !</h1>
    </body>
</html>
`;

const webview = new Webview();

webview.setHTML(html);
webview.run();

For more examples, browse the examples folder of this repository.

Single-file executable

You can compile a single self-sufficient executable file for your webview app.

For example, let's create a single executable for the above Todo App. Clone this repository and run,

bun build --compile --minify --sourcemap ./examples/todoapp/app.ts --outfile todoapp

[!TIP]
By default, a terminal window will also open in the back when double-click opening the executable in Windows and macOS.

To hide it in Windows:

Download hidecmd.bat from this repository and save in the same folder as the binary. Open the terminal there and execute,

.\hidecmd.bat todoapp.exe

To hide it in macOS:

Add the extension .app in the end of the above bun build command.

Cross-platform compilation

Bun now supports cross-compilation of single executable binaries. To cross compile your webview app for a different platform run,

bun build --compile --target=bun-windows-x64 --minify --sourcemap ./examples/todoapp/app.ts --outfile todoapp

Supported targets are: bun-linux-x64, bun-windows-x64, bun-darwin-x64, bun-darwin-arm64.

Documentation

Refer to the comments in the source code for full documentation.

Development

[!IMPORTANT]
If you are on Windows, you need C++ Build Tools.

Building

The compiled library file(s) can be found inside the build folder.

Running

[!TIP] To use your own webview library, set the WEBVIEW_PATH environment variable with the path to your webview shared library file.

Run the following example to see it in action.

bun run examples/basic.ts

For more examples, browse the examples folder of this repository.

Important note for Windows users

The libwebview.dll is sometimes detected as a potential malware by the Windows Defender which is a false positive and is safe to restore.

If this concerns you, feel free to compile the library yourself from source using the instructions provided above.

Credits

This repository is a port of webview_deno with various changes to work with the bun runtime and new windows build script to compile the latest webview.

License

This repository uses MIT license. See LICENSE for full license text.