kekyo / DupeNukem

WebView attachable full-duplex asynchronous interoperable independent messaging library between .NET and JavaScript.
Apache License 2.0
18 stars 0 forks source link

Does this library could be used to substitute AddHostObjectToScript functionality? #22

Open GitClickOk opened 4 months ago

GitClickOk commented 4 months ago

This is not an issue report, this is a question.

Currently, AddHostObjectToScript is broken for WinUI3. You can see some of these reports here:

https://learn.microsoft.com/en-us/answers/questions/1291522/using-addhostobjecttoscript-in-maui-apps https://github.com/dotnet/maui/issues/9424 https://github.com/MicrosoftEdge/WebView2Feedback/issues/2754

In my quests, I found this library that looks like that could be used to replace it. Am I correct?

kekyo commented 4 months ago

@GitClickOk Thanks reached out DupeNukem!

From what I can imagine you are thinking, the answer is probably "yes". I don't understand the details of each issue you've raised, but what we're trying to do with DupeNukem is:

In order to achieve this on MAUI, additional work is required because there is a functional deficiency in MAUI's WebView (there is no abstracted interface or implementation for sending messages from JavaScript to the .NET side).

The sample code achieves this, so I recommend trying it out as is (I don't have an iOS environment, so the sample code only implements it for Windows and Android, but I think it should be possible to implement the same thing for iOS WebView).

https://github.com/kekyo/DupeNukem/blob/main/samples/DupeNukem.Maui/Platforms/Windows/JavaScriptMultiplexedWebViewHandler.cs#L26

The reason I started this project in the first place was because I wanted to solve very slow progress of asynchronous support in WebView2 and the headaches I had with other WebView environments every time :)

https://github.com/MicrosoftEdge/WebView2Feedback/issues/75#issuecomment-1063709945

GitClickOk commented 4 months ago

Thanks, @kekyo! I will try it.

GitClickOk commented 4 months ago

@kekyo, by the way, what about the support of BlazorWebView from Maui? I'm checking the compatibility of this, I am pretty optimistic about it, but for now I got this issue: https://github.com/kekyo/DupeNukem/issues/18.

I'm not sure if I should try work directly with BlazorWebView, or the underling WebView (for example, for Windows I can do like WebView2 webView = (WebView2)blazorWebView.Handler.PlatformView;)

Just to be sure that we are in the same page, the BlazorWebView that I am talking is when you create a new ".NET MAUI Blazor Hybrid App" project in Visual Studio 2022. Then, in MainPage.xaml/MainPage.xaml.cs you can see the BlazorWebView there.

Thanks!