Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launching Chrome and debugging from within Visual Studio Code

I am using Visual Studio Code to debug some front-end javascript (for a Wordpress plugin). I am having trouble configuring the launch.json file correctly.

I can launch chrome manually and then attach to it after the fact (using an Attach request), in which case javascript breakpoints work fine fine.

If I launch chrome from within vscode (using the Launch request), it does connect (I see console output) but I don't get my breakpoints firing. I assume there is some setting incorrect in my launch.json file.

{
"version": "0.2.0",
"configurations": [
    {
        "name": "Launch Signup Form",
        "type": "chrome",
        "request": "launch",
        "url": "http://myclient.dev/signup-form",
        "sourceMaps": true,
        "webRoot": "../../..",
        "runtimeArgs": [
            "--remote-debugging-port=9222"
        ]
    },

    {
        "name": "Attach",
        "type": "chrome",
        "request": "attach",
        "port": 9222
    }
]

}

I've tried whatever I could think of for web root (including the full local path to the web root at 'htdocs' and the relative path you see above. It doesn't seem to care what I put in there, so maybe I'm barking up the wrong tree.

The local project folder is here:

/home/me/code/vagrant-local/www/wordpress-myclient/htdocs/wp-content/plugins/cee-signup-form

On the server, that maps to:

http://myclient.dev/wp-content/plugins/cee-signup-form

In the page 'signup-form' I include the javascript file in question, using its full url.

Obviously, I can manually go the url and then attach every time I want to debug, but having a one-click launch and debug would be far superior.

What am I doing wrong?

like image 863
Leo De Bruyn Avatar asked Jan 10 '16 08:01

Leo De Bruyn


2 Answers

Please follow below steps:

  1. Check you have installed "VS Code - Debugger for Chrome" extention.
  2. First Put this code in .vscode/launch.json :
{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Node",
      "port": 9229,
      "protocol": "inspector",
      "runtimeExecutable": "npm",
      "runtimeArgs": ["run-script", "start"],
      "console": "integratedTerminal"
    },
    {
      "type": "chrome",
      "request": "launch",
      "name": "Chrome",
      "url": "http://localhost:3000",
      "webRoot": "${workspaceRoot}/client/src"
    }
  ],
  "compounds": [
    {
      "name": "Full-stack",
      "configurations": ["Node", "Chrome"]
    }
  ]
}
  1. Go to the Debug mode in VS Code and start with 'Full-stack'.

  2. Start npm

Refer this : https://github.com/auchenberg/timey

like image 119
Vijay Chauhan Avatar answered Sep 22 '22 03:09

Vijay Chauhan


In my case, on Ubuntu 14.04, it worked after having added

"runtimeExecutable": "/usr/bin/chromium-browser"

I have however to start chrome in advance.

like image 22
wbartussek Avatar answered Sep 21 '22 03:09

wbartussek