Android Question Uncaught TypeError in B4A.CallSub

Syd Wright

Well-Known 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)
    WebviewExtras1.addJavascriptInterface(WebView1, "B4A")
End Sub

Sub WebView1_PageFinished (Url As String)
    Sleep(5000)     'Delay Needed because a javascript on the website needs time to complete!
    Dim Javascript As String
    Javascript="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:

Syd Wright

Well-Known 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:

Syd Wright

Well-Known 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).