Skip to content

Full Console Logging

Brian Bothwell edited this page May 14, 2021 · 2 revisions

The following steps will allow viewing console logging from the full application, in both production and development environments. This will show console logs, JavaScript warnings/errors, and Chromium console messages from every window opened by NW.js as well as any scripts running in the Node context.

  1. Install Node.js and ensure node is in your path.

  2. Install the NW.js SDK and ensure nw is in your path.

  3. Add the following to the package.json of the NW.js application:

  "chromium-args": "--enable-logging=stderr",
  1. Create the following debug.js script anywhere:
// 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;
});
  1. Run node /path/to/debug.js from within the directory where package.json is located.
Clone this wiki locally