在Chrome上调试Android WebView

admin 提交于 周四, 05/27/2021 - 10:36
  1. Enable Developer Options in Device (Settings-->About Phone-->Tap 7 times on build number)
  2. Turn on Developer options and Enable USB Debugging (in Developer Options)
  3. Add this line in your custom Application class or in the Activity where the Web View is loaded

    // if your build is in debug mode, enable inspecting of web views

    if (0 != (getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE)) {
        WebView.setWebContentsDebuggingEnabled(true);
    }
    
  4. Open Chrome and type chrome://inspect/#devices and you should see your device in the Remote Target List

  5. Click on inspect to debug it.

 

参考:https://stackoverflow.com/questions/21903934/how-to-debug-webview-remotely#:~:text=Try%20this%3A%201%20Enable%20Developer%20Options%20in%20Device,5%20Click%20on%20inspect%20to%20debug%20it.%20

 

如果inspect的时候出现空白页,可能是Chrome的bug,试试用Edge,参考:https://stackoverflow.com/questions/66670000/android-chrome-inspect-devices-blank-screen

标签

添加新评论

Restricted HTML

  • 允许的HTML标签:<a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id> <img src>
  • 自动断行和分段。
  • 网页和电子邮件地址自动转换为链接。
验证码
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
请输入"汉语"