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

Already on GitHub? Sign in to your account

console.log from node modules #196

AlgoTrader opened this Issue Nov 19, 2012 · 25 comments


None yet
5 participants

I see the strange behavior. If module installed in node_modules contains console.log, my app "hangs" , gray screen is shown and debugger go unresponsive. console.log in webkit side works just fine.

After removing console.log from node libs app returns to work. What may cause hang while printing console.log from node.js side?

Hint: Uncaught Error: Implement me. Unknown stream file type!
I saw it in debugger


rogerwang commented Nov 19, 2012

Hello, please see #184.


rogerwang commented Nov 19, 2012

And the gray screen should be that the process quits on the uncaught error.


rogerwang commented Nov 19, 2012

@zcbenz we need to check why this lead to a crash.

@AlgoTrader what's your OS version? Thanks in advance.

Yes, exactly. That's throw, but the window is alive, just go gray and unresponsive (bar is working). It would be great to have a meaningful error message, not just unresponsive gray screen (can we redirect to a message error page?)

You are right, it's windows. The next question is what to do. The current default behavior is pretty unreasonable. It would be better to just to redirect console.log to some null device. Any hints of how to survive?

Want to say it is the great project, thank you guys.

It's Win 7 64 bit. I can reload the URL and things go work again (starting from point zero). Sometimes throw cause error in debugger and sometimes cause gray screen. I think throw handling is different in node and webkit. Do you need other info on the issue? In direct call of node module method is prints the Uncaught error, in callbacks it hangs, I believe. it is my current vision.

I am experiencing the same issue, and it's getting really annoying. Console.log won't work for me, if called from a node context. I am on Mac OS X Mountain Lion. I get a grey screen, also my debugger window will detach.


rogerwang commented Nov 19, 2012

For a workaround you can just redefine console.log to your own function.


rogerwang commented Nov 19, 2012

@AlgoTrader the window and the web page content are from different process.


rogerwang commented Nov 19, 2012

@AlgoTrader can you show your code where "in callbacks it hangs"? Thanks

Checked the process list. There was single process in list, window process I think. After reloading URL in bar, there were two processes again. So it is clear. node throws at console.log and process quits. Next question is how to make console.log working more reasonable then now

It is pretty big, it's quite big npm module with thousands of lines. I would try console.log in process.netTick and setTimer callbacks. Mine crash is in callback of TCP connection (the SOAP response), but I don't think it's related to TCP

So the minimalistic reproduce:

//console.log("This cause a message in debugger");

process.nextTick( function() {
console.log("this causes gray screen");

Including this module cause gray screen at require. After uncommenting of first line just shows throw in debugger

@rogerwang rogerwang closed this in d41b9ea Nov 19, 2012


rogerwang commented Nov 19, 2012

The crash has been fixed with the previous commit. Will be released in 0.3.4. Thanks for reporting.

zcbenz added a commit that referenced this issue Nov 20, 2012

When I call console.log from a WebKit module with version 0.3.4 on OS X, it doesn't crash but I also don't see any output in the development console. Is this the expected behavior?

I wrote the following simple module as an experiment:

// require-me.js
module.exports.console = console;
module.exports.windowConsole = window.console;

Then I require the module from the developer tools, and try calling functions on each of the exported consoles:

module = require('./require-me');
module.console.log("Testing") // nothing happens
module.windowConsole.log("Testing") // prints testing to the developer tools console

console.log(module.console.log.toString()) // output below, looks like Node's implementation of console.log, not WebKit's
function () {
  process.stdout.write(util.format.apply(this, arguments) + '\n');

It seems like global.console isn't being properly overridden with WebKit's in the node module's context. Was this fixed prior to 0.3.4?

Thanks! 🏭

@ghost ghost assigned rogerwang Nov 27, 2012


rogerwang commented Nov 27, 2012

I can confirm this. Will fix it. Thanks for reporting.

@rogerwang rogerwang reopened this Nov 27, 2012


rogerwang commented Nov 27, 2012

@nathansobo , I just checked it again. On Linux and Mac 'console.log' is not supposed to be replaced by the one from WebKit, because the console works on these 2 platforms, and you should see the log text printed on your console. On windows, since a GUI application doesn't have a console, we replaced the Node's implementation with Webkit's.

@rogerwang rogerwang closed this Nov 27, 2012

@rogerwang I can see the logic in that, but for our use case at least, it would be better to have everything log in the developer tools. Our current application, based on CEF, has its own version of require that loads all our application code synchronously. We really like this design, as it allows us to use Node's model of synchronously requiring our code, rather than relying on script tags, concatenation, etc. But that means that 99.999% of all our code is loaded via require, not just a subset of it that's the Node modules. This means it's important that code that's loaded with require behaves the same way as code that's loaded with a script tag.


rogerwang commented Nov 28, 2012

I see. And it's reasonable to keep the uniform behavior across the supported platforms. will fix it.

@rogerwang rogerwang reopened this Nov 28, 2012

💙 ❤️ 💙


rogerwang commented Nov 30, 2012

close with the previous commit.

@rogerwang rogerwang closed this Nov 30, 2012


I think that @nathansobo's issue from Nov 26, 2012 has reappeared: I find myself unable to log to either DevTools or the command line on linux using the v0.13.0alpha6 build.


<!DOCTYPE html>
    'use strict';
    var testmodule = nw.require('./testmodule');
    console.log(console === testmodule.console);


'use strict';
console.log('hello from testmodule'); // prints nothing
module.exports.console = console;
user@hostname /path/to/nw$ .
[1208/012935:INFO:nw_package.cc(175)] /path/to/nw .

Meanwhile, the DevTools renders something like this:

▶ Console                                                            index.htm:9
▶ Console                                                           index.htm:10
false                                                               index.htm:11

So obviously, a required module has a reference to some console object. However, it is clearly not the same one the page is getting.

I found a workaround for my own issue. Although required modules don't get the same console as the window script, they all get the same console. This means one can set it once, in one file, without modifying every file.

Put the following code into a file and call it, say, consoleHack.js:

'use strict';
module.exports = function consoleHack (newConsole) {
  console = newConsole;

Then, from index.html or wherever, do this before any other modules are required:



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