简体   繁体   English

如何在带有 Chrome 调试的 VS Code 中启用文件的可编辑调试?

[英]How do I enable editable debugging of files within VS Code w/ Chrome Debugging?

Environment:环境:

  • OS: macOS Big Sur 11.5.2 (20G95)操作系统:macOS Big Sur 11.5.2 (20G95)
  • Chrome: Version 93.0.4577.82 (Official Build) (x86_64) Chrome:版本 93.0.4577.82(官方版本)(x86_64)
  • VSCode: Version: 1.60.1 Commit: 83bd43bc519d15e50c4272c6cf5c1479df196a4d Date: 2021-09-10T17:09:14.403Z (5 days ago) Electron: 13.1.8 Chrome: 91.0.4472.164 Node.js: 14.16.0 V8: 9.1.269.39-electron.0 OS: Darwin x64 20.6.0 VSCode:版本:1.60.1 提交:83bd43bc519d15e50c4272c6cf5c1479df196a4d 日期:2021-09-10T17:09:14.403Z(5 天前)Electron: 13441.16.8.Node.13.16.16.16.16.16.16.16.16.16.16.19.16.1.3.8 Electron.0 操作系统:Darwin x64 20.6.0

My action:我的行动:

  1. { VSCode } Open the workspace containing my project directory. { VSCode } 打开包含我的项目目录的工作区。
  2. { VSCode } Add the following block to 'launch.json' in the "configurations" array: { VSCode } 将以下块添加到“configurations”数组中的“launch.json”:
{
   "type": "pwa-chrome",
   "request": "attach",
   "name": "Attach Chrome Debugging to Browser for VSCode",
   "port": 9222,
   "url": "http://localhost:8888/",
   "urlFilter": "http://localhost:8888/*",
   "webRoot": "${workspaceFolder}"
}
  1. { VSCode } Save 'launch.json' { VSCode } 保存“launch.json”
  2. { Chrome } Close all running instances of Chrome { Chrome } 关闭所有正在运行的 Chrome 实例
  3. { Terminal } Navigate to root ( / ) {终端} 导航到根目录 ( / )
  4. { Terminal } Run the command: /Applications/Google\\ Chrome.app/Contents/MacOS/Google\\ Chrome --remote-debugging-port=9222 --user-data-dir=remote-debug-profile {终端} 运行命令: /Applications/Google\\ Chrome.app/Contents/MacOS/Google\\ Chrome --remote-debugging-port=9222 --user-data-dir=remote-debug-profile

Outcome:结果:

  1. { Chrome } Application opens with a popup (not as expected): { Chrome } 应用程序打开时会弹出一个窗口(不像预期的那样):
    带有文本阅读的弹出窗口的屏幕截图:“Google Chrome 无法读取和写入其数据目录:remote-debug-profile

My action:我的行动:

  1. { Chrome } Click "Ok" button. { Chrome } 单击“确定”按钮。

Outcome:结果:

  1. { Chrome } A window opens prompting "Who's using Chrome?" { Chrome } 将打开一个窗口,提示“谁在使用 Chrome?” with an option to select my desired user profile as expected.可以选择按预期选择我想要的用户配置文件。

My action:我的行动:

  1. { Chrome } Click on my desired user profile. { Chrome } 单击我想要的用户配置文件。

Outcome:结果:

  1. { Chrome } A window opens with my desired user profile logged in as expected. { Chrome } 一个窗口打开,我想要的用户配置文件按预期登录。

My action:我的行动:

  1. { VSCode } Add a breakpoint to my code via a debugger; { VSCode } 通过debugger;向我的代码添加断点debugger; statement in my HTML file.我的 HTML 文件中的语句。
  2. { VSCode } Click "Run" button with my debugging profile selected. { VSCode } 单击“运行”按钮并选择我的调试配置文件。
  3. { Chrome } Conduct behavior to trigger breakpoint in my code. { Chrome } 执行行为以在我的代码中触发断点。

Outcome:结果:

  1. { VSCode } The breakpoint is triggered HOWEVER: it is triggered in a "read-only" version of my file, opened in a new tab separate from my actual file. { VSCode } 断点被触发,但是:它是在我的文件的“只读”版本中触发的,在与我的实际文件分开的新选项卡中打开。

My Desired Outcome我想要的结果

Using "attach" I want to be able to have the breakpoint activate inside of the actual file in VSCode, not a "Read-Only" version.使用“附加”我希望能够在 VSCode 中的实际文件内激活断点,而不是“只读”版本。


I've spent about two hours researching this issue and as far as I can tell it has to do with:我花了大约两个小时研究这个问题,据我所知,它与以下方面有关:

  • The location I'm running the terminal command from.我正在运行终端命令的位置。 I tried:我试过:
    • Running it from the project directory, however it dumped a ton of code into my project directory AND failed to open an instance of Chrome where I could select my desired user profile - instead opening up a user profile agnostic Chrome window.从项目目录运行它,但是它将大量代码转储到我的项目目录中,并且无法打开一个 Chrome 实例,我可以在其中选择我想要的用户配置文件 - 而不是打开一个用户配置文件不可知的 Chrome 窗口。
  • The --user-data-dir=remote-debug-profile line in the terminal command.终端命令中的--user-data-dir=remote-debug-profile行。
  • My configuration in Launch.JSON.我在 Launch.JSON 中的配置。 I've tried combinations of:我尝试过以下组合:
    • "type": "chrome"
    • "webRoot": "*/thedirectpathtomyprojectdirectory*"
    • "webRoot": "${workspaceFolder}/src"
    • "userDataDir": "/Library/Application\\ Support/Google/Chrome/Profile 1"
    • "userDataDir": "/Library/Application\\ Support/Google/Chrome"
    • "sourceMapPathOverrides": {"webpack://?:*/*": "${workspaceFolder}/*"}
    • "sourceMaps": true

I'm at a total loss!我完全不知所措!

The problem is with --user-data-dir=remote-debug-profile问题在于--user-data-dir=remote-debug-profile

See here - https://chromium.googlesource.com/chromium/src/+/HEAD/docs/user_data_dir.md见这里 - https://chromium.googlesource.com/chromium/src/+/HEAD/docs/user_data_dir.md

You need to supply an actual directory path.您需要提供实际的目录路径。

  1. Copy your current User Data folder to your custom dir将您当前的用户数据文件夹复制到您的自定义目录

  2. Point chrome shortcut to the custom dir using the --user-data-dir parameter使用 --user-data-dir 参数将 chrome 快捷方式指向自定义目录

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM