Eilon / MauiHybridWebView

MIT License
206 stars 45 forks source link

Exception:Value cannot be null. (Parameter 'json') #27

Closed beethmon closed 7 months ago

beethmon commented 1 year ago

It works but throw this Exception: Value cannot be null. (Parameter 'json') my cs code:

try
{
                await hybridWebView.InvokeJsMethodAsync<int>("TestFun", 123, 456);
}
catch (Exception ex)
{
                Debug.WriteLine(ex.Message);
}

my xaml code:

<ContentPage
    x:Class="ActionTracer.MainPage"
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:ejl="clr-namespace:HybridWebView;assembly=HybridWebView">
    <ejl:HybridWebView
        x:Name="hybridWebView"
        HybridAssetRoot="hybrid"
        MainFile="index.html"
        MaximumWidthRequest="600"
        MinimumHeightRequest="350"
        RawMessageReceived="hybridWebView_RawMessageReceived" />
</ContentPage>

my html code:

<!DOCTYPE html>
<html lang="">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <meta name="viewport" content="width=device-width, initial-scale=1.0, 
minimum-scale=1.0, maximum-scale=1.0, viewport-fit=cover, user-scalable=no">
    <link rel="icon" href="<%= BASE_URL %>favicon.ico">
    <title>
        <%= htmlWebpackPlugin.options.title %>
    </title>
    <script src="_hwv/HybridWebView.js"></script>
</head>
<script>
    function TestFun(value1, value2) {
        alert(value1 + " " + value2);
    }
</script>
Eilon commented 1 year ago

I'll take a look!

beethmon commented 1 year ago

I'll take a look!

Thanks,I fix this problem,cause I forgot return but I had another question Can I disable Android WebView TextZoom on this? I can set it by use blazorWebView in the Init event:

                private void blazorWebView_BlazorWebViewInitialized(object sender, Microsoft.AspNetCore.Components.WebView.BlazorWebViewInitializedEventArgs e)
                {
        #if ANDROID
                    e.WebView.Settings.TextZoom = 100;
                   e.WebView.Settings.SetSupportZoom(false);
        #endif
                }

but It seems private in your library =>private Android.Webkit.WebView PlatformWebView

Eilon commented 7 months ago

For the NullRef I have a fix here: #44

And for the initialization/zoom issue I logged #45 to track supporting that.