Basics:
NextJS 14.2.16
Pages Router
VSCode IDE (latest version)
Flask is the backend, NextJS is only used to serve a React front-end.
Goal:
Debug web app with Chrome using a user profile that has chrome extensions loaded in it.
Have all breakpoints actually be reachable.
My launch.json configuration works only if I do not specify any Chrome profile and then I am unable to use browser debugging tools like React Dev tools or Redux Dev tools, so I really need my own profile to load. When using this configuration (I launch using Full Stack compound):
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch Chrome",
"type": "chrome",
"request": "launch",
"url": "http://localhost:3000",
"webRoot": "${workspaceFolder}/nextjs",
"sourceMaps": true,
"sourceMapPathOverrides": {
"webpack://?:*/*": "${workspaceFolder}/nextjs/*",
},
"userDataDir": false,
"runtimeArgs": [
"--profile-directory=Profile 3",
],
},
{
"name": "Launch NextJS",
"type": "node-terminal",
"request": "launch",
"cwd": "${workspaceFolder}/nextjs",
"command": "npm run dev",
"serverReadyAction": {
"action": "startDebugging",
"pattern": "- Local:\\s*(https?://.+)",
"name": "Launch Chrome",
}
},
{
"name": "Launch Flask",
"type": "debugpy",
"request": "launch",
"module": "flask",
"cwd": "${workspaceFolder}/flask/api",
"env": {
"FLASK_APP": "run.py",
"FLASK_DEBUG": "1"
},
"args": ["run", "--no-debugger", "--no-reload"],
"justMyCode": true
},
],
"compounds": [
{
"name": "Full Stack",
"configurations": ["Launch Flask", "Launch NextJS"]
}
]
}
The Chrome window will open with the correct user profile and extensions loaded, but it remains on an "about:blank" page and will not load my application until I manually type in "localhost:3000" to the URL bar, then it loads the application but my breakpoints don't work. The weird thing is, in VSCode, the breakpoints act like they will be hit, they light up red and aren't gray empty circles, but they never do get hit when they should and when I Diagnose Breakpoints with the command palette, they come up as unbound saying source locations couldn't be found.
The terminal output of NextJS is this, it never attempts to move to the compiling step by itself:
(chap) 1234567:nextjs xxx$ npm run dev
Debugger attached.
> [email protected] dev
> next dev
Debugger attached.
Debugger attached.
▲ Next.js 14.2.16
- Local: http://localhost:3000
- Environments: .env.development
✓ Starting...
✓ Ready in 1892ms
I have tried many different regex patterns for NextJS to match on, but I don't think that's the problem because Chrome does launch, it just doesn't load the application by itself.
I have tried this configuration also, launching with the Debug Full Stack compound:
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch Flask",
"type": "debugpy",
"request": "launch",
"module": "flask",
"cwd": "${workspaceFolder}/flask/api",
"env": {
"FLASK_APP": "run.py",
"FLASK_DEBUG": "1"
},
"args": ["run", "--no-debugger", "--no-reload"],
"justMyCode": true
},
{
"name": "Launch NextJS",
"type": "node",
"request": "launch",
"runtimeExecutable": "node",
"runtimeArgs": ["--inspect", "./node_modules/next/dist/bin/next"],
"cwd": "${workspaceFolder}/nextjs",
"skipFiles": ["<node_internals>/**"],
},
{
"name": "Launch Chrome",
"type": "chrome",
"request": "launch",
"url": "http://localhost:3000",
"webRoot": "${workspaceFolder}/nextjs",
"runtimeArgs": [
"--load-extension=/Users/xxx/Library/Application Support/Google/Chrome/Default/Extensions/fmkadmapgofadopljbjfkapdkoienihi/6.1.5_0"
],
}
],
"compounds": [
{
"name": "Debug Full Stack",
"configurations": ["Launch Flask", "Launch NextJS", "Launch Chrome"]
}
]
}
This opens Chrome, automatically loads the application and breakpoints work, but no profile is loaded and the extension doesn't load either. I think Chrome must have a profile in order for --load-extension to work.
I'm really out of ideas at this point as I have tried so many different configurations founds via stackoverflow and nextjs's git issues, but none really deal with chrome profiles (most people use debugWithChrome under serverReadyAction in their full stack config which will not work for this).
Has anybody gotten another Chrome profile to work successfully with NextJS and VSCode debugging?
Edit: Looks like --load-extension is a deprecated flag/feature of Chrome and no longer is usable, so that's one problem clarified.