Condition
[vscode debugger mode]
[react, nodejs, nextjs]
在vscode debug的launch.json遇到的問題,無法順利連上chrome port
error info
- Cannot connect to the target at localhost:9222: Could not connect to debug target
- unable to attach to browser
Solution
網路上的教學都嘗試過了,但沒有實際解決問題,在Chrome一樣無法使用
–remote-debugging-port=9222
這我不管用
在Chrome.exe的Property.target中,加入–remote-debugging-port=9222,或加入%1
"C:\Program Files\Google\Chrome\Application\chrome.exe" --remote-debugging-port=9222 -- "%1"
reference
改用edge Browser
目前只能先暫時用這個頂著,能夠串到vscode的breakpoint
{
"version": "0.2.0",
"configurations": [
{
"type": "msedge",
"request": "launch",
"name": "Launch Edge against localhost",
"url": "http://localhost:3000",
"webRoot": "${workspaceFolder}"
}
]
}
Other Knowledge
type:“launch” vs. type:“attach”
在launch.json中兩個type的差別
launch是開啟全新的瀏覽器,attach是用既有的連接
Port 9222
Port 9222 用作BrowserRemote Debugging
“%1” in bat
When used in a command line, script, or batch file, %1 represents a variable or matched string.
%1會print command後的input值
創建 bat file
[bash]
echo Hello %1, it's nice to meet you.
[powershell | cmd]
greet.bat Alice
會print