Giter Site home page Giter Site logo

blazorwebview's Introduction

BlazorWebView

A WebKitGTK WebView, utilizing Gir.Core, for running Blazor Hybrid applications on Linux without the need to compile a native library. It is analagous to the Winforms BlazorWebView or the WPF BlazorWebView, but for Linux instead of Windows.

Blazor Hybrid apps allow one to create Blazor desktop applications that uses the local machine's .NET runtime (not Blazor WASM), has full access to local resources (not sandboxed), and does not require hosting through a web server (e.g. Blazor server). It is just like any other desktop application written in C#, but uses Blazor and web technologies to implement the user interface.

Why?

Microsoft has decided to not support Maui on Linux, so there is currently no way to create Blazor Hybrid apps on Linux using only C#.

How?

BlazorWebView uses some of the same code as Steve Sanderson's WebWindow and leverages Microsoft's WebView infrastructure to get Blazor Hybrid working. However, it differs from WebWindow in that it doesn't require one to compile a native shared library in C++, instead utilizing Gir.Core to call into the native libraries. This has the benefit that, as long as the native libraries are installed on the Linux system, one only needs to use the dotnet CLI to build and run BlazorWebView.

Screenshot

Demonstration

Using a Linux terminal

git clone https://github.com/JinShil/BlazorWebView.git
cd BlazorWebView/WebKitGtk.Test
dotnet run

Using Visual Studio Code

On a Linux computer, simply open this repository in Visual Studio Code and press F5 to start a debug session.

Ubuntu 24.04 bwrap error fix

Running the demo project may fail with the following error on ubuntu 24.04:

bwrap: setting up uid map: Permission denied

This is due to Ubuntu developers deciding to use Apparmor to restrict the creation of user namespaces. To resolve this create a file named /etc/apparmor.d/bwrap with the following contents:

abi <abi/4.0>,
include <tunables/global>

profile bwrap /usr/bin/bwrap flags=(unconfined) {
  userns,

  # Site-specific additions and overrides. See local/README for details.
  include if exists <local/bwrap>
}

Followed by a reboot. (Note: this fix was found here)

Usage

See the project in WebKitGtk.Test for an example illustrating how to create a Blazor Hybrid application using the BlazorWebView.

You may need to install the following packages:

  • libadwaita-1-0
  • libwebkitgtk-6.0-4

Status

This project was tested on:

  • Windows Subsystem for Linux
  • Raspberry Pi Bullseye 64-bit
  • Debian Bullseye 64-bit.
  • Ubuntu 24.04 LTS desktop amd64

The root .vscode directory has the necessary configuration files to build, deploy, and debug a Raspberry Pi from a Debian Bullseyse 64-bit workstation PC.

blazorwebview's People

Contributors

czirok avatar jinshil avatar jpmikkers 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

blazorwebview's Issues

Running on Windows

Is it possible to run this project on Windows? (Because it seems to be based on Gtk)

Virtual keyboard

Does the underlying WebKitGTK provide an on-screen keyboard, or would the application need to provide its own? I'd be interested in whether BlazorWebView would work for a touchscreen embedded device.

Cannot run because DLLs not found

Exception has occurred: CLR/System.DllNotFoundException
An unhandled exception of type 'System.DllNotFoundException' occurred in Gtk-4.0.dll: 'Unable to load shared library 'libgtk-4.so.1' or one of its dependencies. In order to help diagnose loading problems, consider using a tool like strace. If you're using glibc, consider setting the LD_DEBUG environment variable:
/snap/dotnet-sdk/236/shared/Microsoft.NETCore.App/8.0.2/libgtk-4.so.1: cannot open shared object file: No such file or directory
/mnt/d/Development/Visual Studio Projects/BlazorWebView/WebKitGtk.Test/bin/Debug/net8.0/libgtk-4.so.1: cannot open shared object file: No such file or directory
/snap/core20/current/lib/x86_64-linux-gnu/libc.so.6: version GLIBC_2.33' not found (required by /lib/x86_64-linux-gnu/libgtk-4.so.1) /snap/dotnet-sdk/236/shared/Microsoft.NETCore.App/8.0.2/liblibgtk-4.so.1: cannot open shared object file: No such file or directory /mnt/d/Development/Visual Studio Projects/BlazorWebView/WebKitGtk.Test/bin/Debug/net8.0/liblibgtk-4.so.1: cannot open shared object file: No such file or directory /snap/dotnet-sdk/236/shared/Microsoft.NETCore.App/8.0.2/libgtk-4.so.1.so: cannot open shared object file: No such file or directory /mnt/d/Development/Visual Studio Projects/BlazorWebView/WebKitGtk.Test/bin/Debug/net8.0/libgtk-4.so.1.so: cannot open shared object file: No such file or directory /snap/dotnet-sdk/236/shared/Microsoft.NETCore.App/8.0.2/liblibgtk-4.so.1.so: cannot open shared object file: No such file or directory /mnt/d/Development/Visual Studio Projects/BlazorWebView/WebKitGtk.Test/bin/Debug/net8.0/liblibgtk-4.so.1.so: cannot open shared object file: No such file or directory' at System.Runtime.InteropServices.NativeLibrary.<LoadByName>g____PInvoke|2_0(UInt16* __libraryName_native, QCallAssembly __callingAssembly_native, Int32 __hasDllImportSearchPathFlag_native, UInt32 __dllImportSearchPathFlag_native, Int32 __throwOnError_native) at Gtk.Internal.ImportResolver.Resolve(String libraryName, Assembly assembly, Nullable1 searchPath)
at System.Runtime.InteropServices.NativeLibrary.LoadLibraryCallbackStub(String libraryName, Assembly assembly, Boolean hasDllImportSearchPathFlags, UInt32 dllImportSearchPathFlags)
at Gtk.Internal.Functions.Init()
at Gtk.Module.Initialize()
at WebKit.Module.Initialize()
at Program.Main(String[] args) in /mnt/d/Development/Visual Studio Projects/BlazorWebView/WebKitGtk.Test/Program.cs:line 12

Exception on fedora 38 / Thoughts on Gir.Core

Hi,

I tried your project on a current fedora 38 with dotnet 6 / 7 installed. Unfortunately it did not work out. It looks like the code in GtkSharp is hard coding an old webkitgtk library.

Unhandled exception. System.TypeInitializationException: The type initializer for 'WebKit.WebView' threw an exception.
 ---> System.DllNotFoundException: Webkit: libwebkit2gtk-4.0.dll, libwebkit2gtk-4.0.so.37, libwebkit2gtk-4.0.dylib, libwebkit2gtk-4.0.0.dll
   at GLibrary.Load(Library library)
   at WebKit.WebView..cctor()

As this project looks quite interesting, I wonder what your thoughts are in regard to base it on Gir.Core? Gir.Core supports Gtk4 and current WebKitGtk versions. It follows the binaries inside the current gnome Flatpak SDK. This allows to create Flatpaks which can be distributed via Flathub.

But the project and API is not complete or guaranteed to be stable, so it is quite possible that the APIs you are relying on are not yet generated or are even not supported anymore as there was some API break on WebKitGTK side.

As I'm actively working on Gir.Core, I would be interested in making the needed API available to you.

I created a small issue on my side gircore/gir.core#931 to keep your project in my mind in case you are not interested as I think it could benefit a lot of users. If you like, the project could even be part of Gir.Core itself as it looks like that not much code is needed maintenance wise.

Is that what you want?

https://github.com/tryphotino/photino.Blazor

Photino is a lightweight open-source framework for building native,
cross-platform desktop applications with Web UI technology.

Photino.Blazor builds on Photino.NET to add Blazor capabilities.

Photino uses the OSs built-in WebKit-based browser control for Windows, macOS and Linux. Photino is the lightest cross-platform framework. Compared to Electron, a Photino app is up to 110 times smaller! And it uses far less system memory too!

Child windows

Is there any guidance or pattern we should follow with respect to opening and managing child windows? Is this supported?

Support for Windows and macOS?

I hope this is not off-base, but I wonder if you'd consider adding support for Windows and/or macOS? Currently we have no single BlazorWebView solution working across all 3 platforms.

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.