How to Debug a Browser App in VS Code with the Built-in Chrome Debugger
Attach VS Code's debugger to a running dev server so you can set breakpoints in your front-end code and step through it in the editor.
Debugging front-end JavaScript usually means jumping into the browser DevTools. VS Code can run the debugger inside the editor instead, so your breakpoints live in the same files you edit. This guide attaches the built-in JavaScript debugger to a local dev server and steps through browser code without leaving VS Code.
What you need
- A web project with a dev server (Vite, Create React App, or similar)
- Google Chrome or Microsoft Edge installed
- VS Code 1.46 or newer (the JavaScript debugger is built in)
Step 1: Start your dev server
In the integrated terminal, run your dev server and note the local URL it prints. The debugger needs that exact address to attach to.
Step 2: Add a Chrome launch configuration
Open Run and Debug with Ctrl+Shift+D, click create a launch.json file, and choose Web App (Chrome). Edit the url so it matches your dev server, and set webRoot to the folder that holds your source files.
{
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Debug in Chrome",
"url": "http://localhost:5173",
"webRoot": "${workspaceFolder}/src"
}
]
}Step 3: Set a breakpoint in your code
Open a source file, such as a click handler, and click the gutter to place a breakpoint on the line you want to inspect. The debugger maps the compiled browser code back to your source using source maps, which most dev servers enable by default.
Step 4: Launch and trigger the code
Press F5. A new Chrome window opens at your dev server URL, controlled by VS Code. Interact with the page so the code runs; click the button that triggers your handler. Execution pauses at the breakpoint and focus jumps back to VS Code.
Step 5: Inspect state and continue
Read the Variables panel to see the value of count and next at this moment. Use F10 to step over and F5 to continue. Edit your code, save, and the dev server hot-reloads the page so you can test the fix immediately.
Result
Your front-end code now pauses inside VS Code with full variable inspection, mapped to the real source files. You can debug a browser app without ever opening DevTools.
Watch related tutorials
1:42:18
28:14
41:09
9:47
8:23
52:31