简体   繁体   English

VSCode:如何使用 Chromium 调试本地文件(扩展名:Debugger for Chrome)

[英]VSCode: How to use Chromium for debugging on local files (extension: Debugger for Chrome )

My goal is to properly set launch.json file to run some *.html in Chromium.我的目标是正确设置launch.json文件以在 Chromium 中运行一些 *.html。

For example: This is my project folder structure:例如:这是我的项目文件夹结构:

project/
├─ some_folder/
│  ├─ index.html
│  ├─ script.js
├─ index.html
├─ script.js

In the end I'd like to create configurations for both index.html files.最后,我想为两个index.html文件创建配置。

Extension page: https://marketplace.visualstudio.com/items?itemName=msjsdiag.debugger-for-chrome扩展页面: https://marketplace.visualstudio.com/items?itemName=msjsdiag.debugger-for-chrome

  • Ubuntu 20.04 Ubuntu 20.04
  • VSCodium 1.55.1 VSCodium 1.55.1

It has to be possible to use Chromium instead of Chrome using runtimeExecutable (and some runtimeArgs if needed) in launch.json必须可以在launch.json中使用runtimeExecutable (以及一些runtimeArgs ,如果需要)使用 Chromium 而不是 Chrome

So I tried:所以我尝试了:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch index.html",
            "type": "chrome",
            "request": "launch",
            "file": "${workspaceFolder}/index.html",
            "runtimeExecutable": "/usr/bin/chromium-browser",
            "runtimeArgs": [
              "--new-window",
              "--user-data-dir=\"/${workspaceFolder}/DevProfile\"",
              "--remote-debugging-port=9222",
              "--disable-background-networking"
            ]
        }
    ]
}

I tried same without or with some of runtimeArgs .我在不使用或使用某些runtimeArgs的情况下进行了相同的尝试。 Also tried ${fileWorkspaceFolder} or ${fileFolder} or index.html absolute path instead ${workspaceFolder} .还尝试${fileWorkspaceFolder}${fileFolder}index.html绝对路径而不是${workspaceFolder}

Still same result - Chromium doesn't even start.仍然是同样的结果——Chromium 甚至没有启动。 No error, nothing.没有错误,什么都没有。 Only some kind of progressbar shortly showed in RUN AND DEBUG window.只有某种进度条在RUN AND DEBUG window 中短暂显示。

I'm out of ideas.我没主意了。 Thanks for help!感谢帮助!

Note: As of a year after the question was posted, the extension mentioned is deprecated.注意:问题发布一年后,提到的扩展名已弃用。

You can try starting chromium with remote debugging enabled, then setting the launch.json configuration to attach to the remote debugging port.您可以尝试在启用远程调试的情况下启动 Chromium,然后设置 launch.json 配置以附加到远程调试端口。

Start chromium like this:像这样启动铬:

/usr/bin/chromium-browser --remote-debugging-port=9222 --user-data-dir=remote-debug-profile

And your launch.config should look like this:你的 launch.config 应该是这样的:

{
  "configurations": [
    {
      "type": "pwa-chrome",
      "request": "attach",
      "name": "Attach to browser",
      "port": 9222
    }
  ]
}

Summarizing VS Code's documentation on this:总结 VS Code 的相关文档:

To attach to a running browser, it needs to be launched in a special debug mode.要附加到正在运行的浏览器,需要以特殊的调试模式启动它。

... ...

Setting the --remote-debugging-port tells the browser to listen on that port for a debug connection.设置--remote-debugging-port告诉浏览器在该端口上侦听调试连接。 Setting a separate --user-data-dir forces a new instance of the browser to be opened;设置单独的--user-data-dir会强制打开浏览器的新实例; if this flag isn't given, then the command will open a new window of any running browser and not enter debug mode.如果未给出此标志,则该命令将打开任何正在运行的浏览器的新 window 并且不进入调试模式。

Source: https://code.visualstudio.com/docs/nodejs/browser-debugging#_attaching-to-browsers来源: https://code.visualstudio.com/docs/nodejs/browser-debugging#_attaching-to-browsers

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

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