How to fire an event when BrowserWindow logs a console message?


#1

I’d like to get the event when the content of BrowserWindow logs a console message.

When we use a webView, ‘console-message’ event is fired when the guest window logs a console message like below.

webview.addEventListener('console-message', function(e) {
  console.log('Guest page logged a message:', e.message);
});

However, I could not find any way to get this event with the content of BrowserWindow.
Is it possible to get console messages logged in ‘https://github.com’ in a below situation?

var BrowserWindow = require('browser-window');

var win = new BrowserWindow({ width: 800, height: 600, show: false });
win.on('closed', function() {
  win = null;
});

win.loadUrl('https://github.com');
win.show();

Thank you for your support!!


#2

Same problem here. Want to get console message from webContents and can’t find anything helpful in the Doc


#3

As far as I’m aware there’s no ‘official’ way of doing this, but I suppose you could override console.log using .executeJavaScript(<code>) and report it back that way.