如何在chrome中調试android应用中的webview

1.确保您的手机android系统在4.4以上。

2.连接数据线到您的电脑和手机

3.开启手机的开发者模式和usb調试

4.在android应用中开启webview调试

配置 WebViews 进行调试

必须从您的应用中启用 WebView 调试。要启用 WebView 调试,请在 WebView 类上调用静态方法 setWebContentsDebuggingEnabled


if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
   
WebView.setWebContentsDebuggingEnabled(true);
}

此设置适用于应用的所有 WebView。

提示:WebView 调试不会受应用清单中 debuggable 标志的状态的影响。如果您希望仅在 debuggable 为 true 时启用 WebView 调试,请在运行时测试标志。


if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
   
if (0 != (getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE))
   
{ WebView.setWebContentsDebuggingEnabled(true); }
}

5.在chrome中打开chrome://inspect#devices, 然后在app中点开webview, 即可在chrome中找到对应的页面,点inspect即可调试。

如何在chrome中調试android应用中的webview

这对于调试jsBridge的东西会非常方便,更多详情请查看https://developers.google.com/web/tools/chrome-devtools/remote-debugging/webviews?hl=zh-cn