Webview is a tiny cross-platform library to make web-based GUIs for desktop applications.
Platforms supported:
windows-x64
linux-x64
macos-x64
macos-arm64
Click here for instructions on linux
Install the webkit dependency.- Development:
apt install libgtk-3-dev libwebkit2gtk-4.0-dev
- Production:
apt install libgtk-3-0 libwebkit2gtk-4.0-37
- Development:
dnf install gtk3-devel webkit2gtk4.0-devel
- Production:
dnf install gtk3 webkit2gtk4.0
yay -S webkit2gtk
Click here for instructions on windows
Must have the WebView2 runtime installed on the system for any version of Windows before Windows 11.bun i webview-bun
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.
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.
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
Add the extension .app
in the end of the above bun build command.
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
.
Refer to the comments in the source code for full documentation.
Important
If you are on Windows, you need C++ Build Tools.
- Go to https://visualstudio.microsoft.com/downloads.
- Scroll down > All Downloads > Tools for Visual Studio.
- Download Build Tools for Visual Studio 2022 and run.
- Select Desktop development with C++ and install.
-
Clone the repository along with the webview submodule.
git clone --recurse-submodules --remote-submodules https://github.com/tr1ckydev/webview-bun.git cd webview-bun bun i
-
Build the library for your platform.
bun run build
The compiled library file(s) can be found inside the build folder.
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.
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.
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.
This repository uses MIT license. See LICENSE for full license text.