Reuse/restart the same node inspect session - node.js

Once a node.js program has run to completion in the context of an --inspect session (i.e. via the Chrome dev tools debugger) is it possible to re-start it without having to re-issue the --inspect command from the command-line?
The issue with re-issuing an --inspect command is that it generates a different chrome url every time and one has to then copy-paste this into Chrome each time. Ideally I want to be able to push F5 to re-start the chrome debug session.
So two issues:
I cannot restart the debug session without killing the current (i.e. no way to just refresh).
I have to copy paste the url into chrome each time I start a new session. (not as bad as issue 1.)

Here's a couple of options for you, though neither will provide you with a simple F5 refresh, both are significantly better than copy/pasting the new URL generated by the --inspect flag.
The most optimal solution is installing this extension for Chrome or Opera: https://chrome.google.com/webstore/detail/nim-node-inspector-manage/gnhhdgbaldcilmgcpfddgdbkhjohddkj
This will manage the node inspector for you. Just click the resulting toolbar icon and select "Auto" from the toggle switch. Your browser will then open the Chrome DevTools in inspection mode whenever your node server generates an inspection URL.
If you want to go the low-tech (and more manual) route, or don't want to install a Chrome extension, just open your Chrome to "chrome://inspect", wait a moment, and you'll get a list under Remote Target that will include your Node server. Just click the "inspect" link there, and the DevTools will open with the current URL. The downside of this method is you'll need to reclick that "inspect" link every time your server restarts. It avoids copy/pasting URLs, but still involves manual labor.

It's also significant to note that if you simply update the url of your inspector with the new ID, it will also work.
When you restart node, you'll get something like this:
Debugger listening on ws://127.0.0.1:9222/72c791b7-178f-47e8-93b1-d1be4d5ffe1e
The bit after the port/ is what you want. Replace that code in your inspector's url and it will connect to the latest session.

Related

Can't debug node.js using Chrome DevTools

When I run node --inspect app.js it says "Debugger attached". Then I open up chrome://inspect and I see my app running there so I click either Open dedicated DevTools or Inspect (next to the app's name). No matter how I open Node DevTools though, it just doesn't seem to be connected to anything (I can't see the source code there, the debugger statements are ignored, nothing logs to the console etc). I also tried opening it by opening regular DevTools and clicking the green Node icon.
It's weird because Chrome clearly sees the server running and something is clearly connecting to Node (and I don't think there's anything else on my network that could do that) but I still can't get DevTools to even acknowledge the server's existence.
I also distinctly remember debugging something the same exact way a few weeks ago and back then everything worked fine (although I remember I also struggled with this a bit but I somehow got it to work at the end, I think attaching the name of the file at the end of the command instead of in putting it in the middle did the trick at the end). The only thing that's happened since then is that I updated from v8 to v10 (LTS)
I've obviously tried rebooting and also reading every manual and article about node --inspect out there, nothing helped.
Chrome version: 92
For me, the problem was The Chrome DevTools was not looking for the connection port my Node.js process was using.
I did the following:
Start the node process with --inspect flag. It started the process on port 9239.
Type chrome://inspect/#devices in Chrome address bar.
Click "Open dedicated DevTools for Node" in the devices page.
It opens the "DevTools-Node.js" window.
Click the "Connection" tab.
Click "Add connection" button.
Type localhost:9239 in the text box and click "Add".
After adding the correct port, the DevTools connected to the Node.js process and I was able to debug it.
I was facing same problem, I have solved it by
1) Updated chrome to latest version and relaunched it
2) Restarted node --inspect server.js
3) Noted port number as shown here
port number
4) Opened chrome://inspect and added localhost: port number noted in step 3
update connection in chrome
use command instead of node --inspect:-
node --inspect-brk
Seems to be a new chrome issue: https://github.com/nodejs/node/issues/26887

Stop node-debug from opening a new browser window

The command:
node-debug sls offline
opens a new browser window every time it is run.
How do we stop it from opening a new window every time? I want to reuse the existing window!
This is a known issue with node inspector. Take a look here.
Since 0.9.0 we use https://github.com/benderjs/browser-launcher2 to
start the browser, and make sure it's Chrome/Chromium/Opera (i.e. the
browsers that can properly render node inspector; we detect installed
browsers in the system and choose the most appropriate one; earlier we
used opener module which just delegated opening the browser to the OS,
which would open the defaul browser, which could have been e.g.
Firefox) and this could be the reason why the behavior has changed.
browser-launcher2 actually does a bit more than just launching a
browser, for instance it creates a new profile for Chrome in a
subfolder of ~/ - this is probably the issue that #CalvinScott
reported (i.e. Chrome that was opened was the new profile created by
browser-launcher, not your original profile; you should be able to
open your original profile of Chrome normally)
Also, you may consider this:
Since version 6.3, Node.js provides a buit-in DevTools-based debugger
which mostly deprecates Node Inspector, see e.g. this blog post to get
started. The built-in debugger is developed directly by the
V8/Chromium team and provides certain advanced features (e.g.
long/async stack traces) that are too difficult to implement in Node
Inspector.

How to create Windows shortcut for chrome-devtools link?

Instead of copying and pasting the link for the chrome-devtools inspector (for use with node.js) each time, is it possible to create a shortcut link to access it?
I've tried the normal way to create a shortcut and if I start the url with http://devtools/..., it opens that URL, however when the "http://devtools" is changed to "chrome-devtools://devtools" (which is required for inspector to work), the chrome shortcut just opens up the default page as if it doesn't see this url.
So using this in the target for the shortcut:
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" chrome-devtools://devtools/remote/serve_file/#521e5b7e2b7cd66e4006a8a56cb9c4e5534a5ef/inspector.html?experiments=true&v8only=true&ws=localhost:9229/node
results in the url being ignored, but changing the:
"chrome-devtools://"
to
"http://"
causes the url to be used although it isn't valid since it has to begin with "chrome-devtools://".
So it looks like shortcuts only use site addresses that are not prefixed with "chrome-devtools://". I've tried putting quotes around the url, but that doesn't solve it.
Does anyone know how to make this work?
I'm switching from using node-inspector for debugging to google-chrome-devtools since node-inspector no longer works with the latest version of node.js and support seems to be dropping in favor of the new --inspect option on node.js.
Environment is Windows 10, node.js v6.3.1, Chrome version 53.0.2785.116 m

Did Chromecast update break debugging?

Before the recent firmware update, web-based debugging (at port 9222) would persist between activities. Now any transition, say from the home screen to my app, stops the debugger with a message at the top saying...
Detached from the target
Remote debugging has been terminated with reason: target_closed.
Please re-attach to the new target.
It's not a huge problem to start a new debug window, but I'm worried that if the debugger isn't running when my app is loaded I won't get the benefit of the "Disable cache (while DevTools is open)" option.
Any details or workarounds would be appreciated.
UPDATE
Confirmed! In my case at least, the debugger stops with the above error and the latest version of my html, javascript, etc. does not get loaded
Try this as a work around and see if it works: when your page is loaded, run window.location.reload() in the debug console to reload the page (so you get a full debugging info from the beginning without missing anything) or window.location.reload(true) to do the same and clear cache as well.

Launching a web page in a different process

I want to launch the browser in a different process when a particular link is clicked on the page. When I checked the net I found the following tip: http://www.dslreports.com/faq/3849 . But there we have to change the registry. Is there any simple way of doing this without touching the registry?
If you use the Google Chrome browser, each new window or tab runs in a separate process. Internet Explorer version 8 will do the same (it's currently in the second beta round).
Earlier versions of IE will run a new window in a separate process if it is launched from, say, the Start menu or the command line, or a link in an email (but not by clicking a link within IE). I imagine you could create a proxy that the client would run through, which would intercept the links you care about and launch them by running a command line request. That seems like more trouble than mucking with the registry though (assuming that registry change still works -- looks like your link is from 2002).
I don't believe this is possible unless you change the client computer setup or software it's running.
Why do you want to do this?

Resources