How to debug javascript in webview in android

后端 未结 7 1356
深忆病人
深忆病人 2020-12-24 01:30

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? Cu

7条回答
  •  粉色の甜心
    2020-12-24 02:07

    Those are the steps i use to debug a WebView content in a device:

    1. Enabled Developer Mode in your device
    2. Plug the device in the PC and enable USB debugging (install driver if needed)
    3. Add this line in your custom Application class or in the Activity where the webview is loaded

      //if your build is in debug mode, enable webviews inspection
      WebView.setWebContentsDebuggingEnabled(BuildConfig.DEBUG);
      
    4. Open Chrome and go to chrome://inspect and you should see your device in the Remote Target list

    5. Start debugging of your app from Android Studio
    6. When a WebView will be added to the layout, in the tab you opened will appear a screenshot with a Inspect button, click there and a Chrome developer console will open

提交回复
热议问题