Android Question Uncaught TypeError in B4A.CallSub

Discussion in 'Android Questions' started by Syd Wright, Feb 10, 2019.

  1. Syd Wright

    Syd Wright Active Member Licensed User

    I am trying to read the source of a webpage. It needs to be done by first opening the URL in a WebView (because it has to execute a Javascript) and then wait for the Webview Pagefinished event. Here is my B4A project and my Class:
    'Activity module:
    Sub Process_Globals
    End Sub

    Sub Globals
    Dim SourceWeb1 As String
    Dim Webbron1 As WebBron          'See My Class
    End Sub

    Sub Activity_Create(FirstTime As Boolean)
        SourceWeb1 = 
    End Sub

    Sub Activity_Resume
    End Sub

    Sub Activity_Pause (UserClosed As Boolean)
    End Sub
    'Class Module "WebBron":
    Sub Class_Globals
    Dim WebView1 As WebView
    Dim WebviewExtras1 As WebViewExtras
    Dim WebSettings1 As WebViewSettings
    Dim SourceText1 As String
    End Sub

    Public Sub Initialize
        WebSettings1.setAppCacheEnabled  (WebView1,
    True)    'Apparently needed!
        WebSettings1.setSavePassword     (WebView1,True)
    End Sub

    Sub WebView1_PageFinished (Url As String)
    5000)     'Delay Needed because a javascript on the website needs time to complete!
        Dim Javascript As String
    "B4A.CallSub('HTML_Kerk1', true, document.activeElement.outerHTML)"
        WebviewExtras1.executeJavascript(WebView1, Javascript)
    End Sub   

    Sub HTML_Kerk1(HTML As String)
        SourceText1 = HTML
    End Sub
    My "WebBron" Class works fine in the above small trial project, but in my main, very large project (with more than 35000 lines of code) I get this error:
    Uncaught TypeError: B4A.CallSub is not a function in https://www.kerk...../ (Line: 1).
    It occurs with any URL. The problem is probably related to WebViewExtras.
    How can this be resolved?
    Last edited: Feb 10, 2019
  2. Syd Wright

    Syd Wright Active Member Licensed User

    I have found the cause (but not the solution): The error also occurs in my small project as soon as I add:
    <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="26"/>
    to the manifest.
    Is webviewextras not compatible with android version 26 or higher?

    it only works with
    <uses-sdk android:minSdkVersion="4" android:targetSdkVersion="14"/>
    <uses-sdk android:minSdkVersion="4"

    in the manifest. Any ideas how to solve this?

    I also tried adding:
    <uses-permission android:name="android.permission.INTERNET"/>
    just in case, but no success
    Last edited: Feb 12, 2019
  3. Syd Wright

    Syd Wright Active Member Licensed User

    Problem solved: I was using WebViewExtras version 1.30
    With version 1.42 everything is OK.
    I am pleased about this, because I tried using WebViewExtras2 (version 2.20), but couldn't get it to run the Javascript as shown in post #1 (under Webview1_PageFinished).
  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