nw.js icon indicating copy to clipboard operation
nw.js copied to clipboard

0.13-beta3 console.log doesn't work in node context

Open jonwwilkes opened this issue 10 years ago • 17 comments

On Linux i386 0.13-beta3, I can't get console.log to print to the terminal window from the node context. Also, it seems that errors originating in the node context don't get output to the terminal window, either.

package.json: { "name": "foo_app", "main": "index.html" }

index.html:

Hello Hello World

foo.js: exports.bar = function() { // console.log("hello from node context"); global.console.log("hello from node context"); }

jonwwilkes avatar Jan 16 '16 03:01 jonwwilkes

Just to give a little more info: in nw.js 0.12 I get this to the devtools window and the Gnome terminal:

[15259:0115/231555:INFO:CONSOLE(2)] ""hello from node context"", source: /home/user/Downloads/nwjs-v0.12.2-linux-ia32/foo.js (2)

I can't figure out a trivial test, but in my application there is a class of error messages that only get printed to the Gnome terminal. In nw.js 0.12 it gives the stack trace for those errors, which of course is a much valued feature. :)

jonwwilkes avatar Jan 16 '16 04:01 jonwwilkes

See #4244

offshore avatar Jan 16 '16 19:01 offshore

@offshore: thanks for the reference. But I'm not looking for workarounds-- I'm reporting a regression. I want node-context errors reported to the terminal window from which I started nw.js. With 0.12 I get that. With 0.13-beta3 I cannot. Therefore it's a regression.

Also notice that "console.log" and/or "global.console.log" do not print out to a devtools window.

jonwwilkes avatar Jan 16 '16 20:01 jonwwilkes

Also-- I apologize for not having a clear example of an error message being printed to the terminal in 0.12 but getting suppressed in 0.13-beta3. However, it's pretty easy to think of examples where this would happen. For example: suppose I have a node module that depends on the "net" module to receive data over the wire. If I screw up the algorithm that processes the data the resulting error won't get printed because it's not associated with any browser context. Therefore I should get an error printed to the terminal window, as happens in 0.12.

try/catch can help in the interim, but that is too clunky, verbose, complicated, and error prone to be a general solution.

jonwwilkes avatar Jan 16 '16 20:01 jonwwilkes

@jonwwilkes That's not a regression. Please read carefully the 0.13 Architecture changes. And I was referencing #4244 not for workarounds, but for paying attention to that changes. As for me, the real problem here is that is no way to fine-control console output for now; and this maybe needs to be taken into consideration, well, if it's not already.

offshore avatar Jan 18 '16 10:01 offshore

I'm really only interested in errors that got reported under 0.12 and now don't get reported at all under 0.13. I gave console.log as an easily reproducible example of suppressing output, but I think it's a different issue. I'll file another bug to show suppression of error output in the node context.

jonwwilkes avatar Jan 18 '16 15:01 jonwwilkes

@offshore: would you mind explaining exactly what "background page" means in the Architecture changes you told me to carefully read? Thanks.

jonwwilkes avatar Jan 18 '16 15:01 jonwwilkes

@jonwwilkes from this comment:

...And finally, have a look at 0.12 to 0.13 migration notes' architecture changes:

The Node.js context is put in the DOM context of the background page, which is shared between opening windows as in 0.12 and before.

This means that in 0.13 you have to expect things sent to console.log inside node context appear in background's page devtools. The terminal window seems not related to this for me; as I said above, I think it's another issue about fine-controlling std streams.

offshore avatar Jan 18 '16 17:01 offshore

@offshore: in my example code above, what is the "background page devtools"? Is it the devtools window for index.html?

If so, then the bug I'm reporting is that there is a class of node context errors which do not get printed there. (And again, I'll try to supply a better example to show this.)

jonwwilkes avatar Jan 18 '16 18:01 jonwwilkes

@jonwwilkes we are just talking about different things. A better example is definitely an option.

offshore avatar Jan 18 '16 18:01 offshore

@offshore: I'll do that. But I still don't understand what "background page" refers to, and the documentation you told me to carefully read doesn't explain what it refers to.

jonwwilkes avatar Jan 18 '16 18:01 jonwwilkes

image Just to make things clear :)) Or maybe we completely misunderstood each other.

offshore avatar Jan 18 '16 18:01 offshore

@offshore: Ah, I see. The documentation is very difficult to understand in this case-- if you're not already thinking about that menu item it's an ambiguous term.

Anyhow, I'll do some more testing and try to post a clean bug example later.

jonwwilkes avatar Jan 18 '16 18:01 jonwwilkes

Np, I thought you saw that comment about connecting to debugger from outside; "index" page has a list of devconsoles available, one of them is "background".

offshore avatar Jan 18 '16 19:01 offshore

I'll see having logs from background page printed to console too.

rogerwang avatar Jan 19 '16 02:01 rogerwang

@rogerwang: sounds good. I just wasn't thinking in terms of the Chrome app, so it did not click what "background page" in the architecture description meant.

Thanks to @offshore for the screenshot clearing that up.

jonwwilkes avatar Jan 19 '16 05:01 jonwwilkes

@jonwwilkes turns out --enable-logging=stderr is needed with the new Chromium code. Will add this to FAQ.

rogerwang avatar Jan 19 '16 06:01 rogerwang