Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to load files to Chrome when debugging node scripts

Currently it's possible to debug node scripts using Chrome as described here. However, if I run like this:

node --inspect --debug-brk myscript 

It will only load myscript to the browser and I'll be able to put breakpoints in this file. But suppose that myscript requires anotherscript and I want to put a breakpoint in this script. I don't see how this can be done since Chrome inspector only loaded myscript.

Is there any way to load a file into Chrome inspector before this files is required in the script and Chrome loads it by itself?

I'm currently modifying sources and put debugger; statement there which works. But I was thinking that should be something more apt for this purpose.

like image 481
Max Koretskyi Avatar asked May 26 '26 13:05

Max Koretskyi


1 Answers

It seems that it's currently not possible.

One possible solution to avoid modifying sources is to put a breakpoint at the end of the script. In this way the Chrome by the time the breakpoint is reached and the execution is paused Chrome will have loaded all relevant files. You can then open any file using Ctrl+P and put a breakpoint there. Chrome keeps breakpoints between sessions if you use Open dedicated Chrome DevTool for Node option:

enter image description here

Then simply restart you node application. See more details in the This will make you more efficient at debugging Webpack unspecified build errors article.

like image 189
Max Koretskyi Avatar answered May 28 '26 05:05

Max Koretskyi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!