diff --git a/.gitignore b/.gitignore index 66fd13c..ea50fd8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ # Binaries for programs and plugins +/webview_app *.exe *.exe~ *.dll diff --git a/README.md b/README.md index 1d7df8a..efed311 100644 --- a/README.md +++ b/README.md @@ -48,3 +48,69 @@ Calling `Eval()` or `Dispatch()` before `Run()` does not work because the webvie [go-docs]: https://pkg.go.dev/github.com/webview/webview_go [webview]: https://github.com/webview/webview + + +### WebView UserAgent Example + +This project demonstrates how to set a custom User-Agent string in webview_go. + +It builds a simple Go application that shows the current User-Agent in the UI and verifies that it matches the value defined in the source code. + +Requirements +Go 1.18+ +C compiler (clang/gcc) +Linux: +libgtk-3-dev +libwebkit2gtk-4.0-dev +macOS: no additional dependencies + +### Build + +chmod +x build.sh +./build.sh + +This will: + 1. Install necessary dependencies (on Linux). + 2. Compile main.go into an executable webview_app. + +### Run + +./webview_app + +Expected behavior + +When the application runs: + • A window will open with: + • A UserAgent section showing the custom value (e.g. MyCustomUserAgent/1.0). + • A button and counter to demonstrate bindings. + +If you see your custom User-Agent displayed in the window, the implementation is correct + +Troubleshooting + +Linux: +1. Error: webkit2/webkit2.h: No such file or directory +-> Install missing GTK/WebKit dependencies: +sudo apt-get update +sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev + +2. Error: pkg-config not found +-> Install pkg-config: +sudo apt-get install -y pkg-config + +3. Blank window / crash on startup +-> Ensure you are running inside a desktop environment with GTK/WebKit support. +-> On minimal VMs, install ubuntu-desktop or run inside an X11 session. + +MacOS: +1. Error: ld: framework not found WebKit +-> Ensure you use clang (not gcc) when compiling. +-> Go automatically links against Cocoa/WebKit frameworks, so usually no manual fix is required. + +2. Window opens but is empty +-> Sometimes macOS blocks WebKit initialization in sandboxed terminals. Try: +open ./webview_test + +3. Custom UserAgent not applied +-> Make sure you call w.SetUserAgent("MyCustomUserAgent/1.0") before w.Navigate(...) or w.SetHtml(...) + diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..3d425c4 --- /dev/null +++ b/build.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +set -e + +echo "[INFO] Installing dependencies..." + +# Проверка платформы +if [[ "$OSTYPE" == "linux-gnu"* ]]; then + sudo apt-get update + sudo apt-get install -y build-essential pkg-config libgtk-3-dev libwebkit2gtk-4.0-dev + echo "[INFO] Dependencies installed (Linux)" +elif [[ "$OSTYPE" == "darwin"* ]]; then + echo "[INFO] No dependencies required on macOS" +else + echo "[ERROR] Unsupported OS: $OSTYPE" + exit 1 +fi + +echo "[INFO] Building Go binary..." +go build -o webview_app ./examples/bind + +echo "[INFO] Build complete. Run with ./webview_test" \ No newline at end of file diff --git a/examples/bind/main.go b/examples/bind/main.go index 3374f84..000be83 100644 --- a/examples/bind/main.go +++ b/examples/bind/main.go @@ -2,12 +2,17 @@ package main import webview "github.com/webview/webview_go" -const html = ` +const html = `