3

The Node.js debugger hides most of my string variables, it prints ... instead, like so: (there's a variable named source)

$ node debug 127.0.0.1:9101
debug> 
debug> exec('source')
'<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" class="DW dw-pri js no... (length: 6408)'
debug>
debug> repl
Press Ctrl + C to leave debug repl
> source
'<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" class="DW dw-pri js no... (length: 6408)'

As you can see, it replaces most of the string, with .... I've googled for a while and typed help in the console. Finally posting here — how do I view the full contents of the string? console.log(source) didn't do anything.

Edit: Now I noticed that console.log does print the variable, in Selenium's terminal window, which perhaps is what I ought to have expected. Not sure if console.log and switching to the Selenium terminal window, is what I'm supposed to do

Update:

Typing just source doesn't work, outside repl:

debug> source
ReferenceError: source is not defined
    at repl:1:1
    at ContextifyScript.Script.runInContext (vm.js:32:29)
    at Object.runInContext (vm.js:87:6)
    at Interface.controlEval (_debugger.js:971:21)
    at REPLServer.eval (_debugger.js:745:41)
    at bound (domain.js:280:14)
    at REPLServer.runBound [as eval] (domain.js:293:12)
    at REPLServer.onLine (repl.js:536:10)
    at emitOne (events.js:96:13)
    at REPLServer.emit (events.js:191:7)

(and when inside repl, the variable gets truncated, as shown in the topmost snippet above.)

And print(source) or print('source'):

debug> print('source')
ReferenceError: print is not defined
    at repl:1:1
    at ContextifyScript.Script.runInContext (vm.js:32:29)
    at Object.runInContext (vm.js:87:6)
    at Interface.controlEval (_debugger.js:971:21)
    at REPLServer.eval (_debugger.js:745:41)
    at bound (domain.js:280:14)
    at REPLServer.runBound [as eval] (domain.js:293:12)
    at REPLServer.onLine (repl.js:536:10)
    at emitOne (events.js:96:13)
    at REPLServer.emit (events.js:191:7)
debug> repl
Press Ctrl + C to leave debug repl
> print(source)
ReferenceError: print is not defined

There aren't many commands to choose among: (in the debugger)

debug> help
Commands: run (r), cont (c), next (n), step (s),
out (o), backtrace (bt), setBreakpoint (sb), clearBreakpoint (cb),
watch, unwatch, watchers, repl, exec, restart, kill, list, scripts,
breakOnException, breakpoints, version
8
  • 1
    Have you tried simply typing the name of your variable without console.log() in the debug command line ? Commented Jun 20, 2017 at 4:32
  • What about print instead of exec? Commented Jun 20, 2017 at 4:42
  • Hi @Soviut, I tested typing just source. Then the debugger won't find source, because the source variable is available only in the Node.js debuggee process, but not in the debugger itself. Commented Jun 20, 2017 at 8:53
  • Hi @OmG, I tested print — there's no such function available (not in the debugger, and not inside the repl) Commented Jun 20, 2017 at 8:55
  • Is there some reason you are not using devtools? Commented Jun 20, 2017 at 9:08

2 Answers 2

2

watch("your_var_name") will print the value of the variable(s) you watch at each breakpoint (you must put the variable/expression name in quotes).

This seems to be the closest thing available on the command line, although frankly just writing

console.log(thing I want to log); debugger;

feels easier to me.

Sign up to request clarification or add additional context in comments.

Comments

0

@Ryan answers is right, you could easily use watch('var_name'); Furthermore, if you just want to print the value of the 'watched' variable without step ahead debugging, you can print all the set watchers until now and related values with the keyword "watchers". It will print the list of set watchers and their values.

1 Comment

This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.