Node.js remote debugging from local Chrome

Hello,

This is a question about using Chrome on my local machine to debug Node.js that is running in GitPod. I don’t have a problem running the in-built debugger, but I’m keen to run the debugger in Chrome Dev Tools in order to benefit from the live code edit support (which as far as I can tell in the VS Code debugger requires the process to be reloaded).

My understanding of what should be necessary to make this happen is the following:

  1. In GitPod, run node --inspect=0.0.0.0 test.js (the 0.0.0.0 is apparently necessary to allow the debugger to be connected to from any remote client - https://nodejs.org/en/docs/guides/debugging-getting-started/#security-implications)
  2. Click to allow the 9229 port to be public in Gitpod, then open up the exposed port in Chrome
  3. Assuming the host is xyz.gitpod.io, go to https://xyz.gitpod.io/json/list to get the URL in the devtoolsFrontendUrl property of the returned JSON - this is like devtools://devtools/bundled/js_app.html?experiments=true&v8only=true&ws=localhost:9229/<some-uuid>
  4. Paste that URL into Chrome, replacing localhost:9229 with xyz.gitpod.io:443 (port 443 for HTTPS)
  5. Then you should connect successfully

There are two odd things:

  • The dev tools’ websocket connection fails, as can be seen in the network tab (HTTP status code 400)
  • In step 1, if you do provide 0.0.0.0, then the /json/list path in step 2 is not available

One path may be to set up a local SSH tunnel to the debugger. There is a thread about setting up a SSH tunnel to a Gitpod workspace here - https://community.gitpod.io/t/how-to-ssh-into-gitpod-workspace/341; and the information about connecting to a remote node.js process over SSH is here - see the Node.js docs linked to above. But before I go down that road, I wanted to surface what I’m doing already in case there’s a gotcha I’m just missing.

Hi @jayfresh,

I couldn’t tell you the reason but the following works for me:

  1. Run node --inspect test.js (without 0.0.0.0)
  2. Make 9229 public.
  3. Change not just localhost in the devtools:... URL but also change ws to wss (since it’s a secured connection). My URL looks like this:
devtools://devtools/bundled/js_app.html?experiments=true&v8only=true&wss=9229-f98998cf-3be4-4397-91f5-c1dee2f7bd3b.ws-eu01.gitpod.io:443/5af2eafc-90a8-448b-ab50-b7189d0f39bf

Let me know if it works for you as well.

1 Like

Yes, amazing, it was the change from ws to wss that did it, thank you!

1 Like