Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot see console output on Windows #685

Open
Ivshti opened this issue May 1, 2013 · 26 comments
Open

Cannot see console output on Windows #685

Ivshti opened this issue May 1, 2013 · 26 comments

Comments

@Ivshti
Copy link
Contributor

Ivshti commented May 1, 2013

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.

@owenc4a4
Copy link
Contributor

owenc4a4 commented May 2, 2013

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

@Ivshti
Copy link
Contributor Author

Ivshti commented May 2, 2013

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.

@zhchbin
Copy link
Contributor

zhchbin commented May 2, 2013

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

@Ivshti
Copy link
Contributor Author

Ivshti commented May 2, 2013

--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.

@tomasdev
Copy link

👍 it should log to somewhere, shouldn't it?

@as3boyan
Copy link

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?

@orthecreedence
Copy link

@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.

@Ivshti
Copy link
Contributor Author

Ivshti commented Apr 30, 2014

@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.

@kirkouimet
Copy link

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

@mydigitalself
Copy link

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

@tommoor
Copy link

tommoor commented Dec 16, 2014

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

@adam-lynch
Copy link

@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.

@mydigitalself
Copy link

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.

@fleg
Copy link

fleg commented Aug 27, 2015

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

@toptierlabs
Copy link

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

@ghostoy
Copy link
Member

ghostoy commented Aug 17, 2016

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

@sal-ortiz
Copy link

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.

@joshperry
Copy link

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.

@pineapplemachine
Copy link

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.

@claytongulick
Copy link

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.

@pineapplemachine
Copy link

pineapplemachine commented Aug 12, 2018

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;
});

@darkguy2008
Copy link

@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 :)

@sysrage
Copy link

sysrage commented Mar 23, 2020

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?

@franck34
Copy link

franck34 commented Apr 8, 2020

+1

@michaelusantiago
Copy link

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

@sysrage
Copy link

sysrage commented Mar 2, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests