-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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.
-
Install Node.js and ensure
node
is in your path. -
Install the NW.js SDK and ensure
nw
is in your path. -
Add the following to the package.json of the NW.js application:
"chromium-args": "--enable-logging=stderr",
- 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;
});
- Run
node /path/to/debug.js
from within the directory where package.json is located.