How to disable in the node debugger "break on first line"

13,517

Solution 1

According this issue I have opened in the node repo, currently, this is not possible. This is also something that the node guys don't see as a feature worth implementing "because it seems kind of pointless. […] Attaching to a running process does exactly" the same thing. See the rest of the discussion in the mentioned issue.

If you think you want such a feature, vote this up, leave a comment in the Github issue, and, if no response, open a new one and post it here as well.

Solution 2

There are actually two debugger concepts in node: V8 debugger (with its TCP-based protocol) and a node command-line debugger (CLI).

When you run node debug app.js, a debugger CLI is run in the master node process and a new child node process is spawned for the debugged script (node --debug-brk app.js). The option --debug or --debug-brk is used to turn on V8 debugger in the child process.

The difference between --debug and --debug-brk is that the latter one adds a breakpoint on the first line, so that execution immediately stops there.

I would suggest you this solution:

  1. When you are creating a child process from your webserver, run node --debug instead of node debug. This way there is only one child process created, it is running your application and it is not paused on the first line.

  2. Now you can use any debugging tool that supports V8 debugger protocol - node built-in CLI debugger, node-inspector or you can event implement your own debugger front-end (GUI) if you like. (I presume this is what you are trying achieve by running CLI debugger in background?)

    If you decided to use built-in CLI, just spawn another another child process and tell node CLI debugger to connect to the process started in step 1:

    node debug localhost:5858

    and continue as before.

Solution 3

Found this while looking for the answer myself - Seems that you can simply run

node-debug --debug-brk=0 (progname)

Hope this helps someone.

Solution 4

I solved same issue just by switching from node v6 to v7

Solution 5

Write a chrome extension to click the start button

1. Run shell

mkdir run_as_devtools
cd run_as_devtools
touch manifest.json
touch run_as_devtools.js

2. Edit the files

run_as_devtools.js:

if (location.protocol === 'chrome-devtools:' && location.href.match(/ws=localhost/))(function () {
    'use strict';
    setTimeout(function () {
        try {
            document.querySelector('html /deep/ .long-click-glyph').click();
        } catch (e) {
            console.log(e);
        }
    }, 500);    
})();

manifest.json: (it uses chromevox's key, so don't use it with chromevox)

{
   "content_scripts": [{
      "js": [ "run_as_devtools.js" ],
      "matches": [ "<all_urls>" ]
   }],
   "key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDEGBi/oD7Yl/Y16w3+gee/95/EUpRZ2U6c+8orV5ei+3CRsBsoXI/DPGBauZ3rWQ47aQnfoG00sXigFdJA2NhNK9OgmRA2evnsRRbjYm2BG1twpaLsgQPPus3PyczbDCvhFu8k24wzFyEtxLrfxAGBseBPb9QrCz7B4k2QgxD/CwIDAQAB",
   "manifest_version": 2,
   "name": "Elevated Devtools extension",
   "version": "1.0"
}

3. Install the extension

Chrome settings - More tools - Extensions- Developer mode - Load unpacked extension - select run_as_devtools folder

P.S. Better to use it with Node inspector manager https://stackoverflow.com/a/43018133/4831179

Reference: https://stackoverflow.com/a/17044405/4831179

Share:
13,517

Related videos on Youtube

Gabriel Petrovay
Author by

Gabriel Petrovay

Dreaming big ...

Updated on June 02, 2022

Comments

  • Gabriel Petrovay
    Gabriel Petrovay about 2 years

    Is there a command line argument or an environment variable that disables the "break on first line" feature of the node debugger?

    • loganfsmyth
      loganfsmyth about 11 years
      What arguments are you passing to node now?
    • Gabriel Petrovay
      Gabriel Petrovay about 11 years
      only node debug script.js
    • Dreen
      Dreen about 11 years
      Ive looked for this myself and dont think thats possible. Just hit 'c' as soon as you start debugging.
  • Gabriel Petrovay
    Gabriel Petrovay about 11 years
    Thanks Miroslav for your answers both here and on Github! What we are doing is building a web debugger client for an internal web framework we have build. We are still missing the "disable break on first line" feature. The lack of this feature probably force us to use an extra process in our stack or hardcode the c (continue). We have now all this info now: SIGUSER1, --debug, --debug-brk, etc. We will for sure figure out/hack something. :)
  • Miroslav Bajtoš
    Miroslav Bajtoš about 11 years
    The thing I don't understand: why do you use CLI interface to communicate from webserver to debugged process? Why don't you use V8 debugger protocol directly? You can look at CLI implementation to see how the commands are translated to V8 requests: github.com/joyent/node/blob/master/lib/_debugger.js
  • Gabriel Petrovay
    Gabriel Petrovay about 11 years
    Yes, we will use the V8 protocol (that's why the question on the node mailing list you answered: groups.google.com/forum/?fromgroups#!topic/nodejs/h6lYK3i6KT‌​A). We have done a proof-of-concept that was running based on the CLI. But, yes, the V8 protocol is the right solution.
  • Steve Seeger
    Steve Seeger over 7 years
    This did not work for me on latest version as of this writing. Using just --debug did work.