diff --git a/HybridWebView/HybridWebView.cs b/HybridWebView/HybridWebView.cs
index 5f7d001..8e1d565 100644
--- a/HybridWebView/HybridWebView.cs
+++ b/HybridWebView/HybridWebView.cs
@@ -220,7 +220,7 @@ public virtual async Task OnProxyRequestMessage(HybridWebViewProxyEventArgs args
var paramObjectValues =
invokeData.ParamValues?
- .Zip(invokeMethod.GetParameters(), (s, p) => JsonSerializer.Deserialize(s, p.ParameterType))
+ .Zip(invokeMethod.GetParameters(), (s, p) => s == null ? null : JsonSerializer.Deserialize(s, p.ParameterType))
.ToArray();
return invokeMethod.Invoke(JSInvokeTarget, paramObjectValues);
diff --git a/HybridWebView/KnownStaticFiles/HybridWebView.js b/HybridWebView/KnownStaticFiles/HybridWebView.js
index 54e4bfc..806dce0 100644
--- a/HybridWebView/KnownStaticFiles/HybridWebView.js
+++ b/HybridWebView/KnownStaticFiles/HybridWebView.js
@@ -20,7 +20,10 @@ window.HybridWebView = {
paramValues = [paramValues];
}
for (var i = 0; i < paramValues.length; i++) {
- paramValues[i] = JSON.stringify(paramValues[i]);
+ // Let 'null' and 'undefined' be passed as-is, but stringify all other values
+ if (paramValues[i] != null) {
+ paramValues[i] = JSON.stringify(paramValues[i]);
+ }
}
}
diff --git a/MauiCSharpInteropWebView/MainPage.xaml.cs b/MauiCSharpInteropWebView/MainPage.xaml.cs
index 719e434..9a528dd 100644
--- a/MauiCSharpInteropWebView/MainPage.xaml.cs
+++ b/MauiCSharpInteropWebView/MainPage.xaml.cs
@@ -175,7 +175,7 @@ private void WriteToLog(string message)
private sealed class MyJSInvokeTarget
{
- private MainPage _mainPage;
+ private readonly MainPage _mainPage;
public MyJSInvokeTarget(MainPage mainPage)
{
@@ -187,6 +187,16 @@ public void CallMeFromScript(string message, int value)
_mainPage.WriteToLog($"I'm a .NET method called from JavaScript with message='{message}' and value={value}");
}
+ public void CallEmptyParams(string thisIsNull, int thisIsUndefined)
+ {
+ _mainPage.WriteToLog($"I'm a .NET method called from JavaScript with null='{thisIsNull}' and undefined={thisIsUndefined}");
+ }
+
+ public void CallNoParams()
+ {
+ _mainPage.WriteToLog($"I'm a .NET method called from JavaScript with no params");
+ }
+
///