Android Question Get html code from webview JavaScript

Salmancio Riquelme Cerezo

New Member
Licensed User
Hello.

When I try to get htlm code, from a rendered google maps url in webview, with JSInterface, and WebChromeClient (Webviewextras2) i get this source code:

When you have eliminated the JavaScript, whatever remains must be an empty page.

I have:
B4X:
WebView1.JavaScriptEnabled = True
WebViewExtras1.JavaScriptEnabled = True
Can someone help me?

Thanks.
 

JohnC

Well-Known Member
Licensed User
Please provide your code that attempts to gets the HTML code from webview.
 

Salmancio Riquelme Cerezo

New Member
Licensed User
B4X:
Sub Globals     
   Private WebView1 As WebView
   Dim WebViewExtras1 As WebViewExtras  
   Dim WebChromeClient1 As DefaultWebChromeClient
   Dim JavascriptInterface1 As DefaultJavascriptInterface
End Sub
In main routine

B4X:
   WebView1.JavaScriptEnabled = True      
   WebViewExtras1.Initialize(WebView1)
   WebViewExtras1.JavaScriptEnabled = True      
   JavascriptInterface1.Initialize      
   WebViewExtras1.addJavascriptInterface(JavascriptInterface1, "B4A")
   WebChromeClient1.Initialize("WebChromeClient1")
   WebViewExtras1.SetWebChromeClient(WebChromeClient1)   
   WebView1.LoadUrl("https://www.google.es/maps")

Sub WebView1_PageFinished (Url As String)  
   Dim Javascript As String
   Javascript = "B4A.CallSub('ProcessHTML', false, document.documentElement.outerHTML)"
   WebViewExtras1.executeJavascript(Javascript)  
End Sub

Sub ProcessHTML(Html As String)
  File.WriteString(File.DirRootExternal,"sample.html",Html)
End Sub
 
Last edited:

JohnC

Well-Known Member
Licensed User
OK, some things to try:

1) Try loading a simple webpage that does not have any/much javascript in it to see if that works. There could be a conflict in the javascript.
2) You have a lot more lines of code doing things with the webview control then the examples on these two pages:

https://www.b4x.com/android/forum/threads/getting-the-source-code-of-a-webpage-with-webview-and-webviewextras.34418/
https://www.b4x.com/android/forum/threads/read-content-from-html-to-string.19408/#post-111864

3) I would read through the above two threads and try their simpler example code on a simple webpage, then if it works, then try the google page.
 

JohnC

Well-Known Member
Licensed User
Keep in mind the older example code on those pages might have slightly different syntax, for example:
B4X:
The old way:

WebViewExtras1.executeJavascript(webview1, Javascript)

The new way:

WebViewExtras1.executeJavascript(Javascript)
 
Top