Skip to content

Commit ce7b4c4

Browse files
authored
Merge pull request #21593 from ajpinedam/chore/enable.corewebview2.eventargs.method
2 parents 2adb6bf + c40207f commit ce7b4c4

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/Uno.UI/UI/Xaml/Controls/WebView/Core/CoreWebView2WebMessageReceivedEventArgs.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
using System;
2+
using System.Text.Json;
3+
using Uno.Foundation.Logging;
4+
15
namespace Microsoft.Web.WebView2.Core;
26

37
/// <summary>
@@ -21,6 +25,23 @@ internal CoreWebView2WebMessageReceivedEventArgs(string webMessageAsJson)
2125
/// <returns></returns>
2226
public string TryGetWebMessageAsString()
2327
{
24-
throw new global::System.NotImplementedException("The member string CoreWebView2WebMessageReceivedEventArgs.TryGetWebMessageAsString() is not implemented. For more information, visit https://aka.platform.uno/notimplemented?m=string%20CoreWebView2WebMessageReceivedEventArgs.TryGetWebMessageAsString%28%29");
28+
if (string.IsNullOrWhiteSpace(WebMessageAsJson))
29+
{
30+
return WebMessageAsJson;
31+
}
32+
33+
try
34+
{
35+
return JsonSerializer.Deserialize<string>(WebMessageAsJson);
36+
}
37+
catch (Exception)
38+
{
39+
if (this.Log().IsEnabled(LogLevel.Warning))
40+
{
41+
this.Log().Warn("The message could not be deserialized to a string.");
42+
}
43+
44+
return null;
45+
}
2546
}
2647
}

0 commit comments

Comments
 (0)