1

.Net 8 Maui App, running/debugging on Mac OS.

What I am trying to do:

I am trying to get data from a web view’s local storage. I am expecting serialized json to be returned by localStorage.getItem(‘dps’) but instead when trying to get the string data after performing a ToString() on the NSObject what it gives me is 0円0円....

Steps to reproduce:

xaml markup

<WebView x:Name="webview" HeightRequest="300" WidthRequest="500" Source="https://app.hosted.onprem">
</WebView> 

button to initiate retrieval of data from localStorage

<Button x:Name="btnLoggedIn" WidthRequest="150" Clicked="btnLoggedIn_Clicked" Text="Validate" />

code behind

private async void btnLoggedIn_Clicked(object sender, EventArgs e)
{
 try
 {
 /*
 //Tried to use generic approach of:
 //webview.EvaluateJavaScriptAsync("localStorage.getItem('dps');");
 //which always returned null.
 */
 var macosResults = await (webview.Handler.PlatformView as WebKit.WKWebView).EvaluateJavaScriptAsync("localStorage.getItem('dps');");
 var stringResults = macosResults.ToString();
 }
 catch (Exception ex)
 {
 
 }
}

If I inspect the NSObject in the debugger I see the value I need and can copy it from there but if I try assigning the value programmatically, it is garbage, 0円0円...

results

What am I missing/doing wrong?

I am ensuring that I am properly waiting for the call to complete and have verified the data exists in local storage and can see it and access it in the debugger.

asked Jun 10, 2025 at 11:54
1
  • Have you tried converting the object to string before sending it, e.g. EvaluateJavaScriptAsync("JSON.stringify(localStorage.getItem('dps'));") ? Commented Jun 11, 2025 at 6:02

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.