Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error In background Process #1

Open
akshaygarg834 opened this issue Jun 7, 2017 · 1 comment
Open

Error In background Process #1

akshaygarg834 opened this issue Jun 7, 2017 · 1 comment

Comments

@akshaygarg834
Copy link

Console.log in background process not working. You can't see a single output out of it. How to debug it?
Is there a way to change stdout of this bakground process to main process stdout so that all console.log() of background process start show in main process console.

@matortheeternal
Copy link

matortheeternal commented Sep 10, 2017

You can use IPC to send a message to the main process to log messages to it, e.g. via:

Background window

const electron = require('electron');
const ipcRenderer = electron.ipcRenderer;

let log = function(message) {
    ipcRenderer.send('worker-message', message);
};

log('Hello world');

Main process

ipcMain.on('worker-message', (e, message) => console.log(message));

You could also pipe it to the developer tools console of the main window via:

Main process

ipcMain.on('worker-message', function(e, message) {
    mainWindow.webContents.send('worker-message', message);
});

Main window

const electron = require('electron');
const ipcRenderer = electron.ipcRenderer;
ipcRenderer.on('worker-message', (event, message) => console.log(message));

You can also see this stack overflow topic for ways to write to stdout in the main process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants