Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to restart Node application from Chrome Devtool

All:

I wonder How to signal Node debugger(Node ver: 8.9.4) to rerun the code from Chrome DevTool?

The way I use it is:

  1. node --inspect-brk app.js
  2. Open chrome://inspect/
  3. Click the link shown under Remote Target
  4. Debug in pop up console.

If I want to run the app again to back to same breakpoint, currently I have to close the devtool, and repeat step 1-4, I wonder is there anyway I can directly reload and run app.js again in devtool console(just like if you run node inspect app.js you can use restart to reload and run)?

like image 858
Kuan Avatar asked Apr 19 '18 19:04

Kuan


People also ask

Can you debug Node JS application in Chrome DevTools How?

Using Google Chrome DevTools to Debug The next step is to head to Chrome, open a new tab, and enter the URL chrome://inspect/ . Click on “Open dedicated DevTools for Node” to start debugging the application. It will take a couple of seconds to view the source code in Chrome DevTools.

How do I debug backend in Chrome?

Press F5 on the keyboard or click Start Debugging button to launch the Debugger. Launch Chrome. Refresh the page to pause the code at the set breakpoint.


2 Answers

Maybe you can restart the script doing the following steps:

As you can see the app is running and we have values inside the totalOrders variable: enter image description here

Right click the (annonymous) at the Call Stack, and click "Restart frame":

enter image description here

The script has restarted and the variable is undefined again:

enter image description here

I hope this answer will help someone.

like image 105
PauloBorba Avatar answered Oct 29 '22 01:10

PauloBorba


On Chromium 85, Ubuntu 21.10, node.js 14.17.0, after I click on DevTools "Open dedicated DevTools for node", the popup window automatically reconnects whenever I restart the program.

So if I want to restart the program, I can:

  • Alt + Tab to go to terminal
  • Ctrl + C to kill the program
  • Up to go up history to re-run the command
  • Re-run the node --inspect-brk app.js command
  • Alt + Tab to go back to the dedicated DevTools window

and after this the debugging process will have restarted from the beginning, with all breakpoints kept.

It is not as ideal as a button on the UI, but at least you don't have to click links on the web UI with the mouse which would be the most painful part.