class MyJavaScriptInterface
{
@SuppressWarnings("unused")
public void processHTML(String html)
{
// process html
}
}
final WebView browser = (WebView)findViewById(R.id.browser);
browser.getSettings().setJavaScriptEnabled(true);
browser.addJavascriptInterface(new MyJavaScriptInterface(), "HTMLOUT");
browser.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url)
{
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
browser.loadUrl("javascript:window.HTMLOUT.processHTML('<html>'+document.getElementsByTagName('html')[0].innerHTML+'</html>');");
}
}, 2000);
}
});
browser.loadUrl("someurl");
What I want to achieve is to call the processHTML method only when all the javascripts are loaded on the page (usually 2-3 seconds after onPageFinished occurred).
The rude solution I found is to use a delayed handler but i would ask if there is a way to know when all the scripts are loaded.
I could loop that handler until I don't find the info I want but it doesn't seem to be an elegant solution.