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:
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?
B4X:
'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 = "https://www.kerkomroep.nl/#/kerken?is_live=true&orderBy=plaats"
Webbron1.Initialize
Webbron1.WebView1.LoadUrl(SourceWeb1)
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
B4X:
'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
WebView1.Initialize("WebView1")
WebSettings1.setAppCacheEnabled (WebView1,True) 'Apparently needed!
WebSettings1.setSavePassword (WebView1,True)
WebSettings1.setDOMStorageEnabled(WebView1,True)
WebviewExtras1.addJavascriptInterface(WebView1, "B4A")
WebviewExtras1.addWebChromeClient(WebView1,"WebViewExtras1")
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
Msgbox(SourceText1,"")
End Sub
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: