使用 Chrome DevTools 检查请求和响应

默认情况下,开发人员代理在命令提示符中显示其消息。 如果您使用开发代理与发出大量请求的应用程序配合使用,可能会很难找到您感兴趣的消息。 更重要的是,你可能想要检查开发人员代理截获的请求和响应。

若要更轻松地查找感兴趣的消息,请使用 DevToolsPlugin 插件在 Chrome DevTools 中显示开发代理消息。

小窍门

开发代理支持将 Chrome DevTools 与 Microsoft Edge、Microsoft Edge Dev 和 Google Chrome 配合使用。

DevToolsPlugin 公开了 Dev Proxy 消息,以及在 Chrome DevTools 中截获的请求和响应的信息。

显示开发代理消息的开发工具的 Microsoft Edge 屏幕截图。

Microsoft Edge 的屏幕截图,其中开发人员工具显示开发人员代理截获的请求和响应。

将 Chrome DevTools 与开发代理配合使用:

  1. 打开位于您的 Dev Proxy 安装目录中的 devproxyrc.json 文件。 也可使用 devproxy config open 命令。

  2. 通过将以下片段添加到plugins数组中,启用DevToolsPlugin插件。

    {
      "name": "DevToolsPlugin",
      "enabled": true,
      "pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll",
      "configSection": "devTools"
    }
    
  3. 添加分区 devTools 并指定首选浏览器:

    "devTools": {
      "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.27.0/devtoolsplugin.schema.json",
      "preferredBrowser": "Edge"
    }
    

    小窍门

    支持的值包括:Edge、、 EdgeDevChrome

  4. 完整 devproxyrc.json 文件如下所示:

    {
      "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.27.0/rc.schema.json",
      "plugins": [
        {
          "name": "DevToolsPlugin",
          "enabled": true,
          "pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll",
          "configSection": "devTools"
        }
      ],
      "devTools": {
        "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.27.0/devtoolsplugin.schema.json",
        "preferredBrowser": "Edge"
      }
    }
    
  5. 保存devproxyrc.json文件,然后启动开发代理。