Android Question Debugging the webview javascript

Hi I can debug a the webpage shown by the android chrome browser using chrome://inspect/#devices, but it does not seem to work for a webview.
In android studio one should apparently set WebView1.SetWebContentsDebuggingEnabled(True)
However I cannot find out how to do that on B4A .
Please describe how that can be done
 

hatzisn

Expert
Licensed User
Longtime User
Why don't you debug the web page in a web browser before you embed it in the webview?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
 
Upvote 0
Why don't you debug the web page in a web browser before you embed it in the webview?
Thanks for your reply, the webpage is debugged and works in browsers, it has a number of issues in the webview but not beeing able to see it with the dev tools I do not know where the issues are. Essentially I wanted to connect to classic bluetooth for biosignal recording and wanted to make a hybrid solution as browsers do only support BLE.
 
Upvote 0
I think the problem is that setWebContentsDebuggingEnabled does not seem to exist in B4A. Will this library be a fix and will it allow chrome://inspect/#devices, to debug the webapp?
 
Upvote 0

hatzisn

Expert
Licensed User
Longtime User
I think the problem is that setWebContentsDebuggingEnabled does not seem to exist in B4A. Will this library be a fix and will it allow chrome://inspect/#devices, to debug the webapp?

The javaobject allows you to execute java methods with the RunMethod command.

setWebContentsDebuggingEnabled exists in java and can be run this way.
 
Upvote 0
After some hours I got it to work.
It was not quite clear to me where and how setWebContentsDebuggingEnabled should be added (been away from b4a since my licenced version 8)
Here is my working code and I am able to debug it with chrome://inspect/#devices (Hoping it may help others,)

I found among other things that localStorage does not work out of the box for the webview but has to be enabled.

I downloaded the libraries WebViewExtras2 & WebViewSettings

Also a library has to be added for JavaObject to work.



Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.

Private EditText1 As EditText
Private WebView1 As WebView
Private WebViewExtras1 As WebViewExtras
Private WebViewSetting1 As WebViewSettings
Private WebChromeClient1 As DefaultWebChromeClient
Private JavascriptInterface1 As DefaultJavascriptInterface


End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("Main")
Dim WVJO As JavaObject = WebView1
WVJO.RunMethod("setWebContentsDebuggingEnabled",Array(True))
WebViewSetting1.SetDOMStorageEnabled(WebView1,True)
EditText1.Text="https://....../index.php "
WebView1.LoadUrl(EditText1.Text)
End Sub

Thanks for your comments
Hi I can debug a the webpage shown by the android chrome browser using chrome://inspect/#devices, but it does not seem to work for a webview.
In android studio one should apparently set WebView1.SetWebContentsDebuggingEnabled(True)
However I cannot find out how to do that on B4A .
Please describe how that can be done
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
Are you adding the chromeclient to webview?
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
This thread seems to suggest that webview errors can be "sent to the console" if you add chromeclient to webview using webviewextras:


And this is how you can add the chromeclient to webview using webviewextras:

 
Last edited:
Upvote 1
Top