Get html content from webview in Android (using Xamarin with C#)
<p>What I want to do is basically what was answered here:</p>

<p><a href="https://stackoverflow.com/questions/8200945/how-to-get-html-content-from-a-webview">how to get html content from a webview?</a></p>

<p>However, I'm working with Xamarin in C#, and the code given in the top answer is in java. I tried to translate it to C# as follows:</p>

<pre><code>  public class LoginWebViewController : Activity
{
    WebView localWebView;

    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);

        SetContentView(Resource.Layout.WebView);

        localWebView = FindViewById&lt;WebView&gt;(Resource.Id.LocalWebView);
        localWebView.SetWebViewClient(new JustWebViewClient());

        localWebView.LoadUrl(LoginOperations.GetTPLoginUrl());

        localWebView.Settings.JavaScriptEnabled = true;
        localWebView.AddJavascriptInterface(new MyJavaScriptInterface(this), "HtmlViewer");


    }

    class MyJavaScriptInterface
    {
        private Context ctx;

        MyJavaScriptInterface(Context ctx)
        {
            this.ctx = ctx;
        }

        public void showHTML(String html)
        {
            Console.WriteLine(html);
        }

    }
}
</code></pre>

<p>But I get the following error: </p>

<p><a href="https://i.imgur.com/gmMOrlR.png" rel="nofollow noreferrer"><img src="https://i.imgur.com/gmMOrlR.png" alt="enter image description here"></a></p>

<p>I tried changing the class to public but it still gives the same error. What is wrong?</p>

<p>Additional code: </p>

<pre><code> public class MyWebViewClient : WebViewClient
{
    public override void OnPageFinished(WebView view, String url)
    {
        base.OnPageFinished(view,url);

        Console.WriteLine("DONE LOADING PAGE");

        view.LoadUrl("javascript:HtmlViewer.showHTML" +
                "('&lt;html&gt;'+document.getElementsByTagName('html')[0].innerHTML+'&lt;/html&gt;');");


    }
}
</code></pre>