VS Code调试配置分享

这不是一篇科普文,只是一篇浏览器调试配置的分享(主要对准对准vs code调试)

调试配置

使用vs code插件debugger-for-chromedebugger-for-edge(EdgeHTML&Chromium)调试之前,会自动在工程下添加.vscode文件夹,里面的launch.json就是配置调试参数的位置。

launch.json

很多的配置参数,具体看参考章节的nodejs-debuggingdebugging-protocol

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [


{
"type": "chrome",
"request": "launch",
"name": "vuejs: launch chrome",
"url": "http://localhost:8080",
"webRoot": "${workspaceFolder}/src",
"userDataDir": false,
"breakOnLoad": true,
"sourceMapPathOverrides": {
"webpack:///./src/*": "${webRoot}/*"
}
},
{
"type": "chrome",
"request": "attach",
"name": "vuejs: attach chrome",
"webRoot": "${workspaceFolder}/src",
"port": 9222,
"sourceMapPathOverrides": {
"webpack:///./src/*": "${webRoot}/*"
}
},
{
"type": "edge",
"request": "launch",
"name": "vuejs: launch EdgeHTML",
"url": "http://localhost:8080",
"webRoot": "${workspaceFolder}/src",
"userDataDir": false,
"breakOnLoad": true,
"sourceMapPathOverrides": {
"webpack:///./src/*": "${webRoot}/*"
}
},
{
"type": "edge",
"request": "attach",
"name": "vuejs: attach EdgeHTML",
"webRoot": "${workspaceFolder}/src",
"port": 2015,
"sourceMapPathOverrides": {
"webpack:///./src/*": "${webRoot}/*"
}
},
{
"type": "edge",
"request": "attach",
"version": "dev", // dev, beta, or canary
"name": "vuejs: attach Edge(Chromium)",
"webRoot": "${workspaceFolder}/src",
"port": 9223,
"sourceMapPathOverrides": {
"webpack:///./src/*": "${webRoot}/*"
}
},
{
"type": "edge",
"request": "launch",
"version": "dev",
"name": "vuejs: launch Edge(Chromium)",
"url": "http://localhost:8080",
"webRoot": "${workspaceFolder}/src",
"userDataDir": false,
"breakOnLoad": true,
"sourceMapPathOverrides": {
"webpack:///./src/*": "${webRoot}/*"
}
},
{
"type": "firefox",
"request": "launch",
"name": "vuejs: firefox",
"url": "http://localhost:8080",
"webRoot": "${workspaceFolder}/src",
"pathMappings": [{ "url": "webpack:///src/", "path": "${webRoot}/" }]
}
]
}

launch模式

launch模式就是重新打开一个浏览器实例(不是tab)。

attach模式

attach模式,是附加到现在已经打开的浏览器调试端口上,所以需要你在已经打开的浏览器中访问launch.json中配置的网站地址。

attach模式的tab窗口选择
attach模式的tab窗口选择

chrome配置

  • windows
chrome配置远程调试端口
chrome配置远程调试端口
  • mac

    终端执行: /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222

  • Linux

    终端执行: google-chrome --remote-debugging-port=9222

Edge(Chromium)

  • windows

Edge(Chromium)调试端口配置

命令行:msedge.exe --remote-debugging-port=2015

  • mac和Liunx现在官方没说怎么调试…..

Microsoft Edge (EdgeHTML)

  • windows

    命令行: microsoftedge.exe --devtools-server-port=2015

    竟然不能快捷方式配置,不科学。

个人建议

个人建议平时开发,把端口配置到快捷方式,使用attach模式可以共享使用已经安装的浏览器插件。

具体还有很多参数配置,可以参考官方文档。

参考

debugger-for-chrome

debugger-for-edge

vscode-chrome-debug-github

vscode-recipes

devtools-protocol-chromium

devtools-protocol-edge

nodejs-debugging