I'm experiencing an issue with debugging my Angular application using Visual Studio Code and the Chrome debugger. When I start the debugging session, the Chrome browser window doesn't open until I manually exit the prelaunch task. This behaviour is preventing me from seamlessly starting my debugging process. Here are the details:
{
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"preLaunchTask": "npm: start",
"url": "http://localhost:4200",
"webRoot": "${workspaceFolder}",
"sourceMapPathOverrides": {
"webpack:/*": "${webRoot}/*",
"/./*": "${webRoot}/*",
"/src/*": "${webRoot}/*",
"/*": "*",
"/./~/*": "${webRoot}/node_modules/*"
}
}
]
}
{
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "start",
"isBackground": true,
"presentation": {
"focus": true,
"panel": "dedicated"
},
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": {
"owner": "typescript",
"source": "ts",
"applyTo": "closedDocuments",
"fileLocation": ["relative", "${cwd}"],
"pattern": "$tsc",
"background": {
"activeOnStart": true,
"beginsPattern": {
"regexp": "(.*?)"
},
"endsPattern": {
"regexp": "Compiled |Failed to compile."
}
}
}
}
]
}
The Chrome browser window should open automatically once ng serve completes its initial compilation and starts watching for changes.
The Chrome browser window does not open until I manually exit the ng serve prelaunch task.
What I've Tried:
How can I configure VS Code and the Chrome debugger to automatically open the Chrome window as soon as ng serve completes its initial compilation and enters watch mode, without requiring manual intervention? It is kind of weird since I copied and pasted the exact launch and tasks from an Angular app where the debugging works.
Any help or suggestions would be greatly appreciated!
With the help of this question question and documentation, I was able to find the problem.
I've updated the problemMatcher.background.endsPattern value into:
"endsPattern": "Watch mode enabled. Watching for file changes..."
And now the preLaunchTask knows when to open the chrome debugger window. I believe it has something to do with Angular watch mode message, hence it has to be updated.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With