Skip to content

Evaluating javascript in MAUI WebView on IOS returns NULL #20288

@VictorHopmans

Description

@VictorHopmans

Description

We're using the method EvaluateJavaScriptAsync() from the MAUI WebView to inject javascript in a website like mijn.overheid.nl to obtain the innerHTML. However on iOS the result is always NULL. When trying this with a website like google.com we get the expected result (the innerHtml). When executing the method on Android with mijn.overheid.nl we also will get a result back which is not null.
We talked about this issue with @jfversluis on 25 January 2024, and he provided us with the workaround mentioned below.

Steps to Reproduce

  1. Start the reproduction project from the reproduction project repository on iOS and run it.
  2. The initial page will show a MAUI WebView with mijn.overheid.nl loaded. Below the WebView there is a button with the text 'Click Me', Click this button.
  3. The Label above the WebView (and below the text 'Hello, World!') will show the result obtained from the method EvaluateJavaScriptAsync(). This label will be empty as the result is NULL.

Link to public reproduction project repository

https://github.com/VictorHopmans/MauiAppTestWebView

Version with bug

8.0.6

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

iOS 17

Did you find any workaround?

#if
IOS || MACCATALYST var resultios = await (webView.Handler.PlatformView as WebKit.WKWebView).EvaluateJavaScriptAsync("document.documentElement.innerHTML"); var result = resultios.ToString();
#else
// en dan javascript injecteren. // Voor deze overheidssites is het result altijd NULL op iOS (op Android wordt de javascript wel uitgevoerd) var result = await webView.EvaluateJavaScriptAsync("document.documentElement.innerHTML");
#endif

Relevant log output

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions