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

Cannot see console output on Windows

Open Ivshti opened this issue 12 years ago • 26 comments

Hello,

It seems that node-webkit does not have console output on Windows (it just forks as a background process), which prevents me from properly debugging a custom NPAPI browser plugin.

How can this be solved?

The output in the debugger does not do the job, since it only outputs JS logs.

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Ivshti avatar May 01 '13 16:05 Ivshti

The console's output doesn't show at the cmd. You can see the output at the devtools

owenc4a4 avatar May 02 '13 01:05 owenc4a4

Please read the last sentance. Devtools is not enough since I need the ENTIRE stdout, including logs of C++ node.js modules, npapi plugins and node-webkit itself. Devtools will only show webkit output and anything from the JS console functions.

Ivshti avatar May 02 '13 01:05 Ivshti

You can try run node-webkit with --enable-logging. However, I didn't try whether it can stdout there.

Reference: http://www.chromium.org/for-testers/enable-logging

zhchbin avatar May 02 '13 05:05 zhchbin

--enable-logging shows the node-webkit log itself, but it does not include the NPAPI log, even at the highest verbosity level. BTW, it does not include the JS log too.

I found this similar problem: https://groups.google.com/forum/?fromgroups#!topic/native-client-discuss/jm9Vw4crezs I tried using "start /wait ... --enable-logging" as well, but that did not change anything in comparison to "--enable-logging" alone, just made CMD wait for the process to end.

Ivshti avatar May 02 '13 13:05 Ivshti

:+1: it should log to somewhere, shouldn't it?

tomasdev avatar Feb 10 '14 01:02 tomasdev

When I use --enable-logging in node-webkit, it shows console(seems like it's created for each nw process), it there is an option to not show there these consoles to user?

as3boyan avatar Mar 10 '14 10:03 as3boyan

@Ivshti did you ever find a fix for this? I'm trying to debug a node.js native module built for nw. It works on Linux but not Windows, and I'm unable to see any any of my STDOUT/printf messages since nw seems to be swallowing them.

Any tips on how to get debug output to the CMD window (or in my case, MSYS) would be appreciated.

orthecreedence avatar Apr 29 '14 19:04 orthecreedence

@orthecreedence yes, --enable-logging shows the console log under newer versions. Apparently something was broken before. Anyway. I don't know if this will show you logs from a node module.

Ivshti avatar Apr 30 '14 06:04 Ivshti

Bump, not working for me with the latest release in Windows

kirkouimet avatar Oct 10 '14 21:10 kirkouimet

@Ivshti Do you do --enable-logging on the output binary for windows or does it need to be done during build somehow?

mydigitalself avatar Dec 11 '14 12:12 mydigitalself

@mydigitalself I believe you add it within the package.json

tommoor avatar Dec 16 '14 06:12 tommoor

@mydigitalself the binary. It's part of "Content API of Chromium" mentioned at https://github.com/rogerwang/node-webkit/wiki/Command-line-switches.

Weirdly though, on Windows 8.1 now it doesn't seem to log anything for me still. I'm also using another switch (remote-debugging-port) which it works fine.

adam-lynch avatar Dec 16 '14 11:12 adam-lynch

I couldn't get it to work at all using that mechanism on Windows 7, when running the binary it spawns out a new window and returns to the command prompt.

However, I did find the secret hidden code for enabling Sawbuck, and that works a treat.

mydigitalself avatar Dec 16 '14 12:12 mydigitalself

Is there any way to see stdout/stderr on Windows? --enable-logging does not help impossible to debug app, nw crash earlier than error has printed in devtools

fleg avatar Aug 27 '15 11:08 fleg

Has someone figure out how to debug on windows? It is pretty tough if you cannot see any console output :S

toptierlabs avatar Oct 12 '15 15:10 toptierlabs

It's supported via passing --enable-logging=stderr CLI argument. Then you will see all console and NW logs like Linux and Mac.

ghostoy avatar Aug 17 '16 06:08 ghostoy

The --enable-logging=stderr thing worked for me, more or less, in a ConEMU terminal with NW v.0.23.6-sdk on Windows 7 SP1 (I'll probably try it on Windows 10 later tonight). I see Chromium's stderr output, although the only thing i see there is [9576:11240:0714/143612.982:WARNING:push_messaging_service_factory.cc(30)] PushMessagingService could not be built because InstanceID is unexpectedly disabled which comes up in my terminal for every window that is opened (including the DevTools window).

When I load up this content, either by referring to the html in my package.json or by loading it via nw.Window.open(...), I see none of the console.log(...) statements in my code or html show up in my terminal (or in my DevTools console for that matter). I can open up DevTools and make calls to console.log(...) myself there that are reflected in my terminal, but that is the only output I see. There is nothing from the console.log() statements in my own code or html or anything from any of the process.stdout.write(...) or process.stderr.write(...) statements anywhere.

my test html (named main.html):

<html>
  <head>
    <script type='text/javscript'>
      console.log("at INIT: console output");
      process.stdout.write("at INIT: stdout output!");
      process.stderr.write("at INIT: stderr output!");

      window.addEventListener('load', function(evt) {
        console.log("on LOADED: console output");
        process.stdout.write("on LOADED: stdout output!");
        process.stderr.write("on LOADED: stderr output!");
      });
    </script>
  </head>

  <body>
    Some Content!
  </body>

</html>

when i test loading this from a .js file, I just run nw.Window.open('main.html');

and for good measure, here is my package.json:

{
  "name": "nwStdStreamsTest",
  "description": "a dumb project to verify nw.js bugs.",
  "version": "0.0.1",

  "main": "main.html",
  "window": {
    "show": true,
    "frame": true,
    "toolbar": true,
    "show_in_taskbar": true,
    "min_width": 100,
    "min_height": 100,
    "resizable": true
  },

  "dependencies": {
    "nw": "= 0.23.6-sdk"
  }

}

I am primarily a Linux user and have seen this feature working on OS X as well as Linux, as one would expect STDOUT and STDERR to work. I've also seen all of the other bugs reporting this same issue but IMHO there doesn't seem to be a lot of attention to this issue from the nw team. The consensus appears to be, unilaterally, that it DOES work and everyone else is just plain wrong.

If anything, I'd call this a bug based solely on the fact that it compromises expectations from standard streams, which haven't changed as far as back as anyone can remember and might be just about as "legacy" as legacy can get. This complexity will, in turn, be inherited by consuming implementations, adding a catch-22 to otherwise cross-platform applications.

sal-ortiz avatar Jul 14 '17 19:07 sal-ortiz

This used to work great for me, if I put "chromium-args": "--enable-logging=stderr" in my package.json, until I updated my version of nwjs from 0.26.0 to 0.28.1.

joshperry avatar Feb 22 '18 04:02 joshperry

I'm also trying to see console output on Windows 7. Adding "chromium-args": "--enable-logging=stderr", in package.json works great on OSX, but when trying to develop on Windows this doesn't help. The NW.js SDK 0.31.4 release forks and immediately returns control to the CLI, never outputting anything to the Windows console.

pineapplemachine avatar Jul 07 '18 16:07 pineapplemachine

Same problem here. I've developed a native addon, and trying to debug issues with it is very difficult without being able to see a console log.

claytongulick avatar Jul 16 '18 21:07 claytongulick

Workaround: visible NW.js console output on Windows

Put this script in the same directory that you would run nw . and whenever you need to test your app run node this-script.js instead.

You'll probably need to have "chromium-args": "--enable-logging=stderr" set in package.json.

The resulting logging behavior is the same as I get on OSX. (Where I didn't have to bother with a wrapper just to make sure stdout and stderr actually get displayed somewhere.)

Before: https://i.imgur.com/CmRgNMT.png After: https://i.imgur.com/e3qsEnL.png

// Run nwjs
const childProcess = require("child_process");
const proc = childProcess.exec("nw .");

// Keeps this wrapper process running
let keepAlive;
let quit = false;
function keepAliveCallback(){
    if(!quit) keepAlive = setTimeout(keepAliveCallback, 1000);
}
keepAliveCallback();

// Relay stdout and stderr from process until it exits
proc.stdout.on("data", function(data){
    process.stdout.write(data);
});
proc.stderr.on("data", function(data){
    process.stderr.write(data);
});
proc.on("exit", function(){
    quit = true;
});

pineapplemachine avatar Aug 12 '18 14:08 pineapplemachine

@pineapplemachine that worked for me, THANKS!

I just had to add some adjustments to my console.log logger, it works if I use a single string/argument, not more than one, but it's fixable with JSON.stringify :)

darkguy2008 avatar Sep 02 '19 19:09 darkguy2008

Thanks @pineapplemachine. This also saved me, today. I'm surprised this is still necessary, when this has been an issue for so long. @rogerwang Can't a better nw CLI parameter be added to automatically dump console to stdout instead of spawning a new process and returning to the shell?

sysrage avatar Mar 23 '20 23:03 sysrage

+1

franck34 avatar Apr 08 '20 03:04 franck34

It this what you are looking for? https://docs.nwjs.io/en/latest/For%20Users/Debugging%20with%20DevTools/

michaelusantiago avatar Feb 08 '22 02:02 michaelusantiago

FWIW, I've just published nwdc as a workaround for this behavior. It's basically @pineapplemachine's code published as an NPM package, so you can run an NW.js app with npx nwdc . instead of nw ..

A binary executable (nwdc.exe -- built with pkg) is also available in "Releases", so you don't even need to have Node.js installed. Just copy the executable to your NW.js SDK directory (or anywhere else in your PATH) and run your NW.js app with nwdc . instead of nw ..

https://github.com/nwutils/nwdc

sysrage avatar Mar 02 '22 17:03 sysrage