Android Question Get html code from webview JavaScript

Discussion in 'Android Questions' started by Salmancio Riquelme Cerezo, Jun 12, 2019.

  1. Salmancio Riquelme Cerezo

    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:
    Code:
    WebView1.JavaScriptEnabled = True
    WebViewExtras1.JavaScriptEnabled = 
    True
    Can someone help me?

    Thanks.
     
  2. JohnC

    JohnC Well-Known Member Licensed User

    Please provide your code that attempts to gets the HTML code from webview.
     
  3. Salmancio Riquelme Cerezo

    Salmancio Riquelme Cerezo New Member Licensed User

    Code:
    Sub Globals     
       
    Private WebView1 As WebView
       
    Dim WebViewExtras1 As WebViewExtras  
       
    Dim WebChromeClient1 As DefaultWebChromeClient
       
    Dim JavascriptInterface1 As DefaultJavascriptInterface
    End Sub
    In main routine

    Code:
    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: Jun 13, 2019
  4. JohnC

    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/t...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.
     
    José J. Aguilar likes this.
  5. JohnC

    JohnC Well-Known Member Licensed User

    Keep in mind the older example code on those pages might have slightly different syntax, for example:
    Code:
    The old way:

    WebViewExtras1.executeJavascript(webview1, Javascript)

    The new way:

    WebViewExtras1.executeJavascript(Javascript)
     
  6. Salmancio Riquelme Cerezo

    Salmancio Riquelme Cerezo New Member Licensed User

    Solved with.

    Code:
    Javascript = "B4A.CallSub('ProcessHTML', false, document.body.innerHTML)"
    Thanks.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice