|
webview 0.12.0
A tiny cross-platform webview library for C/C++ to build modern cross-platform GUIs.
|
A tiny cross-platform webview library for C/C++ to build modern cross-platform GUIs.
The goal of the project is to create a common HTML5 UI abstraction layer for the most widely used platforms.
It supports two-way JavaScript bindings (to call JavaScript from C/C++ and to call C/C++ from JavaScript).
| Platform | Technologies |
|---|---|
| Linux | GTK, WebKitGTK |
| macOS | Cocoa, WebKit |
| Windows | Windows API, WebView2 |
The most up-to-date documentation is right in the source code. Improving the documentation is a continuous effort and you are more than welcome to contribute.
Your compiler must support minimum C++11 except for platforms that require a more modern version.
This project uses CMake and Ninja, and while recommended for your convenience, these tools aren't required for using the library.
The GTK and WebKitGTK libraries are required for development and distribution. You need to check your package repositories regarding which packages to install.
Your compiler must support C++14 and we recommend to pair it with an up-to-date Windows 10 SDK.
For Visual C++ we recommend Visual Studio 2022 or later. There are some requirements when using MinGW-w64.
Developers and end-users must have the WebView2 runtime installed on their system for any version of Windows before Windows 11.
If you are a developer of this project then please go to the development section.
You will have a working app, but you are encouraged to explore the available examples.
Create the following files in a new directory:
.gitignore:
CMakeLists.txt:
main.cc:
CMakeLists.txt:
main.c:
Build the project:
Find the executable in the build/bin directory.
The following CMake targets are available:
| Name | Description |
|---|---|
| webview::core | Headers for C++. |
| webview::core_shared | Shared library for C. |
| webview::core_static | Static library for C. |
Special targets for on-demand checks and related tasks:
| Name | Description |
|---|---|
| webview_format_check | Check files with clang-format. |
| webview_reformat | Reformat files with clang-format. |
The following boolean options can be used when building the webview project standalone or when building it as part of your project (e.g. with FetchContent).
| Option | Description |
|---|---|
| WEBVIEW_BUILD | Enable building |
| WEBVIEW_BUILD_DOCS | Build documentation |
| WEBVIEW_BUILD_EXAMPLES | Build examples |
| WEBVIEW_BUILD_SHARED_LIBRARY | Build shared libraries |
| WEBVIEW_BUILD_STATIC_LIBRARY | Build static libraries |
| WEBVIEW_BUILD_TESTS | Build tests |
| WEBVIEW_ENABLE_CHECKS | Enable checks |
| WEBVIEW_ENABLE_CLANG_FORMAT | Enable clang-format |
| WEBVIEW_ENABLE_CLANG_TIDY | Enable clang-tidy |
| WEBVIEW_ENABLE_PACKAGING | Enable packaging |
| WEBVIEW_INSTALL_DOCS | Install documentation |
| WEBVIEW_INSTALL_TARGETS | Install targets |
| WEBVIEW_IS_CI | Initialized by the CI environment variable |
| WEBVIEW_STRICT_CHECKS | Make checks strict |
| WEBVIEW_STRICT_CLANG_FORMAT | Make clang-format check strict |
| WEBVIEW_STRICT_CLANG_TIDY | Make clang-tidy check strict |
| WEBVIEW_USE_COMPAT_MINGW | Use compatibility helper for MinGW |
| WEBVIEW_USE_STATIC_MSVC_RUNTIME | Use static runtime library (MSVC) |
Non-boolean options:
| Option | Description |
|---|---|
| WEBVIEW_CLANG_FORMAT_EXE | Path of the clang-format executable. |
| WEBVIEW_CLANG_TIDY_EXE | Path of the clang-tidy executable. |
These options can be used when when using the webview CMake package.
| Option | Description |
|---|---|
| WEBVIEW_WEBKITGTK_API | WebKitGTK API to interface with, e.g. 6.0, 4.1 (recommended) or 4.0. This will also automatically decide the GTK version. Uses the latest recommended API by default if available, or the latest known and available API. Note that there can be major differences between API versions that can affect feature availability. See webview API documentation for details on feature availability. |
| Option | Description |
|---|---|
| WEBVIEW_MSWEBVIEW2_VERSION | MS WebView2 version, e.g. 1.0.1150.38. |
| WEBVIEW_USE_BUILTIN_MSWEBVIEW2 | Use built-in MS WebView2. |
These options can be specified as preprocessor macros to modify the build, but are not needed when using CMake.
| Name | Description |
|---|---|
| WEBVIEW_API | Controls C API linkage, symbol visibility and whether it's a shared library. By default this is inline for C++ and extern for C. |
| WEBVIEW_BUILD_SHARED | Modifies WEBVIEW_API for building a shared library. |
| WEBVIEW_SHARED | Modifies WEBVIEW_API for using a shared library. |
| WEBVIEW_STATIC | Modifies WEBVIEW_API for building or using a static library. |
| Name | Description |
|---|---|
| WEBVIEW_GTK | Compile the GTK/WebKitGTK backend. |
| WEBVIEW_COCOA | Compile the Cocoa/WebKit backend. |
| WEBVIEW_EDGE | Compile the Win32/WebView2 backend. |
| Option | Description |
|---|---|
| WEBVIEW_MSWEBVIEW2_BUILTIN_IMPL | Enables (1) or disables (0) the built-in implementation of the WebView2 loader. Enabling this avoids the need for WebView2Loader.dll but if the DLL is present then the DLL takes priority. This option is enabled by default. |
| WEBVIEW_MSWEBVIEW2_EXPLICIT_LINK | Enables (1) or disables (0) explicit linking of WebView2Loader.dll. Enabling this avoids the need for import libraries (*.lib). This option is enabled by default if WEBVIEW_MSWEBVIEW2_BUILTIN_IMPL is enabled. |
In order to build this library using MinGW-w64 on Windows then it must support C++14 and have an up-to-date Windows SDK.
Distributions that are known to be compatible:
Linking the WebView2 loader part of the Microsoft WebView2 SDK is not a hard requirement when using our webview library, and neither is distributing WebView2Loader.dll with your app.
If, however, WebView2Loader.dll is loadable at runtime, e.g. from the executable's directory, then it will be used; otherwise our minimalistic implementation will be used instead.
Should you wish to use the official loader then remember to distribute it along with your app unless you link it statically. Linking it statically is possible with Visual C++ but not MinGW-w64.
Here are some of the noteworthy ways our implementation of the loader differs from the official implementation:
Customization options can be used to change how the library integrates the WebView2 loader.
This project uses the CMake build system.
In addition to the dependencies mentioned earlier in this document for developing with the webview library, the following are used during development of the webview library.
Replace CONFIG with one of Debug, Release, or Profile. Use Profile to enable code coverage (GCC/Clang).
Run tests:
Generate test coverage report:
Find the coverage report in build/coverage.
Run this after building the Debug and Release configs of the project:
See CMake toolchain files in the cmake/toolchains directory.
For example, this targets Windows x64 on Linux with POSIX threads:
Since a browser engine is not a full web browser it may not support every feature you may expect from a browser. If you find that a feature does not work as expected then please consult with the browser engine's documentation and open an issue if you think that the library should support it.
For example, the library does not attempt to support user interaction features like alert(), confirm() and prompt() and other non-essential features like console.log().
| Language | Project |
|---|---|
| Ada | thechampagne/webview-ada |
| Bun | tr1ckydev/webview-bun |
| C# | webview/webview_csharp |
| C3 | thechampagne/webview-c3 |
| Crystal | naqvis/webview |
| D | thechampagne/webview-d |
| Deno | webview/webview_deno |
| Go | webview/webview_go |
| Harbour | EricLendvai/Harbour_WebView |
| Haskell | lettier/webviewhs |
| Janet | janet-lang/webview |
| Java | webview/webview_java |
| Kotlin | Winterreisender/webviewko |
| Nim | oskca/webview, neroist/webview |
| Node.js | Winterreisender/webview-nodejs |
| Odin | thechampagne/webview-odin |
| Pascal | PierceNg/fpwebview |
| Python | zserge/webview-python |
| PHP | 0hr/php-webview |
| Ruby | Maaarcocr/webview_ruby |
| Rust | Boscop/web-view |
| Swift | jakenvac/SwiftWebview |
| V | malisipi/mui, ttytm/webview |
| Zig | thechampagne/webview-zig |
If you wish to add bindings to the list, feel free to submit a pull request or open an issue.
You can generate bindings for the library by yourself using the included SWIG interface (webview.i).
Here are some examples to get you started. Unix-style command lines are used for conciseness.
Code is distributed under MIT license, feel free to use it in your proprietary projects as well.