Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebViewHandler OnProgressChanged not called on Android when loading/navigating WebView #24812

Open
LeoJHarris opened this issue Sep 18, 2024 · 2 comments
Labels
p/2 Work that is important, but is currently not scheduled for release platform/android 🤖 s/needs-repro Attach a solution or code which reproduces the issue t/bug Something isn't working
Milestone

Comments

@LeoJHarris
Copy link

Description

OnProgressChanged is not being called using the following Handler setup and loading WebView

public class CustomWebViewHandler : WebViewHandler
{
    private CustomWebView? Element => VirtualView as CustomWebView;

    protected override void ConnectHandler(Android.Webkit.WebView platformView)
    {
        base.ConnectHandler(platformView);

        if (Element is not null)
        {
            platformView.SetWebChromeClient(new CustomWebChromeClient(Element));
        }

        platformView.Settings.JavaScriptEnabled = true;
    }

    private class CustomWebChromeClient(CustomWebView customWebView) : WebChromeClient
    {
        public override void OnProgressChanged(Android.Webkit.WebView? view, int newProgress) => customWebView.UpdateProgress(Math.Round((double)newProgress / 100, 2));
    }
}

Steps to Reproduce

No response

Link to public reproduction project repository

No response

Version with bug

8.0.90 SR9

Is this a regression from previous behavior?

No, this is something new

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 14

Did you find any workaround?

WebViewRenderer still works which I've rolled back to.

public class CustomWebViewHandler(Android.Content.Context context) : WebViewRenderer(context)
{
    protected override void OnElementChanged(ElementChangedEventArgs<WebView> e)
    {
        base.OnElementChanged(e);

        if (Control == null)
        {
            return;
        }

        if (e.NewElement is CustomWebView customWebView)
        {
            Control.SetWebChromeClient(new CustomWebChromeClient(customWebView));
        }

        Control.Settings.JavaScriptEnabled = true;
    }

    private class CustomWebChromeClient(CustomWebView customWebView) : WebChromeClient
    {
        private readonly CustomWebView _customWebView = customWebView;

        public override void OnProgressChanged(Android.Webkit.WebView view, int newProgress) => _customWebView.UpdateProgress(System.Math.Round((double)newProgress / 100, 2));
    }
}

Relevant log output

No response

@LeoJHarris LeoJHarris added the t/bug Something isn't working label Sep 18, 2024
@ninachen03
Copy link

Could you provide us with a sample project so we can investigate it further? Looking forward to your reply!

@tj-devel709 tj-devel709 added the s/needs-repro Attach a solution or code which reproduces the issue label Sep 18, 2024
Copy link
Contributor

Hi @LeoJHarris. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md

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.

@tj-devel709 tj-devel709 added this to the Backlog milestone Sep 18, 2024
@tj-devel709 tj-devel709 added the p/2 Work that is important, but is currently not scheduled for release label Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p/2 Work that is important, but is currently not scheduled for release platform/android 🤖 s/needs-repro Attach a solution or code which reproduces the issue t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants