https://github.com/michaelkim/webview
Cross-platform header-only webview library for C++
https://github.com/michaelkim/webview
cpp webview
Last synced: 11 months ago
JSON representation
Cross-platform header-only webview library for C++
- Host: GitHub
- URL: https://github.com/michaelkim/webview
- Owner: MichaelKim
- License: mit
- Created: 2019-06-07T06:58:22.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2021-10-17T07:22:48.000Z (over 4 years ago)
- Last Synced: 2025-03-31T07:22:21.565Z (12 months ago)
- Topics: cpp, webview
- Language: C++
- Homepage:
- Size: 345 KB
- Stars: 71
- Watchers: 2
- Forks: 10
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# webview
[](https://github.com/MichaelKim/webview/actions/workflows/ci.yaml)
A tiny cross-platform webview library written in C++ using Edge on Windows (both EdgeHTML and Chromium), Webkit on MacOS, and WebkitGTK on Linux.
Inspired from zerge's [webview](https://github.com/webview/webview), this library was rewritten with several priorities:
- A more "C++"-like API
- Support for Microsoft Edge on Windows
- Replaced Objective-C runtime C code with actual Objective-C code
## Support
| | Windows | Windows | MacOS | Linux |
| ---------- | ------------------ | ------------------ | -------------------------------- | ----------------------------- |
| Version | Windows 10, v1809+ | Windows 7, 8.1, 10 | Tested on MacOS Mojave, Catalina | Tested on Ubuntu 18.04.02 LTS |
| Web Engine | EdgeHTML | Chromium | Webkit | WebKit |
| GUI | Windows API | Windows API | Cocoa | GTK |
## Documentation
- [Build Steps](docs/build.md)
- [API Reference](docs/api.md)
- [Limitations](docs/limitations.md)
## Usage
```c++
#include "webview.h"
WEBVIEW_MAIN {
// Create a 800 x 600 webview that shows Google
wv::WebView w{800, 600, true, true, Str("Hello world!"), Str("http://google.com")};
if (w.init() == -1) {
return 1;
}
while (w.run() == 0);
return 0;
}
```
Since Windows (WinAPI) uses `std::wstring`s, all string literals should be wrapped in the macro `Str(s)`.
The following URL schemes are supported:
- HTTP(S): `http://` and `https://`
- Local file: `file:///`, make sure to point to an `html` file
- Not supported in Edge Legacy (see [Limitations](docs/limitations.md))
- Inline data: `data:text/html,...`
Check out example programs in the [`examples/`](examples/) directory in this repo.
Note: `WEBVIEW_MAIN` is a macro that resolves to the correct entry point:
```c++
#ifdef WEBVIEW_WIN
#define WEBVIEW_MAIN int __stdcall WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
#else
#define WEBVIEW_MAIN int main(int, char **)
#endif
```
This is needed since Win32 GUI applications uses `WinMain` as the entry point rather than the standard `main`. You can write your own main for more control, but make sure to use `WinMain` if you need to support Windows.