Android WebViews 远程调试入门Get started with remote debugging Android WebViews

使用开发人员工具在本机 Android 应用中Microsoft Edge Android WebView。Debug Android WebViews in your native Android apps using Microsoft Edge Developer Tools.

在 Android 4.4 \ (KitKat) 或更高版本上,使用 DevTools 调试本机 Android 应用中的 WebView 内容。On Android 4.4 (KitKat) or later, use DevTools to debug WebView content in native Android apps.

摘要Summary

  • 在本机 Android 应用中打开 Android WebView 调试;在 DevTools Microsoft Edge Android WebViews。Turn on Android WebView debugging in your native Android app; debug Android WebViews in Microsoft Edge DevTools.
  • 若要显示启用调试的 Android WebView 列表,请导航到 edge://inspectTo display the list of the Android WebViews with debugging turned on, navigate to edge://inspect.
  • 使用通过远程调试调试网页的相同方式调试 Android WebView。Debug Android WebViews in the same way you debug a webpage through remote debugging.

将 Android WebViews 配置为调试Configure Android WebViews to debug

必须在你的应用中打开 Android WebView 调试。Android WebView debugging must be turned on within your app. 若要启用 Android WebView 调试,请对类运行 setWebContentsDebuggingEnabled WebView 静态方法。To turn on Android WebView debugging, run the setWebContentsDebuggingEnabled static method on the WebView class.

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

该设置适用于应用的所有 Android WebView。The setting applies to all of the Android WebViews of the app.

提示

Android WebView 调试不受应用清单中标志 debuggable 状态的影响。Android WebView debugging is not affected by the state of the debuggable flag in the manifest of the app. 如果你希望仅在标志为 时启用 Android WebView debuggable 调试, true 请在运行时测试标志。If you want to turn on Android WebView debugging only when the debuggable flag is true, test the flag at runtime.

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

在 DevTools 中打开 Android WebViewOpen an Android WebView in DevTools

若要显示已打开调试的 Android WebView 列表,并在设备上运行,请导航到 edge://inspectTo display a list of the Android WebViews with debugging turned on that run on your device, navigate to edge://inspect.

若要开始调试,在你要调试的 Android WebView 下,选择"检查 "。To start debugging, under the Android WebView you want to debug, choose inspect. 使用 DevTools 的方式与执行远程浏览器选项卡的方式相同。Use DevTools in the same way that you do a remote browser tab.

排除故障Troubleshoot

你的 Android WebView 不会显示在 edge://inspect 页面上?Your Android WebViews aren't displayed on the edge://inspect page?

  • 验证已针对你的应用打开 Android WebView 调试。Verify that Android WebView debugging is turned on for your app.
  • 在你的设备上,使用你想要调试的 Android WebView 打开应用。On your device, open the app with the Android WebView you want to debug. 然后,刷新 edge://inspectThen, refresh edge://inspect.

联系 Microsoft Edge DevTools 团队Getting in touch with the Microsoft Edge DevTools team

使用以下选项讨论帖子中的新功能和更改,或与 DevTools 相关的任何其他内容。Use the following options to discuss the new features and changes in the post, or anything else related to DevTools.

  • 使用“发送反馈”图标发送反馈,或在 DevTools 中选择Alt+Shift+I \ (Windows、Linux) 或 Option+Shift+I \ (macOS)。Send your feedback using the Send Feedback icon or select Alt+Shift+I (Windows, Linux) or Option+Shift+I (macOS) in DevTools.
  • 发推 @EdgeDevToolsTweet at @EdgeDevTools.
  • 我们想要的 Web 提交建议。Submit a suggestion to The Web We Want.
  • 若要提交有关本文的错误,请使用以下“反馈” 部分。To file bugs about this article, use the following Feedback section.

Microsoft Edge DevTools 中的“发送反馈”图标

备注

此页面的某些部分是根据 Google 创建和共享的作品所做的修改,并根据 Creative Commons Attribution 4.0 International License 中描述的条款使用。Portions of this page are modifications based on work created and shared by Google and used according to terms described in the Creative Commons Attribution 4.0 International License.
原始页面位于 此处,Meggin Kearney \ (Tech Writer) 。The original page is found here and is authored by Meggin Kearney (Tech Writer).

Creative Commons License
本作品根据 Creative Commons Attribution 4.0 International License 获得许可。This work is licensed under a Creative Commons Attribution 4.0 International License.