WebviewGtk 0.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package WebviewGtk --version 0.1.0
                    
NuGet\Install-Package WebviewGtk -Version 0.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="WebviewGtk" Version="0.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="WebviewGtk" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="WebviewGtk" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add WebviewGtk --version 0.1.0
                    
#r "nuget: WebviewGtk, 0.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package WebviewGtk@0.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=WebviewGtk&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=WebviewGtk&version=0.1.0
                    
Install as a Cake Tool

WebviewGtk

A lightweight C# wrapper around WebKitGTK to embed a native web browser in your Linux desktop apps with minimal overhead.

| ⚠️ This project is primarily intended for personal use, but might be helpful as a base for other GTK-powered .NET apps for linux.

Features

  • Splash screen overlay while the page loads
  • StrictMode: limit navigation to a single base URI
  • JavaScript ↔ C# command bridge (via window.__backendCallback)
  • Context menu disabling
  • Developer tools toggle (DebugMode)
  • Optional text selection blocking
  • Safe shutdown via CancellationToken

Quickstart

Basic usage

WebViewConfig config = new()
{
    StartUri = new Uri("https://example.com"),
    WindowTitle = "My App",
    Width = 1280,
    Height = 720,
    AllowSelection = false,
    SplashFilename = "loading.gif",
    DebugMode = false,
    StrictMode = true,
    WindowPosition = Gtk.WindowPosition.Center
};

WebkitGtkWrapper.RunWebkit(config, (evt, uri) =>
{
    Console.WriteLine($"Navigation event: {evt}, URI: {uri}");
}, CancellationToken.None);

With JS command handler

WebkitGtkWrapper.RunWebkitWithHandler(config,
    (evt, uri) => Console.WriteLine($"Changed: {evt}, URI: {uri}"),
    command =>
    {
        Console.WriteLine($"Received from JS: {command}");
        return "\"response from backend\"";
    },
    CancellationToken.None);

On the JS side, you can send messages like:

window.webkit.messageHandlers.backend.postMessage("your-command");

And receive responses via:

window.__backendCallback?.("your-result");

Native Dependencies

Library Shared Object Name Description
GLib libglib-2.0.so.0 Core GNOME utility library
GObject libgobject-2.0.so.0 GObject type system
Gtk libgtk-3.so.0 GTK+ 3 UI toolkit
GdkPixbuf libgdk_pixbuf-2.0.so Image loading for splash animation
JavascriptCoreGtk libjavascriptcoregtk-4.1.so.0 JavaScript engine behind WebKitGTK
WebKit libwebkit2gtk-4.1.so.0 WebView rendering engine

.NET 8+ is required.

Architecture Notes

  • Uses low-level P/Invoke to call GTK and WebKitGTK APIs directly.
  • IntPtr-based interop, with manual GCHandle pinning to prevent delegate collection.
  • No third-party UI frameworks — clean low-level interop only.
  • Compatible with Linux desktops, and potentially usable via WSL/X with X-server (not officially tested).

WebViewConfig Fields (summary)

Field Type Description
StartUri Uri The initial web address to load
WindowTitle string Window title text
Width/Height int Default window size
AllowSelection bool Allow text selection in the WebView
StrictMode bool Restrict navigation to the base URI
DebugMode bool Enable WebKit developer tools
SplashFilename string? Optional path to loading animation (GIF)
WindowPosition Gtk.WindowPosition GTK window placement enum

License

This project is licensed under the GNU General Public License v3.0 (GPL-3.0).

You are free to use, modify, and distribute this software — but any distributed binaries or derived works must also be open-sourced under the same license.

TL;DR

If you use this in your own project and distribute it — you must also share your source code under GPL-3.0.

Full license text is available in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.html

Author

Jackhammer88 C# developer, interop enjoyer, and fan of unsafe elegance.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.2.0 216 4/7/2025
0.1.0 129 4/6/2025