Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Electron ipcRenderer module


May 25, 2021 Electron


Table of contents


ipcRenderer module is an example of an EventEmitter class. I t provides a limited way for you to send synchronous or asynchronous messages from the rendering process to the main process. You can also receive a response from the main process.

View examples of ipcMain codes.

Message monitoring

ipcRenderer has the following methods for listening to events:

ipcRenderer.on(channel, listener)

  • channel String
  • listener Function

Listen channel when a new message arrives, listener(event, args...) Call listener .

ipcRenderer.once(channel, listener)

  • channel String
  • listener Function

Add a one-time listener function listener event. This listener will be called upon the next time a new message is sent to channel and then deleted.

ipcRenderer.removeListener(channel, listener)

  • channel String
  • listener Function

Remove the channel from the array of listeners in the listener .

ipcRenderer.removeAllListeners([channel])

  • channel String (optional)

Delete all listeners, or delete all in channel specified channel.

Send a message

ipcRenderer has the following methods for sending messages:

ipcRenderer.send(channel[, arg1][, arg2][, ...])

  • channel String
  • arg (optional)

You can also send arbitrary parameters by sending asynchronous messages to the main process via channel Arguments are serialized by JSON and then do not contain functions or prototype chains.

The main process processes the message by using the ipcMain module to listen to the channel

ipcRenderer.sendSync(channel[, arg1][, arg2][, ...])

  • channel String
  • arg (optional)

You can also send any parameter by sending a synchronization message to the main process via channel Arguments are serialized by JSON and then do not contain functions or prototype chains.

The main process listens to the channel by using the ipcMain channel to process messages, event.returnValue

Note: Sending a sync message will block the entire rendering process and never use it unless you know what you're doing.

ipcRenderer.sendToHost(channel[, arg1][, arg2][, ...])

  • channel String
  • arg (optional)

Similar ipcRenderer.send but its events will be sent to <webview> not the main process.