1

I want processHTML to be triggered after the webpage is done loading. I think I need:

document.load = 

for this. But I don't know the correct syntax for how to put it in loadUrl:

    class JavaScriptTokenSubstractInterface {
        @JavascriptInterface
        @SuppressWarnings("unused")
        fun processHTML(html: String) {
            Log.d("","html shown is loading and not the result.")
        }
    }

    val webView: WebView = findViewById(R.id.webView)
    webView.settings.javaScriptEnabled = true
    webView.settings.useWideViewPort = true
    webView.requestFocus(View.FOCUS_DOWN)
    webView.addJavascriptInterface(JavaScriptTokenSubstractInterface(), "HTMLOUT")
    webView.webViewClient = object : WebViewClient() {

        override fun onPageFinished(webView: WebView?, url: String?) {
            super.onPageFinished(webView, url)
            Thread.sleep(3000)
            webView?.loadUrl("javascript:window.HTMLOUT.processHTML('<html>'+document.getElementsByTagName('html')[0].innerHTML+'</html>');")
        }
    }

    webView.loadUrl("www.someWebPageThatIsLoading.nl")

What happens: 1. The loading of the page is shown 2. processHTML is triggered and it shows the HTML of the loading page 3. A few seconds go by and the page is done loading

processHTML should be triggered after the loading is done.

Jim Clermonts
  • 1,694
  • 8
  • 39
  • 94

0 Answers0