Press "Enter" to skip to content

VSCode Chrome Debugger and Gutenberg

While working on a recent issue in Gutenberg, I needed to do some javascript debugging. Normally I’d just do this in Chrome using the dev tools, but I decided to see if I could get the VSCode Chrome debugger working to be able to do it directly inside the IDE. 

Initially, the debugger was running and executing, but any breakpoints I added were marked as invalid. This is because VSCode was having trouble parsing the source maps for the JS files being loaded by the browser.

It took a while of tinkering with the config, but this is what I finally got working:

    "version": "0.2.0",
    "configurations": [
            "type": "chrome",
            "request": "launch",
            "name": "Launch Chrome against gutenberg-develop",
            "url": "http://gutenberg-develop.test/wp-admin/post-new.php",
            "webRoot": "/Users/wearnhardt/vvv/www/gutenberg/public_html/",
            "sourceMaps": true,
            "sourceMapPathOverrides": {
                "webpack://wp.[name]/*": "${webRoot}/wp-content/plugins/gutenberg/*",

In my setup, I’m using a custom-site on VVV called gutenberg. VVV lives in my user directory on my machine. 

The solution was just adding the correct webRoot and sourceMapPathOverrides, but it was tough to troubleshoot because most of the documentation said to just run the .scripts command in the debug console to determine how files were mapped.

But whenever I ran that, it didn’t provide me with any listed mappings for the individual JS files being loaded (as most of the documentation said it should), so I couldn’t tell what was wrong.

Ultimately I added "trace": true to the launch.json and then looked at the full output provided to the log and was able to tell the issue. 

Gutenberg’s webpack config doesn’t specify a source path, so when the debugger is setting up, it tries to fall back to the directory of the js file to use as the path to find its mapped files. 

This essentially leads to paths like this:

Once I got the correct sourceMapPathOverrides rules in place, it started working great!

Be First to Comment

Leave a Reply