Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug javascript in webview in android

I have a webview that works fine on iOS, but not Android. Is there a tool where I can connect to Android webview in browser and debug it using firefox or webkit console? Currently I have no idea what is causing the webview not to work in Android.

In iOS I am able to open my iPad or iPhone simulator, open the webview pane, and in my desktop browser I listen to port 9999, and it shows me the tools you see in webkit developer tool/debugging tools.

I am looking for similar tool for Android, or at least to get me started on debugging.

like image 932
user1118019 Avatar asked May 08 '12 22:05

user1118019


People also ask

How do I enable JavaScript on Android WebView?

JavaScript is disabled in a WebView by default. You can enable it through the WebSettings attached to your WebView . You can retrieve WebSettings with getSettings() , then enable JavaScript with setJavaScriptEnabled() . WebView myWebView = (WebView) findViewById(R.

Can WebView run JavaScript?

WebView is a special component in Android which serves as kind of built-in browser inside Android applications. If you want to execute HTML, CSS or JavaScript code in your Android app, or you need to allow users visit a URL without leaving your application, WebView is the way to go.


1 Answers

The easiest way to debug WebView is to connect your Android device to PC by USB and inspect your WebView by Chrome dev tools.

So, you will need:

1) Activate USB debugging on our devise. You can find it Settings >> Developer Options >> Debugging >> USB Debugging (activate checkbox)

2) Connect you devise to Computer by USB

Note: If you are developing on Windows, install the appropriate USB driver for your device. See OEM USB Drivers on the Android Developers' site.

3) Open Chrome browser and type in the URL field: chrome://inspect/#devices

4) Confirm that 'Discover USB devices' activated

5) On your device, an alert prompts you to allow USB debugging from your computer. Tap OK.

6) On the chrome://inspect page displays every connected device. Click inspect for connected device and you will get console.

More detailed manual is Debugging Android WebView

like image 152
Vladyslav Babenko Avatar answered Oct 06 '22 17:10

Vladyslav Babenko