0

Recently I faced a pretty annoying issue, So I am loading an iframe (youtube video) in my webview and checking if the WebView has finished loading, it works for other contents but not for iFrame, it shows the page loading finished way before the iFrame is fully loaded. I tried in both SetWebChromeClient and SetWebViewClient - In both cases, loading finishes way before the iFrame finishes loading.

I have simple WebView

webView.LoadDataWithBaseURL("https://.", IFRAME_HERE, "text/html", "UTF-8", null);

So Setting webView.SetWebViewClient(new WebViewClientClass()); with the following

public override void OnPageStarted(WebView view, string url, Bitmap favicon)
            {
                base.OnPageStarted(view, url, favicon);
                Log.Info("101029", "STARTED");
            }

            public override void OnPageFinished(WebView view, string url)
            {
                base.OnPageFinished(view, url);
                Log.Info("101029", "FINISHED");
            }

Or setting webView.SetWebChromeClient(new NewClient(ParentLayout, ContentLayout)) with the following

 public override void OnProgressChanged(WebView view, int newProgress)
            {
                base.OnProgressChanged(view, newProgress);
                if (newProgress == 100)
                {
                    Log.Info("101029", "Finished");                  
                }
                else
                {
                    Log.Info("101029", newProgress.ToString());
                }
            }

Same things happen, Webview shows loading is finished while the iFrame is still loading. How do I tackle the loading of iFrames to accurately get when the iFrame has finished loading? any idea? Cheers

EDIT:

I also tried the following for `` (Still no luck)

internal class WebViewClientClass : WebViewClient
        {
            bool loadingFinished = true;
            bool redirect = false;                
            public override bool ShouldOverrideUrlLoading(WebView view, IWebResourceRequest request)
            {
                if (!loadingFinished)
                {
                    redirect = true;
                }

                loadingFinished = false;
                Android.Net.Uri url = request.Url;
                view.LoadUrl(url.ToString());
                return true;
            }

            public override void OnPageStarted(WebView view, string url, Bitmap favicon)
            {
                base.OnPageStarted(view, url, favicon);
                loadingFinished = false;
                Log.Info("101029", "loading started");
            }

            public override void OnPageFinished(WebView view, string url)
            {
                if (!redirect)
                {
                    loadingFinished = true;
                }

                if (loadingFinished && !redirect)
                {
                    base.OnPageFinished(view, url);
                    Log.Info("101029", "loading finised");
                }
                else
                {
                    redirect = false;
                }

            }
        }
Ali
  • 2,702
  • 3
  • 32
  • 54

0 Answers0