0

enter image description here

This topic was raised and discussed hundreds of times. None of them correpond to the case I am facing.Please read below before answering.

I want to use WebView do get some info received from a server response and displayed in WebView but after embedded javascript execution. The wanted info can change in server at any time, purpose is to store this info locally on client side post requests to update it on on-demand basis.

I use WebChromeClient to determine when page is loaded (onProgressChanged = 100%) and JavaScriptInterface to get the HTML content, but I get the source code (with javascripts not executed yet).

The info I want to catch is available only after javascripts execution. Please see attached diagram, it may help to clarify my concern.

If someone was faced to similar issue I would appreciate to know how it was resolved. Thanks

MaxV
  • 2,601
  • 3
  • 18
  • 25
agray
  • 1
  • 2

1 Answers1

0

If you know when that JSON arrives on the page, then you can use WebView.evaluateJavascript and run javascript to extract the HTML.

According to https://stackoverflow.com/a/35917295/2921519 HTML extraction can be done by

new XMLSerializer().serializeToString(document)

If you need the javascript to notify the Android side proactively when the page content changes, then you will need to add a javascript interface according to https://developer.android.com/guide/webapps/webview#BindingJavaScript

Maurice Lam
  • 1,577
  • 9
  • 14
  • Thank you for your suggestion, unfortunately all URL are the same (except the one calling the server). The point is not how, but when I should inject javascript in WebView to get the html content. Other option is to use HttpClient to intercept JSON data in the server response, but the problem is the same, there is no specific event to use to invoke getHttp. – agray Jan 14 '21 at 12:45