如何在 MAUI 中启用开发者工具

huangapple go评论78阅读模式
英文:

How to enable developer tools in MAUI

问题

半年前,我开始使用MAUI项目,当我开始这个项目时,我能够通过右键单击WebView来打开上下文菜单并打开Web开发工具。出于某种原因,我在一段时间内失去了这种能力。现在,我如何启用上下文菜单和打开Web开发工具?

英文:

Half years ago I started work on the project using MAUI, when I started the project I was able to open context menu on WebView by right mouse click and open Web developer tools.

For some reason from a while I lost this ability. Now, how I can enable context menu and opening of web developer tools?

答案1

得分: 1

Microsoft Edge DevTools 可用于调试 MAUI Android Webview,请参考以下文档和步骤:

远程调试 Android WebViews。

步骤 1:
将以下代码添加到 MainActivity 类中,以启用 Android WebView 的调试。

protected override void OnCreate(Bundle savedInstanceState)
{
    base.OnCreate(savedInstanceState);
    if (Build.VERSION.SdkInt >= BuildVersionCodes.Kitkat)
    {
        Android.Webkit.WebView.SetWebContentsDebuggingEnabled(true);
    }
}

步骤 2:
构建您的应用程序。

步骤 3:
使用 Edge 浏览器打开 edge://inspect,然后点击页面上显示的 Android 设备下面的 Inspect 按钮。

来源:Microsoft Learn

用于调试 IOS 上的 WebView:

连接 iOS 设备到计算机。

启用 Web Inspector 选项。方法如下:
转到 设置 > Safari > 滚动到底部 > 打开高级菜单 > 打开 Web Inspector

打开要调试或预览的移动 Safari 浏览器上的所需网页。完成后,在 Mac 设备上启用 Develop 菜单。

要启用 Develop 菜单,请按照以下步骤操作:
启动 Safari 浏览器
点击顶部的 Safari > 设置 > 高级
选中复选框 - 在菜单栏中显示 Develop 菜单以启用它

来源:BrowserStack

英文:

Microsoft Edge DevTools could be used for debugging MAUI Android Webview, please refer to the following documentation and steps:

Remotely debug Android WebViews.

Step 1.
Add the following code to the MainActivity class to enable debugging of Android WebView.

protected override void OnCreate(Bundle savedInstanceState)
{
    base.OnCreate(savedInstanceState);
    if (Build.VERSION.SdkInt >= BuildVersionCodes.Kitkat)
    {
        Android.Webkit.WebView.SetWebContentsDebuggingEnabled(true);
    }
}

Step 2:
Build your application.

Step 3:
Open the edge://inspect using the Edge browser and click the Inspect button below your Android device that appears on the page.

source: Microsoft Learn

For debugging WebView on IOS:

Connect the iOS device to the machine.

Enable the Web-Inspector option. To do so:
Go to Settings > Safari > Scroll down to the bottom > Open Advanced Menu>Turn on Web Inspector

Open the desired web page to debug or preview on your mobile Safari browser. Once done, enable the Develop menu on the Mac device.

To enable the Develop menu, follow the steps below:
Launch Safari browser
Click on Safari at the top > Settings > Advanced
Mark the checkbox – Show Develop menu in the menu bar to enable it

source: BrowserStack

答案2

得分: 0

这是答案,如果您使用Google Chrome。 https://developer.chrome.com/docs/devtools/remote-debugging/webviews/

英文:

Here is an answer if you use Google Chrome. https://developer.chrome.com/docs/devtools/remote-debugging/webviews/

huangapple
  • 本文由 发表于 2023年5月17日 19:05:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/76271406.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定