Android WebViewClient's ShouldInterceptRequest is never called in MAUI WebView
See original GitHub issueDescription
Android WebViewClient’s ShouldInterceptRequest is never called in MAUI WebView
Steps to Reproduce
1.create a maui demo;
2.copy the following code to MauiProgram.cs:
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
})
.ConfigureMauiHandlers(handlers =>
{
handlers.AddHandler<Microsoft.Maui.Controls.WebView, ProblemHandler2>();
});
return builder.Build();
}
}
internal class ProblemHandler1 : WebViewHandler
{
protected override Android.Webkit.WebView CreatePlatformView()
{
var wv = base.CreatePlatformView();
wv.SetWebViewClient(new CustomWebClient());
return wv;
}
}
internal class ProblemHandler2 : WebViewHandler
{
protected override Android.Webkit.WebView CreatePlatformView()
{
var wv = new Android.Webkit.WebView(Android.App.Application.Context);
wv.SetWebViewClient(new CustomWebClient());
return wv;
}
}
internal class CustomWebClient : WebViewClient
{
public override WebResourceResponse ShouldInterceptRequest(Android.Webkit.WebView view, IWebResourceRequest request)
{
Debugger.Break();
Debug.WriteLine(request.Url.ToString());
return base.ShouldInterceptRequest(view, request);
}
}
MainPage.xaml.cs
public partial class MainPage : ContentPage
{
int count = 0;
public MainPage()
{
InitializeComponent();
WebViewHandler.Mapper.AppendToMapping("MyHandler", (handler, view) =>
{
#if ANDROID
var xWv = handler.PlatformView;
// For ProblemHandler2, this is needed to actually navigate:
xWv.LoadUrl("https://www.google.com/");
#endif
});
this.wv.Source = "https://www.google.com/";
}
}
3.build and deploy this demo to android device. (I only tested on android 13 emulator )
Link to public reproduction project repository
https://github.com/datvm/DemoMauiWvClient
Version with bug
Unknown/Other (please specify)
Last version that worked well
Unknown/Other
Affected platforms
Android, I was not able test on other platforms
Affected platform versions
Android 13
Did you find any workaround?
No response
Relevant log output
No response
Issue Analytics
- State:
- Created a year ago
- Reactions:5
- Comments:25 (9 by maintainers)
Top Results From Across the Web
Android WebViewClient's ShouldInterceptRequest is never ...
I realized a problem: Setting MAUI WebView 's Source property no longer navigates the real Android WebView: WebViewHandler.Mapper.
Read more >How to set custom WebViewClient on Android handler
I am working on brand new Maui app, and would like to know how I can use a custom WebViewClient on Android, using...
Read more >Intercept all requests in WebView on Android | by Andy Wang
I have a requirement that all HTTP requests from a WebView on Android need to be handled locally. For example, providing assets for...
Read more >WebViewClient | Android Developers
Quickly bring your app to life with less code, using a modern declarative approach to UI, and the simplicity of Kotlin. ... Start...
Read more >JS/.NET interact on MAUI WebView : r/dotnetMAUI
NET interactions in a WebView on both Android and iOS. ... I tried to built it with handlers, but than the OnPageFinished is...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Still no reply from the team about this. It would be nice to at least get a rough timeline for a fix. 1 month, 6 months, longer??
WebViewClient.OnPageFinished(Android.Webkit.WebView platformView, string url) is NOT being called as well.