Android webview is only loading "about:blank" when using custom WebviewClient with .Net 7.0
Description
Creating a custom WebviewClient and modifying the mapping for the webview to use it prevents the webview from loading any web page other than "about:blank".
Example :

Steps to Reproduce
- Create a new MAUI app
- Add a WebView
- Set the Webview source
- Create a custom WebviewClient
- Modify the mapping to assign an instance of your WebviewClient to your webview
- Start the app
- See the blank page
Link to public reproduction project repository
https://github.com/Mackly/MauiApp1.git
Version with bug
7.0 Release Candidate 2
Last version that worked well
Unknown/Other
Affected platforms
Android
Affected platform versions
Android 9 and up
Did you find any workaround?
Not yet, still searching, but I'm starting to run out of ideas. Hence, this bug report.
Relevant log output
No response
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.
@Mackly yea we have some logic in the handler that should probably be moved into MauiWebViewClient :-/
If you copy the code here does it fix the problem for you?
https://github.com/dotnet/maui/blob/main/src/Core/src/Handlers/WebView/WebViewHandler.Android.cs#L24-L36
Hi @PureWeen. Thanks for the suggestion. Although I'm not sure where I should add this piece of code.
Is it possible that the problem is related to this part of the code as it might not be called because I've modified the mapping. Thus no page can be loaded because of the check here and since _webViewClient is null ?
I have found a workaround. It seems the problem does come from what I am mentioning in my last comment (unless I am missing something). The workaround is to simply add that line before setting the custom web client. Thus initializing the handler with a webclient and making sure _webViewClient value is not null. It is not the best solution as it requires creating an unused "dummy" webclient but it works for now.
Another workaround is to not inherit from Microsoft.Maui.Handlers.WebViewHandler, but to inherit from its base class: ViewHandler<IWebView, Android.Webkit.WebView> That was our only workaround since the ModifyMapping() workaround didn't quite work out for us.
I also would like more insight into the commit that allegedly (?) introduced this bug. Why was a null check to "_webViewClient" added if the private field is never set in the first place? How can it ever not be null?
I get that WebView interaction seems to be low priority for Microsoft, but this workaround has been a thorn in our sides for several months now :/
WebView Source property is non functional on Android regardless if a custom web view client is used. It times out after a few minutes regardless of the url. This worked a few months ago. Permissions are correct.
Is this a bug or by design? Probably should add this to list of release QA checklist for Android.
I have found a workaround. It seems the problem does come from what I am mentioning in my last comment (unless I am missing something). The workaround is to simply add that line before setting the custom web client. Thus initializing the handler with a webclient and making sure _webViewClient value is not null. It is not the best solution as it requires creating an unused "dummy" webclient but it works for now.
Adding your code I get lots of namespace and references not found. Is there another step?
Never mind, looking through your project I see another class that has to be added in the Androi folder.
Unfortunately, the Source property still is non-functional and times out after a few minutes. Is there something else that I may have missed?
Verified this issue with Visual Studio Enterprise 17.7.0 Preview 1.0. Not repro on android platform with above project.
https://github.com/Mackly/MauiApp1.git
Hi @Mackly. We have added the "s/try-latest-version" label to this issue, which indicates that we'd like you to try and reproduce this issue on the latest available public version. This can happen because we think that this issue was fixed in a version that has just been released, or the information provided by you indicates that you might be working with an older version.
You can install the latest version by installing the latest Visual Studio (Preview) with the .NET MAUI workload installed. If the issue still persists, please let us know with any additional details and ideally a reproduction project provided through a GitHub repository.
This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.