Giter VIP home page Giter VIP logo

webview's Introduction

webview

Discord Build Status

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).

Note

Language binding for Go has moved. Versions <= 0.1.1 are available in this repository.

Platform Support

Platform Technologies
Linux GTK 3, WebKitGTK
macOS Cocoa, WebKit
Windows Windows API, WebView2

Documentation

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.

Prerequisites

Your compiler must support minimum C++11 except for platforms that require a more modern version.

Linux and BSD

The GTK and WebKit2GTK libraries are required for development and distribution. You need to check your package repositories regarding how to install those those.

Debian-based systems:

  • Packages:
    • Development: apt install libgtk-3-dev libwebkit2gtk-4.0-dev
    • Production: apt install libgtk-3-0 libwebkit2gtk-4.0-37

Fedora-based systems:

  • Packages:
    • Development: dnf install gtk3-devel webkit2gtk4.0-devel
    • Production: dnf install gtk3 webkit2gtk4.0

BSD-based systems:

  • FreeBSD packages: pkg install webkit2-gtk3
  • Execution on BSD-based systems may require adding the wxallowed option (see mount(8)) to your fstab to bypass W^X memory protection for your executable. Please see if it works without disabling this security feature first.

Windows

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. We have a separate section for MinGW-w64.

Developers and end-users must have the WebView2 runtime installed on their system for any version of Windows before Windows 11.

Getting Started

If you are a developer of this project then please go to the development section.

Instructions here are written for GCC when compiling C/C++ code using Unix-style command lines, and assumes that multiple commands are executed in the same shell session. Command lines for Windows use syntax specific to the Command shell but you can use any shell such as PowerShell as long as you adapt the commands accordingly. See the MinGW-w64 requirements when building on Windows.

You will have a working app but you are encouraged to explore the available examples and try the ones that go beyond the mere basics.

Start with creating a new directory structure for your project:

mkdir my-project && cd my-project
mkdir build libs "libs/webview"

Windows Preparation

The WebView2 SDK is required when compiling programs:

mkdir libs\webview2
curl -sSL "https://www.nuget.org/api/v2/package/Microsoft.Web.WebView2" | tar -xf - -C libs\webview2

If you wish to use the official WebView2 loader (WebView2Loader.dll) then grab a copy of the DLL (replace x64 with your target architecture):

copy /Y libs\webview2\build\native\x64\WebView2Loader.dll build

Note: See the WebView2 loader section for more options.

C/C++ Preparation

Fetch the webview library:

curl -sSLo "libs/webview/webview.h" "https://raw.githubusercontent.com/webview/webview/master/webview.h"
curl -sSLo "libs/webview/webview.cc" "https://raw.githubusercontent.com/webview/webview/master/webview.cc"

Getting Started with C++

Save the basic C++ example into your project directory:

curl -sSLo basic.cc "https://raw.githubusercontent.com/webview/webview/master/examples/basic.cc"

Build and run the example:

# Linux
g++ basic.cc -std=c++11 -Ilibs/webview $(pkg-config --cflags --libs gtk+-3.0 webkit2gtk-4.0) -o build/basic && ./build/basic
# macOS
g++ basic.cc -std=c++11 -Ilibs/webview -framework WebKit -o build/basic && ./build/basic
# Windows/MinGW
g++ basic.cc -std=c++14 -mwindows -Ilibs/webview -Ilibs/webview2/build/native/include -ladvapi32 -lole32 -lshell32 -lshlwapi -luser32 -lversion -o build/basic.exe && "build/basic.exe"

Bonus for Visual C++

Build a C++ example:

cl basic.cc /std:c++14 /EHsc /Fobuild\ ^
    /I libs\webview ^
    /I libs\webview2\build\native\include ^
    /link /OUT:build\basic.exe

Getting Started with C

Save the basic C example into your project directory:

curl -sSLo basic.c "https://raw.githubusercontent.com/webview/webview/master/examples/basic.c"

Build the library and example, then run it:

# Linux
g++ -c libs/webview/webview.cc -std=c++11 -DWEBVIEW_STATIC $(pkg-config --cflags gtk+-3.0 webkit2gtk-4.0) -o build/webview.o
gcc -c basic.c -std=c99 -Ilibs/webview -o build/basic.o
g++ build/basic.o build/webview.o $(pkg-config --libs gtk+-3.0 webkit2gtk-4.0) -o build/basic && build/basic
# macOS
g++ -c libs/webview/webview.cc -std=c++11 -DWEBVIEW_STATIC -o build/webview.o
gcc -c basic.c -std=c99 -Ilibs/webview -o build/basic.o
g++ build/basic.o build/webview.o -framework WebKit -o build/basic && build/basic
# Windows/MinGW
g++ -c libs/webview/webview.cc -std=c++14 -DWEBVIEW_STATIC -Ilibs/webview2/build/native/include -o build/webview.o
gcc -c basic.c -std=c99 -Ilibs/webview -o build/basic.o
g++ build/basic.o build/webview.o -mwindows -ladvapi32 -lole32 -lshell32 -lshlwapi -luser32 -lversion -o build/basic.exe && "build/basic.exe"

Bonus for Visual C++

Build a shared library:

cl libs\webview\webview.cc /std:c++14 /EHsc /Fobuild\ ^
    /D WEBVIEW_BUILD_SHARED ^
    /I libs\webview ^
    /I libs\webview2\build\native\include ^
    /link /DLL /OUT:build\webview.dll

Build a C example using the shared library:

cl basic.c build\webview.lib /EHsc /Fobuild\ ^
    /D WEBVIEW_SHARED ^
    /I libs\webview ^
    /link /OUT:build\basic.exe

More Examples

The examples shown here are mere pieces of a bigger picture so we encourage you to try other examples and explore on your own—you can follow the same procedure. Please get in touch if you find any issues.

Compile-time Options

C API Linkage

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.

App Distribution

Distribution of your app is outside the scope of this library but we can give some pointers for you to explore.

macOS Application Bundle

On macOS you would typically create a bundle for your app with an icon and proper metadata.

A minimalistic bundle typically has the following directory structure:

example.app                 bundle
└── Contents
    ├── Info.plist          information property list
    ├── MacOS
    |   └── example         executable
    └── Resources
        └── example.icns    icon

Read more about the structure of bundles at the Apple Developer site.

Tip: The png2icns tool can create icns files from PNG files. See the icnsutils package for Debian-based systems.

Windows Apps

You would typically create a resource script file (*.rc) with information about the app as well as an icon. Since you should have MinGW-w64 readily available then you can compile the file using windres and link it into your program. If you instead use Visual C++ then look into the Windows Resource Compiler.

The directory structure could look like this:

my-project/
├── icons/
|   ├── application.ico
|   └── window.ico
├── basic.cc
└── resources.rc

resources.rc:

100 ICON "icons\\application.ico"
32512 ICON "icons\\window.ico"

Note: The ID of the icon resource to be used for the window must be 32512 (IDI_APPLICATION).

Compile:

windres -o build/resources.o resources.rc
g++ basic.cc build/resources.o [...]

Remember to bundle the DLLs you have not linked statically, e.g. those from MinGW-w64 and optionally WebView2Loader.dll.

MinGW-w64 Requirements

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:

MS WebView2 Loader

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:

  • Does not support configuring WebView2 using environment variables such as WEBVIEW2_BROWSER_EXECUTABLE_FOLDER.
  • Microsoft Edge Insider (preview) channels are not supported.

The following compile-time options can be used to change how the library integrates the WebView2 loader:

  • WEBVIEW_MSWEBVIEW2_BUILTIN_IMPL=<1|0> - Enables or disables 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=<1|0> - Enables or disables 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.

Development

To build the library, examples and run tests, use one of the builds scripts in the script directory:

  • build.sh:

    • On Unix-based systems.
    • On Windows in a Unix-like environment such as MSYS2.
  • build.bat:

    • On Windows when building with Visual C++.

You can specify individual tasks on the command line for these scripts:

Task Description
info Displays information.
clean Cleans the build directory.
format Reformats code.
deps Fetches dependencies.
check Runs checks.
build Builds the library, examples and tests.
test Runs tests.

Additionally, the scripts accept the following environment variables.

Both scripts:

Variable Description
CI Changes behavior in CI environments (more strict).
TARGET_ARCH Target architecture for cross-compilation (x64, x86).
BUILD_DIR Overrides the path of the build directory.

Only build.sh:

Variable Description
HOST_OS Host operating system (linux, macos, windows).
TARGET_OS Target operating system for cross-compilation (see HOST_OS).
CC C compiler executable.
CXX C++ compiler executable.
LIB_PREFIX Library name prefix.
PKGCONFIG Alternative pkgconfig executable.

Cross-compilation

See the CI configuration for examples.

Limitations

Browser Features

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().

Bindings

Language Project
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.

Generating Bindings

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.

mkdir -p build/bindings/{python,csharp,java,ruby}
swig -c++ -python -outdir build/bindings/python -o build/bindings/python/python_wrap.cpp webview.i
swig -c++ -csharp -outdir build/bindings/csharp -o build/bindings/csharp/csharp_wrap.cpp webview.i
swig -c++ -java -outdir build/bindings/java -o build/bindings/java/java_wrap.cpp webview.i
swig -c++ -ruby -outdir build/bindings/ruby -o build/bindings/ruby/ruby_wrap.cpp webview.i

License

Code is distributed under MIT license, feel free to use it in your proprietary projects as well.

webview's People

Contributors

1l0 avatar abemedia avatar andrewarrow avatar bengtan avatar dandeto avatar fantaisie-software avatar geaz avatar gitter-badger avatar jakenvac avatar jslegendre avatar justjosias avatar nothingismagick avatar petabyt avatar pierre-felber avatar programmerino avatar r32 avatar raff avatar rajivshah3 avatar richardhozak avatar runeimp avatar shannah avatar shivaprsd avatar silversquirl avatar steffenl avatar tcb13 avatar thechampagne avatar timgates42 avatar ttytm avatar winterreisender avatar zserge avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

webview's Issues

Hide terminal window for Golang apps when launched from Finder in OSX

At the moment the exe build opens and terminal and then opens the webview window.

This shoudl work but does not.


cd /Users/apple/workspace/go/src/github.com/zserge/webview/examples/minimal-go && go build -ldflags "-H=windowsgui" main.go

/usr/local/opt/go/libexec/pkg/tool/darwin_amd64/link: running clang failed: exit status 1
ld: unknown option: -T
clang: error: linker command failed with exit code 1 (use -v to see invocation)

If anyone has ideas would be great..

I am also working on packaging of installers... There are a few libs for golang that do this for you well..

Error compiling CXX on windows

Hi, I get error compiling timer-cxx sample with both CMake or Mingw on Windows 10.
Tried also extern "C" for webview.h header

What else can i try?

Support CSS3/HTML5 Animations

I'm not sure if this is possible in webview or not, or if I'm simply doing it wrong... I'm trying to open a webview and do some type of loading animation (HTML5/CSS). I have this in my main.go (and the base.css file loaded via go-bindata. I don't get any errors, but nothing seems to happen in the webview when launched. The HTML/CSS3 combination does work when plopped into files on disk and loaded into a browser.

main.go
func main() { w := webview.New(webview.Settings{ Title: "Loading...", URL: data:text/html,

`,
})
defer w.Exit()

w.Dispatch(func() {
    w.InjectCSS(string(MustAsset("js/base.css")))
})
w.Run()

}`

I've omitted assets.go since it was generated by go-bindata, but base.css is in the js/ folder relative to main.go and does seem to load properly.

`#loader-wrapper {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 1000;
}
#loader {
display: block;
position: relative;
left: 50%;
top: 50%;
width: 150px;
height: 150px;
margin: -75px 0 0 -75px;
border-radius: 50%;
border: 3px solid transparent;
border-top-color: #3498db;
-webkit-animation: spin 2s linear infinite; /* Chrome, Opera 15+, Safari 5+ /
animation: spin 2s linear infinite; /
Chrome, Firefox 16+, IE 10+, Opera */
}

#loader:before {
content: "";
position: absolute;
top: 5px;
left: 5px;
right: 5px;
bottom: 5px;
border-radius: 50%;
border: 3px solid transparent;
border-top-color: #e74c3c;
-webkit-animation: spin 3s linear infinite; /* Chrome, Opera 15+, Safari 5+ /
animation: spin 3s linear infinite; /
Chrome, Firefox 16+, IE 10+, Opera */
}

#loader:after {
content: "";
position: absolute;
top: 15px;
left: 15px;
right: 15px;
bottom: 15px;
border-radius: 50%;
border: 3px solid transparent;
border-top-color: #f9c922;
-webkit-animation: spin 1.5s linear infinite; /* Chrome, Opera 15+, Safari 5+ /
animation: spin 1.5s linear infinite; /
Chrome, Firefox 16+, IE 10+, Opera */
}

@-webkit-keyframes spin {
0% {
-webkit-transform: rotate(0deg); /* Chrome, Opera 15+, Safari 3.1+ /
-ms-transform: rotate(0deg); /
IE 9 /
transform: rotate(0deg); /
Firefox 16+, IE 10+, Opera /
}
100% {
-webkit-transform: rotate(360deg); /
Chrome, Opera 15+, Safari 3.1+ /
-ms-transform: rotate(360deg); /
IE 9 /
transform: rotate(360deg); /
Firefox 16+, IE 10+, Opera /
}
}
@Keyframes spin {
0% {
-webkit-transform: rotate(0deg); /
Chrome, Opera 15+, Safari 3.1+ /
-ms-transform: rotate(0deg); /
IE 9 /
transform: rotate(0deg); /
Firefox 16+, IE 10+, Opera /
}
100% {
-webkit-transform: rotate(360deg); /
Chrome, Opera 15+, Safari 3.1+ /
-ms-transform: rotate(360deg); /
IE 9 /
transform: rotate(360deg); /
Firefox 16+, IE 10+, Opera */
}
}`

Could I simply be missing the proper browser detection? Or, does webview simply not support animation? If it doesn't support animation, consider this a feature request. :)

tray ?

I was wondering is there is a possibility to support the Tray Like Electorn does ?

Here are 3 screen shots of the google drive tray as an example of what i am trying to do.
It seems to use some native and then some html (stage 3)

stage1

stage2

stage3

How to embed resources other than HTML/CSS/JS?

For most developers that would be a very relevant question -- how can one embed graphics into the application using this library?

I presume I could just base64 encode and use data-uri, but that looks like a terrible approach to me.

Some libraries I've seen offer a tiny tool that reads files and outputs a .c or .go with a binary content of that file in exported variable, so that these resources could be easily embedded into the app.

Is it possible to be done currently in this lib? Or could it be easily implemented?

Error with go get "github.com/zserge/webview"

Go version: go1.9.2 windows/amd64
gcc (GCC) 4.8.3

I am try to get the webview src using go get "github.com/zserge/webview". Running this gives the below error, could you please advise on how to resolve this?

# github.com/zserge/webview
cc1.exe: sorry, unimplemented: 64-bit mode not compiled in

How to get current URL of a webview.WebView instance

Let's say I opened a webview.WebView instance by calling webview.New and passing to it a webview.Settings instance with URL property set to https://youtube.com. This opens a new window where the user can browse youtube.

Now I need to get alerted in my Go code every time the user navigates to a different url (preferrably within youtube.com). The webview.WebView does not expose any CurrentURL property or a OnLocationChanged callback mechanism which I can use to do this.

Is there any way to achieve this?

Compiling needs more info on deps

Could you provide additional information on how to get dependencies? I've never done a lot with C, but I've been programming a while, so if I'm missing something basic that should be apparent, please let me know what to look into.

I copied the c example into a folder with just main.c, webview.h, and MakeFile, and I changed the two relative paths from the MakeFile to be correct for being in the same folder, but I got the error:

C:\Source\Go\src\github.com\PaluMacil\misc\c-webview [master ≡]> make example
cc -std=c99 -Wall -Wextra -pedantic -DWEBVIEW_WINAPI=1 main.c  -lole32 -lcomctl32 -loleaut32 -luuid -mwindows -o example
process_begin: CreateProcess(NULL, cc -std=c99 -Wall -Wextra -pedantic -DWEBVIEW_WINAPI=1 main.c -lole32 -lcomctl32 -loleaut32 -luuid -mwindows -o ex
ample, ...) failed.
make (e=2): The system cannot find the file specified.
make: *** [example] Error 2

Then I looked at the Go file and the cgo flags for a hint, and tried out some additional MakeFile values as follows:

# CFLAGS ?= -std=c99 -Wall -Wextra -pedantic
CC = gcc
CFLAGS = -DWEBVIEW_WINAPI=1
LDFLAGS = -lole32 -lcomctl32 -loleaut32 -luuid -mwindows

ifeq ($(OS),Windows_NT)
	WEBVIEW_CFLAGS := -DWEBVIEW_WINAPI=1
	WEBVIEW_LDFLAGS := -lole32 -lcomctl32 -loleaut32 -luuid -mwindows
else ifeq ($(shell uname -s),Linux)
	WEBVIEW_CFLAGS := -DWEBVIEW_GTK=1 $(shell pkg-config --cflags gtk+-3.0 webkitgtk-3.0)
	WEBVIEW_LDFLAGS := $(shell pkg-config --libs gtk+-3.0 webkitgtk-3.0)
else ifeq ($(shell uname -s),Darwin)
	WEBVIEW_CFLAGS := -DWEBVIEW_COCOA=1 -x objective-c
	WEBVIEW_LDFLAGS := -framework Cocoa -framework WebKit
endif

example: main.c webview.h
	$(CC) $(CFLAGS) $(WEBVIEW_CFLAGS) main.c $(LDFLAGS) $(WEBVIEW_LDFLAGS) -o $@

My error now mentions other problems:

gcc -DWEBVIEW_WINAPI=1 -DWEBVIEW_WINAPI=1 main.c -lole32 -lcomctl32 -loleaut32 -luuid -mwindows -lole32 -lcomctl32 -loleaut32 -luuid -mwindows -o exa
mple
In file included from main.c:6:0:
webview.h:377:26: warning: initialization from incompatible pointer type [-Wincompatible-pointer-types]
     Site_QueryInterface, Site_AddRef,       Site_Release,
                          ^~~~~~~~~~~
webview.h:377:26: note: (near initialization for 'MyIOleClientSiteTable.AddRef')
webview.h:377:45: warning: initialization from incompatible pointer type [-Wincompatible-pointer-types]
     Site_QueryInterface, Site_AddRef,       Site_Release,
                                             ^~~~~~~~~~~~
webview.h:377:45: note: (near initialization for 'MyIOleClientSiteTable.Release')
webview.h:382:5: warning: initialization from incompatible pointer type [-Wincompatible-pointer-types]
     InPlace_AddRef,
     ^~~~~~~~~~~~~~
webview.h:382:5: note: (near initialization for 'MyIOleInPlaceSiteTable.AddRef')
webview.h:383:5: warning: initialization from incompatible pointer type [-Wincompatible-pointer-types]
     InPlace_Release,
     ^~~~~~~~~~~~~~~
webview.h:383:5: note: (near initialization for 'MyIOleInPlaceSiteTable.Release')
webview.h:399:5: warning: initialization from incompatible pointer type [-Wincompatible-pointer-types]
     Frame_AddRef,
     ^~~~~~~~~~~~
webview.h:399:5: note: (near initialization for 'MyIOleInPlaceFrameTable.AddRef')
webview.h:400:5: warning: initialization from incompatible pointer type [-Wincompatible-pointer-types]
     Frame_Release,
     ^~~~~~~~~~~~~
webview.h:400:5: note: (near initialization for 'MyIOleInPlaceFrameTable.Release')
webview.h:416:5: warning: initialization from incompatible pointer type [-Wincompatible-pointer-types]
     UI_AddRef,
     ^~~~~~~~~
webview.h:416:5: note: (near initialization for 'MyIDocHostUIHandlerTable.AddRef')
webview.h:417:5: warning: initialization from incompatible pointer type [-Wincompatible-pointer-types]
     UI_Release,
     ^~~~~~~~~~
webview.h:417:5: note: (near initialization for 'MyIDocHostUIHandlerTable.Release')
webview.h: In function 'EmbedBrowserObject':
webview.h:469:41: warning: passing argument 4 of 'pClassFactory->lpVtbl->CreateInstance' from incompatible pointer type [-Wincompatible-pointer-types
]
      pClassFactory, 0, &IID_IOleObject, &browserObject)) {
                                         ^
webview.h:469:41: note: expected 'void **' but argument is of type 'IOleObject ** {aka struct IOleObject **}'
webview.h:472:45: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
       SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG)ptr);

Does anything in my env affect this?

C:\Source\Go\src\github.com\PaluMacil\misc\c-webview [master ≡ +0 ~2 -0 !]> go env
set GOARCH=amd64
set GOBIN=C:\Source\Go\bin
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\Source\Go
set GORACE=
set GOROOT=C:\Go
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\dcwol\AppData\Local\Temp\go-build252644231=/tmp/go-build -gno-record-gcc
-switches
set CXX=g++
set CGO_ENABLED=1
set PKG_CONFIG=pkg-config
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2

Here is my Go version:

C:\Source\Go\src\github.com\PaluMacil\misc\c-webview [master ≡ +0 ~2 -0 !]> go version
go version go1.8.3 windows/amd64

GCC version:

C:\Source\Go\src\github.com\PaluMacil\misc\c-webview [master ≡ +0 ~2 -0 !]> gcc -v
Using built-in specs.
COLLECT_GCC=C:\Program Files\mingw-w64\x86_64-7.1.0-posix-seh-rt_v5-rev0\mingw64\bin\gcc.exe
COLLECT_LTO_WRAPPER=C:/Program\ Files/mingw-w64/x86_64-7.1.0-posix-seh-rt_v5-rev0/mingw64/bin/../libexec/gcc/x86_64-w64-mingw32/7.1.0/lto-wrapper.exe

Target: x86_64-w64-mingw32
Configured with: ../../../src/gcc-7.1.0/configure --host=x86_64-w64-mingw32 --build=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --prefix=/mingw64
--with-sysroot=/c/mingw710/x86_64-710-posix-seh-rt_v5-rev0/mingw64 --enable-shared --enable-static --disable-multilib --enable-languages=c,c++,fortra
n,lto --enable-libstdcxx-time=yes --enable-threads=posix --enable-libgomp --enable-libatomic --enable-lto --enable-graphite --enable-checking=release
 --enable-fully-dynamic-string --enable-version-specific-runtime-libs --enable-libstdcxx-filesystem-ts=yes --disable-libstdcxx-pch --disable-libstdcx
x-debug --enable-bootstrap --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-gnu-as --with-gnu-ld --wi
th-arch=nocona --with-tune=core2 --with-libiconv --with-system-zlib --with-gmp=/c/mingw710/prerequisites/x86_64-w64-mingw32-static --with-mpfr=/c/min
gw710/prerequisites/x86_64-w64-mingw32-static --with-mpc=/c/mingw710/prerequisites/x86_64-w64-mingw32-static --with-isl=/c/mingw710/prerequisites/x86
_64-w64-mingw32-static --with-pkgversion='x86_64-posix-seh-rev0, Built by MinGW-W64 project' --with-bugurl=http://sourceforge.net/projects/mingw-w64
CFLAGS='-O2 -pipe -fno-ident -I/c/mingw710/x86_64-710-posix-seh-rt_v5-rev0/mingw64/opt/include -I/c/mingw710/prerequisites/x86_64-zlib-static/include
 -I/c/mingw710/prerequisites/x86_64-w64-mingw32-static/include' CXXFLAGS='-O2 -pipe -fno-ident -I/c/mingw710/x86_64-710-posix-seh-rt_v5-rev0/mingw64/
opt/include -I/c/mingw710/prerequisites/x86_64-zlib-static/include -I/c/mingw710/prerequisites/x86_64-w64-mingw32-static/include' CPPFLAGS=' -I/c/min
gw710/x86_64-710-posix-seh-rt_v5-rev0/mingw64/opt/include -I/c/mingw710/prerequisites/x86_64-zlib-static/include -I/c/mingw710/prerequisites/x86_64-w
64-mingw32-static/include' LDFLAGS='-pipe -fno-ident -L/c/mingw710/x86_64-710-posix-seh-rt_v5-rev0/mingw64/opt/lib -L/c/mingw710/prerequisites/x86_64
-zlib-static/lib -L/c/mingw710/prerequisites/x86_64-w64-mingw32-static/lib '
Thread model: posix
gcc version 7.1.0 (x86_64-posix-seh-rev0, Built by MinGW-W64 project)

build on darwin fails

~/src/webview$ go build -x
WORK=/var/folders/q_/6fv7kfsj7b11y457c2dsssgw0000gn/T/go-build352003042
mkdir -p $WORK/webview/_obj/
mkdir -p $WORK/
cd /Users/lsm/src/webview
CGO_LDFLAGS="-g" "-O2" "-framework" "Cocoa" "-framework" "WebKit" /usr/local/Cellar/go/1.8.1/libexec/pkg/tool/darwin_amd64/cgo -objdir $WORK/webview/_obj/ -importpath webview -- -I $WORK/webview/_obj/ -g -O2 -DWEBVIEW_COCOA=1 -x objective-c webview.go
# webview
./webview.go:132:3: struct size calculation error off=8 bytesize=0
~/src/webview$ uname -a 
Darwin io.local 16.1.0 Darwin Kernel Version 16.1.0: Wed Oct 19 20:31:56 PDT 2016; root:xnu-3789.21.4~4/RELEASE_X86_64 x86_64

Why can't I call a Go function from JS and access it's return value in JS

I have a variant of the counter example as follows

app.js (using vuejs)

var vm = new Vue({
  el: '#app',
  template: '<div><div class="counter">{{ counterVal }}</div><button class="btn btn-primary" v-on:click="increment">Increment</button></div>',
  data: {
    counterVal: 0
  },
  methods: {
    increment: function() { 
      this.counterVal = native.add(this.counterVal, 1);             
      alert(this.counterVal);
    },
  }
});

native.go

package main

import (
	"fmt"
)

//Native 
type Native struct{}

//NewNative 
func newNative() Native {
	return Native{}
}

//Add 
func (c *Native) Add(val1 uint, val2 uint) uint {
	fmt.Println(val1 + val2)
	return val1 + val2
}

In main.go inside w.Dispatch(func() { I simply do

native := newNative()
w.Bind("native", &native)

But in the JS the first time i hit the Increment button native.add seems to return undefined.

Is returning values from Go methods not supported?

A way to terminate the main loop

Currently there are webview_init and webview_exit`, which are basically a constructor and a descructor for the webview object.

I suggest to add something like void webview_terminate(struct webview *w) that would terminate and break out of the main loop.

Text input crashes application

Thanks for a great library, but:

Running the examples/window-go/main.goapp and focusing the text input box will cause the application to crash.

Using macOS 10.12.6 and golang installed from homebrew.

~/go/src/github.com/zserge/webview/examples/window-go $ go build -o app
~/go/src/github.com/zserge/webview/examples/window-go $ ./app 
fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x7fff92269b52]

runtime stack:
runtime.throw(0x439a3a8, 0x2a)
	/usr/local/Cellar/go/1.9.2/libexec/src/runtime/panic.go:605 +0x95
runtime.sigpanic()
	/usr/local/Cellar/go/1.9.2/libexec/src/runtime/signal_unix.go:351 +0x2b8

goroutine 1 [syscall, locked to thread]:
runtime.cgocall(0x42d4f30, 0xc42013de48, 0x4399a98)
	/usr/local/Cellar/go/1.9.2/libexec/src/runtime/cgocall.go:132 +0xe4 fp=0xc42013de08 sp=0xc42013ddc8 pc=0x4003964
github.com/zserge/webview._Cfunc_CgoWebViewLoop(0x5200040, 0x1, 0x0)
	github.com/zserge/webview/_obj/_cgo_gotypes.go:157 +0x4d fp=0xc42013de48 sp=0xc42013de08 pc=0x42d060d
github.com/zserge/webview.(*webview).Loop.func1(0x5200040, 0xc400000001, 0xc400000000)
	/Users/oozberg/go/src/github.com/zserge/webview/webview.go:281 +0x68 fp=0xc42013de80 sp=0xc42013de48 pc=0x42d3018
github.com/zserge/webview.(*webview).Loop(0xc42000e060, 0xc42013de01, 0xc42000e001)
	/Users/oozberg/go/src/github.com/zserge/webview/webview.go:281 +0x3a fp=0xc42013dea8 sp=0xc42013de80 pc=0x42d0e1a
github.com/zserge/webview.(*webview).Run(0xc42000e060)
	/Users/oozberg/go/src/github.com/zserge/webview/webview.go:285 +0x30 fp=0xc42013ded0 sp=0xc42013dea8 pc=0x42d0e70
main.main()
	/Users/oozberg/go/src/github.com/zserge/webview/examples/window-go/main.go:76 +0xdd fp=0xc42013df80 sp=0xc42013ded0 pc=0x42d43ed
runtime.main()
	/usr/local/Cellar/go/1.9.2/libexec/src/runtime/proc.go:195 +0x226 fp=0xc42013dfe0 sp=0xc42013df80 pc=0x402d736
runtime.goexit()
	/usr/local/Cellar/go/1.9.2/libexec/src/runtime/asm_amd64.s:2337 +0x1 fp=0xc42013dfe8 sp=0xc42013dfe0 pc=0x4059111

goroutine 6 [IO wait]:
internal/poll.runtime_pollWait(0x5044f70, 0x72, 0xffffffffffffffff)
	/usr/local/Cellar/go/1.9.2/libexec/src/runtime/netpoll.go:173 +0x57
internal/poll.(*pollDesc).wait(0xc420118098, 0x72, 0x0, 0x0, 0x0)
	/usr/local/Cellar/go/1.9.2/libexec/src/internal/poll/fd_poll_runtime.go:85 +0xae
internal/poll.(*pollDesc).waitRead(0xc420118098, 0xffffffffffffff00, 0x0, 0x0)
	/usr/local/Cellar/go/1.9.2/libexec/src/internal/poll/fd_poll_runtime.go:90 +0x3d
internal/poll.(*FD).Accept(0xc420118080, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
	/usr/local/Cellar/go/1.9.2/libexec/src/internal/poll/fd_unix.go:335 +0x1e2
net.(*netFD).accept(0xc420118080, 0xc42003ce48, 0x40025c7, 0xc420090da0)
	/usr/local/Cellar/go/1.9.2/libexec/src/net/fd_unix.go:238 +0x42
net.(*TCPListener).accept(0xc42000e058, 0x4256618, 0x4055bd0, 0xc42003ce90)
	/usr/local/Cellar/go/1.9.2/libexec/src/net/tcpsock_posix.go:136 +0x2e
net.(*TCPListener).Accept(0xc42000e058, 0x43a39e8, 0xc420090d20, 0x4538680, 0xc42011c330)
	/usr/local/Cellar/go/1.9.2/libexec/src/net/tcpsock.go:247 +0x49
net/http.(*Server).Serve(0xc420148000, 0x4537d00, 0xc42000e058, 0x0, 0x0)
	/usr/local/Cellar/go/1.9.2/libexec/src/net/http/server.go:2695 +0x1b2
net/http.Serve(0x4537d00, 0xc42000e058, 0x0, 0x0, 0xc42002ffc8, 0x4291c90)
	/usr/local/Cellar/go/1.9.2/libexec/src/net/http/server.go:2323 +0x73
main.startServer.func1(0x4537d00, 0xc42000e058)
	/Users/oozberg/go/src/github.com/zserge/webview/examples/window-go/main.go:46 +0x9e
created by main.startServer
	/Users/oozberg/go/src/github.com/zserge/webview/examples/window-go/main.go:41 +0xe0

goroutine 7 [IO wait]:
internal/poll.runtime_pollWait(0x5044eb0, 0x72, 0x0)
	/usr/local/Cellar/go/1.9.2/libexec/src/runtime/netpoll.go:173 +0x57
internal/poll.(*pollDesc).wait(0xc420118118, 0x72, 0xffffffffffffff00, 0x45354c0, 0x4531a30)
	/usr/local/Cellar/go/1.9.2/libexec/src/internal/poll/fd_poll_runtime.go:85 +0xae
internal/poll.(*pollDesc).waitRead(0xc420118118, 0xc42014c000, 0x1000, 0x1000)
	/usr/local/Cellar/go/1.9.2/libexec/src/internal/poll/fd_poll_runtime.go:90 +0x3d
internal/poll.(*FD).Read(0xc420118100, 0xc42014c000, 0x1000, 0x1000, 0x0, 0x0, 0x0)
	/usr/local/Cellar/go/1.9.2/libexec/src/internal/poll/fd_unix.go:126 +0x18a
net.(*netFD).Read(0xc420118100, 0xc42014c000, 0x1000, 0x1000, 0xc4200418c8, 0x424c98a, 0xc42007b598)
	/usr/local/Cellar/go/1.9.2/libexec/src/net/fd_unix.go:202 +0x52
net.(*conn).Read(0xc42000e068, 0xc42014c000, 0x1000, 0x1000, 0x0, 0x0, 0x0)
	/usr/local/Cellar/go/1.9.2/libexec/src/net/net.go:176 +0x6d
net/http.(*connReader).Read(0xc42007b590, 0xc42014c000, 0x1000, 0x1000, 0xc42005c2c0, 0x4531734, 0x2)
	/usr/local/Cellar/go/1.9.2/libexec/src/net/http/server.go:753 +0x105
bufio.(*Reader).fill(0xc420060180)
	/usr/local/Cellar/go/1.9.2/libexec/src/bufio/bufio.go:97 +0x11a
bufio.(*Reader).ReadSlice(0xc420060180, 0xc42005c20a, 0xc420041a38, 0x4034c5b, 0x2, 0xc420041a48, 0x4034314)
	/usr/local/Cellar/go/1.9.2/libexec/src/bufio/bufio.go:338 +0x2c
bufio.(*Reader).ReadLine(0xc420060180, 0x100, 0xf8, 0x437eaa0, 0xc420041a98, 0x220004003729, 0xf8)
	/usr/local/Cellar/go/1.9.2/libexec/src/bufio/bufio.go:367 +0x34
net/textproto.(*Reader).readLineSlice(0xc42007b5c0, 0xc420041b20, 0xc420041b20, 0x4012dd8, 0x100, 0x437eaa0)
	/usr/local/Cellar/go/1.9.2/libexec/src/net/textproto/reader.go:55 +0x70
net/textproto.(*Reader).ReadLine(0xc42007b5c0, 0xc420116300, 0x0, 0xc420041b90, 0x408bce2)
	/usr/local/Cellar/go/1.9.2/libexec/src/net/textproto/reader.go:36 +0x2b
net/http.readRequest(0xc420060180, 0x0, 0xc420116300, 0x0, 0x0)
	/usr/local/Cellar/go/1.9.2/libexec/src/net/http/request.go:925 +0x99
net/http.(*conn).readRequest(0xc420090d20, 0x45385c0, 0xc42005c280, 0x0, 0x0, 0x0)
	/usr/local/Cellar/go/1.9.2/libexec/src/net/http/server.go:933 +0x17c
net/http.(*conn).serve(0xc420090d20, 0x45385c0, 0xc42005c280)
	/usr/local/Cellar/go/1.9.2/libexec/src/net/http/server.go:1739 +0x50e
created by net/http.(*Server).Serve
	/usr/local/Cellar/go/1.9.2/libexec/src/net/http/server.go:2720 +0x288

CMake support

As CMake is now more popular in the cross-platform world than, say, GNU Make, I believe we should should support CMake in this library. That would simplify integration into C/C++ projects.

Specify location for Window

I really love this package. Is there a way to specify where the main Window should open? On my OS X it always opens bottom left.

building for windows using golang

GOOS=windows GOARCH=amd64 go build

main.go:17:2: build constraints exclude all Go files in /Users/apple/workspace/go/src/github.com/zserge/webview

How to persist the app in background when "Close" button clicked? (minimal example)

This library is great and produces small enough output. However the existing README and examples do not provide clear explanation on whether there is an option to keep application running in background when app window has been closed.

For example Qt provides an option to override default behavior of this action. Also it offers option of not destroying window, but hiding it (the event loop still runs, the object can still manipulated, but window is not shown in desktop environment).

Would be good to know if this lib already has such functionality, or if not, if that can be easily implemented.

On a personal note -- I am considering migrating my app away from Qt (currently Qt/C++ statically linked against .a of Go code), but for my app (and many other apps I presume) this would be a requirement to have such option.

Callback to know when the page is loaded to inject custom JS code into the page

As we now have JS-to-C bindings, it would be handy to have a callback that is invoked when the page is just loaded. That would allow native part of the app to inject some JS code into the page or wrap certain functions such as console.log.

I think for gtk-webkit the right signal to listen to would be document-load-finished (https://webkitgtk.org/reference/webkitgtk/stable/webkitgtk-webkitwebview.html#WebKitWebView-document-load-finished)

For Cocoa WebKit it is likely to be webView:didFinishLoadForFrame delegate method.

For MSHTML, well, there must be a solution, too.

Mac person -- need to compile for windows

Hi -- I am a mac user and I am trying to get my app working in windows. To do this I have to install a virtual machine, then install Go, GIT, Then MinGW-64 bit -- I've done that and all it does is complain: "Sorry unimplemented 64 bit cc1.exe"

In short I spent more %$#@! time installing $#@! for windows than I did writing the gui application in the first place. Is there an easier way -- maybe a precompiled that I can install?

OSX: todo-go crashing non deterministically as the windows starts opening

On average it opens correctly 30% of the time.
It opens for a brief millisecond and then dies.
When it does open and stays open it seems stable.

Env:

x-MacBook-Pro:zserge-webview apple$ go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/apple/workspace/go"
GORACE=""
GOROOT="/usr/local/opt/go/libexec"
GOTOOLDIR="/usr/local/opt/go/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/wp/ff6sz9qs6g71jnm12nj2kbyw0000gp/T/go-build335519809=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

Make file:
I am running it with "build-todo" task at bottom of this make...

# ref: https://github.com/zserge/webview

DIR=${PWD}

LIB_GO_PATH=github.com/zserge/webview
LIB_FILE_PATH=${GOPATH}/src/${LIB_GO_PATH}

EX_GO_PATH=${LIB_GO_PATH}/examples
EX_FILE_PATH=${GOPATH}/src/${EX_GO_PATH}

help:
	@awk -F ':|##' '/^[^\t].+?:.*?##/ { printf "\033[36m%-22s\033[0m %s\n", $$1, $$NF }' $(MAKEFILE_LIST)

check: ## check paths

	@echo "## Checking paths ##"
	@echo 

	@echo "DIR \t \t ${DIR}"
	@echo 

	@echo "LIB_GO_PATH: \t ${LIB_GO_PATH}"
	@echo "LIB_FILE_PATH: \t ${LIB_FILE_PATH}"
	@echo 

	@echo "EX_GO_PATH: \t ${EX_GO_PATH}"
	@echo "EX_FILE_PATH: \t ${EX_FILE_PATH}"
	@echo 



dep: ## get code

	go get -u ${LIB_GO_PATH}/...
	


dep-clean: ## clean out all code

	# delete lib code
	rm -rf ${LIB_FILE_PATH}


open-bash: ## open bash shell

	# open bash terminal
	open -a Terminal.app ${LIB_FILE_PATH}

open-fs: ## open file system

	# Opens Finder.
	open ${LIB_FILE_PATH}

open-vsc: ## open vscode

	# Opens Visual Studio Code
	code ${LIB_FILE_PATH}


run: ## run minimal example

	cd ${EX_FILE_PATH}/minimal-go && go run main.go

build: ## build minimal example

	cd ${EX_FILE_PATH}/minimal-go && rm -rf minimal.app

	# Make OSX app scaffold
	cd ${EX_FILE_PATH}/minimal-go && mkdir -p minimal.app/Contents/MacOS
	cd ${EX_FILE_PATH}/minimal-go && mkdir -p minimal.app/Contents/Info.plist
	cd ${EX_FILE_PATH}/minimal-go && mkdir -p minimal.app/Resources/minimal.icns
	
	# build into the scaffold.
	cd ${EX_FILE_PATH}/minimal-go && go build -o minimal.app/Contents/MacOS/minimal
	cd ${EX_FILE_PATH}/minimal-go && open ./minimal.app

build-todo: ## build todo example

	## clean first
	cd ${EX_FILE_PATH}/todo-go && rm -rf todo.app

	# Make OSX app scaffold
	cd ${EX_FILE_PATH}/todo-go && mkdir -p todo.app/Contents/MacOS
	cd ${EX_FILE_PATH}/todo-go && mkdir -p todo.app/Contents/Info.plist
	cd ${EX_FILE_PATH}/todo-go && mkdir -p todo.app/Resources/todo.icns
	
	# build into the scaffold.
	cd ${EX_FILE_PATH}/todo-go && go build -o todo.app/Contents/MacOS/todo
	cd ${EX_FILE_PATH}/todo-go && open ./todo.app

Add flag to make window appear in center of main screen

Currently when I let webview open a window it appears between my two monitors and is split which is not good. I suggest adding a flag to the open function which when set makes the window appear centered on the main screen.

fails to build on go version go1.10beta1 darwin/amd64

go1.10beta1 came out yesterday.

webview samples are failing to build

x-MacBook-Pro:darwin_amd64 apple$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/apple/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/apple/workspace/go"
GORACE=""
GOROOT="/usr/local/opt/go/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/opt/go/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/wp/ff6sz9qs6g71jnm12nj2kbyw0000gp/T/go-build361907964=/tmp/go-build -gno-record-gcc-switches -fno-common"

cd /Users/apple/workspace/go/src/github.com/zserge/webview/examples/todo-go && go build -o todo.app/Contents/MacOS/todo
/usr/local/opt/go/libexec/pkg/tool/darwin_amd64/link: running dsymutil failed: signal: segmentation fault

scrolling is much slower on OSX

Hey this is a really cool project!

I gave the example a go and was just curious why scrolling was much slower going to safari and scrolling there?

Is this possible to adjust? I'm guessing it's related to my tracking speed set on my OSX, which I'm wondering if I can somehow pass into the webview.

Packaging for Windows 10

I am writing an appx module in golang at the moment. This is the way all packaging works for all windows 10 now. Its a bit like the Plists for OSX. All you need is the right appx xml and then you can zip it and submit the app to the Windows store. Its then signed by MS.

If you want to distribute to non windows 10x users like Windows 10 home or pro (or whatever they are called these days) then you can / or need to self sign it.

Am raising it here in case others are interested in working on this..

HDPI Support?

Hi,
I really love this library, and it is super useful to me. I was wondering about HDPI support, at least on windows. On my machine, the opened web browser looks very pixelated. IE10 looks just fine, and supports high definition fonts, but the window that this opens up just looks blocky.

Is there any way I can make the webview work well with HDPI displays?

Hide script errors on Windows?

If there is a script error on the page you are viewing, an alert pops up, blocking the UI. Is there a way to suppress these?

capture

How to cross-compile for Windows?

When I try to build the Go example on my Mac machine into a Windows executable, I get the following error:

main.go:11:2: no buildable Go source files in /Users/rlommers/go/src/github.com/zserge/webview

Any idea how to cross-compile for Windows on my Mac?

API to change window title

It's often helpful to rename window title, e.g. when some document is opened within the app the title becomes App - document name.

  • gtk: gtk_window_set_title(window, title)
  • cocoa: [window setTitle:@"title"];
  • winapi: SetWindowText(window, title)
  • Go API wrapper
  • Documentation

Hide console on Windows

When the webview app starts on Windows, a black console window starts in a background.
It should be hidden at start.
Plus, when a webview window is closed, a console must be closed too instead of staying alive and preventing other instances of webview start.

IE Javscript compatibility

Is it possible tu use Microsoft Edge webview to execute javascript instead of MSHTML or use a polyifill for common js documents methods?

Webview will receive weird strings when spammed with an empty one

JS/HTML:

<div id="console" style="max-height: 80%;width: 100%; overflow-y: auto; font-family: 'Lucida Console'"></div>

<div style="width: 100%">
    <input type="button" id="btndo" value="Do"
           onclick="window.external.invoke_(document.getElementById('txt').value); document.getElementById('txt').value=''"
           style="float: right; padding-left: 5px;"
    />
    <div style="overflow: auto;">
        <input type="text" id="txt"
               onkeyup="event.preventDefault ? event.preventDefault() : event.returnValue = false;if (event.keyCode === 13) document.getElementById('btndo').click();"
               style="width: 100%;
  box-sizing: border-box;"/>
    </div>
</div>

<script>
    function add(data) {
        var d = document.getElementById("console");
        d.innerText = d.innerText + "\n" + data;
    }
</script>
var wv webview.WebView

func L(text string) {
	wv.Eval("add(\"" + strings.TrimSpace(text) + "\")")
}

func main() {
	callback := func(w webview.WebView, data string) {
		L("> "+data)
	}

	addr := "127.0.0.1:999"
	go func() {
		m := http.NewServeMux()
		m.HandleFunc("/", http.FileServer(http.Dir(".")).ServeHTTP)
		log.Fatal(http.ListenAndServe(addr, m))
	}()

	wv = webview.New(webview.Settings{Title: "CMD", URL: "http://" + addr, Width: 375, Height: 310, Resizable: true, ExternalInvokeCallback: callback})
	wv.Run()
}

output: (of spamming enter a few times rapidly)

> �œÁ�
>
> À¥Á�
> СÁ�
> 0ŸÁ�
>  £Á�
> `¨Á�
>
> À¥Á�
> à�Á�

Call Javascript functions from C and call C functions from Javascript

Currently to bind core app logic to the web UI one has to use websockets or HTTP API. Although it may not be problematic in Go, it is still very much unusual to C developers.

Ideally, there should be a way to call JS code from C side and back.

This is likely to affect the API of the library, for example webview() function would return some handle that could later be used to call JS functions. Also, this requires looking at different webview implementations in depth.

With Gtk-Webkit it seems to be more-or-less clear: https://webkitgtk.org/reference/webkitgtk/stable/webkitgtk-webkitwebview.html#webkit-web-view-execute-script

For Cocoa-Webkit a similar function seems to exist: https://developer.apple.com/documentation/webkit/webview/1408429-stringbyevaluatingjavascriptfrom?language=objc

As for MSHTML - I need a deeper look from my side. Sample applies to calling C functions from JavaScript. To speed things up any help is appreciated.

Capturing "Save" keybind

Hi,
On Windows, it appears that it is not possible to capture user input of "ctrl + s". The reason for this makes sense, to avoid letting users save your html page or break something. However, I am developing an application that has a text edit, and it is impossible to allow users to save due to this limitation.

For now I have a button, but if I could listen for that keybind it would help me immensely.

Customize window background color

Often, if a web page is heavy it takes some time to load and render it (even if it's served locally). In this case a plain window background is shown, which has normally some light color. If a webpage background is dark - it creates an aesthetically unpleasant blink when app starts. It can be avoided by setting a window background color to be close to that of the web page.

WebKit Threading Violation - initial use of WebKit from a secondary thread.

Just started playing with this nice little library last night. Thank you for putting this together!

Very now and then (50/50?) my app on startup crashes with the above error and the following stacktrace:

https://gist.github.com/prologic/6b0f58fa058ef603215696c66476bb0c

At this stage I have no context/clue what's going on here so posting for visbility and hopefully someone with deeper knowledge of webview's inner workings can file a PR to fix this. AFACT this is a pretty critical bug as it breaks usability for a user.

Multi-threading support

Currently, webview runs on the main UI thread only and JS code can be evaluated in the main thread only. If an app has to be multithreaded - there is no way to call JS code asynchronously from another thread.

My first (and very thoughtless) approach was to add API to spawn platform-specific threads, join, interrupt them, lock/unlock mutexes etc, Not only it bloats the API, it also seems to be way out of the scope of this library.

My current approach is very similar to libui - basically, provide a function to post arbitrary callbacks with some void * arguments to the main thread. It leaves cross-platform multi-threading up to the app developer (which is handy if you prefer to use std::thread, goroutines etc). But it still allows to submit JS code to the web engine safely from any non-UI thread.

Customize window icon

Currently, if a developer wants a custom application icon he can put .icns file into the app bundle on MacOS, or use custom resource file on Windows.

This still uses the default application icon on Windows in the window bar, and it uses the default icon on Linux.

It may be possible to add a special icon parameter to the webview structure that would be pixmap data and it would be used as a window icon in Gtk and WINAPI. I don't consider loading icons from files, because I assume most of the webview apps would embed all the resources into a standalone executable, and I don't want to force developers distribute more than one executable file for their apps.

On linux the following API can be used: https://developer.gnome.org/gtk3/stable/GtkWindow.html#gtk-window-set-icon

On windows it's likely to be something like, except that icon should be read from memory buffer:

HANDLE icon = LoadImage(fgDisplay.Instance, "c:\\icon.ico", IMAGE_ICON, 32, 32, LR_LOADFROMFILE);
SendMessage(instance, (UINT)WM_SETICON, ICON_BIG, (LPARAM)icon);

Web Event Callbacks?

So I noticed the callback function in the webview struct, but I don't think that's what I'm looking for. Namely, I would like to know if there's a way to intercept web events such as page redirects / navigation. A concrete example would be intercepting the redirect of an OAuth 2 application so that you can extract the state information the server returns.

OSX: window not closing when using the Menu > Quit

There is one bug with closing the app on OSX.

Does Not work, when you use the top menu next to the Apple logo of the screen.
screen shot 2017-09-21 at 21 41 54

Does work, when you click the red button in the top left of the window.
screen shot 2017-09-21 at 21 43 47

Here is a simple make file to reproduce:

build:

	# Make OSX app 
	cd ${EX_FILE_PATH}/minimal-go && mkdir -p minimal.app/Contents/MacOS
	cd ${EX_FILE_PATH}/minimal-go && mkdir -p minimal.app/Contents/Info.plist
	cd ${EX_FILE_PATH}/minimal-go && mkdir -p minimal.app/Resources/minimal.icns
	
	# build into the scaffold.
	cd ${EX_FILE_PATH}/minimal-go && go build -o minimal.app/Contents/MacOS/minimal
	cd ${EX_FILE_PATH}/minimal-go && open ./minimal.app

System dialogs

Although I prefer keep webview small, simple and focused on one thing only, I believe it has to have some support of system dialogs, such as open/save file chooser or basic alert (aka messagebox) dialogs.

I see in libui all 3 platforms take ~400 LOC, so borrowing parts of that could be a compromise.
I'm working on it now.

  • Linux/GTK
  • MacOS/Cocoa
  • Windows
  • Golang wrapper

OSX: several UI nitpicks

  • when the window starts, it would be nice to detach from terminal and set focus on it
  • mouse pointer to change its shape to "resize" when it is close to the window edges - just like all other windows behave
  • when above the web view, mouse pointer does not change its shape as it should - e.g. above the hyper links, I expect it to change to the pointer shape

Automatic binding Go types with JavaScript (helps with app architecture)

Currently, webview provides all the building blocks to make an awesome GUI app, but it doesn't tell you how to use them. Often it's good to have an un-opinionated library, but in this case it becomes a stumbling block for the new users.

I will follow up with a number of blog posts about best practices I've discovered so far. My biggest pain at the moment is to write JS wrappers for window.external.invoke_() and parse dynamic JSONs in Go to run certain methods in response.

I suggest adding WebView.Register(name string, obj interface{}) method that would register an arbitrary Go struct and expose it under the given name in the JS environment. All public methods will be accessible under their names, and all public fields should be updated automatically, too.

The way I expect it to work is by processing a Go type using reflection and generating some JS code to run invoke_(). Also it should wrap existing ExternalInvokeCallback function into another one that would handle these specific wrapped methods and delegate them to a Go type.

type Counter struct {
	Value int `json:"value"`
}

func (c *Counter) Add(n int) {
	c.Value = c.Value + n
}

func (c *Counter) Reset() {
	c.Value = 0
}

w.Register("counter", &Counter{})
counter.reset();
counter.add(1);
console.log(counter.value);

The cgo flag for MacOS is "darwin", not "macos"

At least up to MacOS Sierra )and go 1.8.3) the "os" name for MacOS is "darwin", but you are using:

 #cgo macos CFLAGS: -DWEBVIEW_COCOA=1 -x objective-c
 #cgo macos LDFLAGS: -framework Cocoa -framework WebKit

This causes WEBVIEW_COCOA to be undefined. Changing to the following fixes the problem:

#cgo darwin CFLAGS: -DWEBVIEW_COCOA=1 -x objective-c 
#cgo darwin LDFLAGS: -framework Cocoa -framework WebKit

If you tested this with a different version of MacOS and/or go, and it worked for you, please consider adding both "macos" and "darwin" flags.

window.print() ?

how to open a printer dialog ?

javascript does not work. I guess because its a web view.

How to load local images?

w := webview.New(webview.Settings{
	Title:  "test",
	Width:  100,
	Height: 300,
	URL:    `data:text/html,` + url.PathEscape(string(MustAsset("assets/index.html"))),
})
<!DOCTYPE html>
<html>
<body>
<img src="http://css.tools.chinaz.com/tools/images/public/logos/logo-index.png" >
<img src="test.png" >
</body>
</html>
test/
 - main.go
 - test.png
 - assets/
   - index.html

mshtmhst.h is missing

when I go get this project,it said that mshtmhst.h is missing.I using win7 X86...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.