mozilla / positron

a experimental, Electron-compatible runtime on top of Gecko
Other
561 stars 64 forks source link

console.log logs to terminal but not console window #115

Open mykmelez opened 7 years ago

mykmelez commented 7 years ago

On the node-integration branch, when I call console.log in the main.js script of the "hello world" app, the log message appears in the terminal window from which I ran Positron, but it doesn't appear in the devtools console window.

> ./mach run ~/Projects/positron/positron/test/hello-world/ --jsdebugger
…
JS engine: spidermonkey
screen shot 2016-09-02 at 16 59 07
mykmelez commented 7 years ago

The code I'm testing is:

console.log("JS engine: " + process.jsEngine);

Note that this happens even if I take steps to ensure that the console window is open first, f.e. by adding a debugger statement before the console.log call. I also tried waiting until the main window's console was open (after the call to mainWindow.webContents.openDevTools()):

   mainWindow.webContents.on('devtools-opened', function() {
       console.log("JS engine: " + process.jsEngine);
   });

(Although I wouldn't expect the message to appear in the main window's console, since that console is presumably only for messages logged by the page in that window.)

red15 commented 7 years ago

I think you might find this stackoverflow question should solve your issue : http://stackoverflow.com/questions/31759367/using-console-log-in-electron-app

mykmelez commented 7 years ago

I think you might find this stackoverflow question should solve your issue : http://stackoverflow.com/questions/31759367/using-console-log-in-electron-app

@red15 That question concerns a console for a BrowserWindow, whereas this issue occurs in the console for the main process, i.e. the console in the Developer Tools window that opens when you append --jsdebugger to the command line.

Note that the "main process console" is Positron-specific, as Electron doesn't provide a Developer Tools window for the main process (although you can connect to that process via an external debugger).

Ryuno-Ki commented 7 years ago

@mykmelez: Where do thrown errors get logged to? That is, is STDERR the same channel as STDOUT? I found several modules for Node development … https://blog.risingstack.com/node-js-logging-tutorial/ and https://stackoverflow.com/questions/12016474/node-js-logging for example.

Maybe Electron/Positron do something different. From what I've read, Electron is built around Node process (vs. NW.js around the HTML).

mykmelez commented 7 years ago

@mykmelez: Where do thrown errors get logged to? That is, is STDERR the same channel as STDOUT?

Erm, I'm not quite sure what you're asking here, but the disposition of stderr and stdout is presumably the responsibility of the environment. Positron does whatever Gecko does with errors thrown in JavaScript, which is presumably to write them to stderr in addition to any relevant Developer Tools console.

Maybe Electron/Positron do something different. From what I've read, Electron is built around Node process (vs. NW.js around the HTML).

Yes, Electron and Positron are likely to do different things. And indeed, Electron's initial process runs a script in a Node context that doesn't have access to an HTML DOM, while NW.js's initial process loads a web page in a context that does have access to an HTML DOM.

I found several modules for Node development … https://blog.risingstack.com/node-js-logging-tutorial/ and https://stackoverflow.com/questions/12016474/node-js-logging for example.

I appreciate the research (yours, and @red15's as well)! However, this issue is highly likely to be specific to Positron (and the Gecko Developer Tools implementation more generally), not something that also exists in Electron, nor something that can be addressed by Node.js debugging documentation.

There's something about the way that we've integrated Node into the Gecko "chrome" process that causes these errors to not make it to the Developer Tools console for that process (which one can open via the Positron-specific --jsdebugger flag).