
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
@freik/electron-better-ipc
Advanced tools
Forked from https://github.com/sponsors/sindresorhus
But that package didn't work for me, so I forked it and am fixing it
Simplified IPC communication for Electron apps
The biggest benefit of this module over the built-in IPC is that it enables you to send a message and get the response back in the same call. This would usually require multiple IPC subscriptions.
You can use this module directly in both the main and renderer process.
$ npm install electron-better-ipc
Requires Electron 5 or later.
Here, as an example, we use the built-in IPC to get an emoji by name in the renderer process from the main process. Notice how it requires coordinating multiple IPC subscriptions.
const {ipcMain: ipc} = require('electron');
ipc.on('get-emoji', async (event, emojiName) => {
const emoji = await getEmoji(emojiName);
event.sender.send('get-emoji-response', emoji);
});
const {ipcRenderer: ipc} = require('electron');
ipc.on('get-emoji-response', (event, emoji) => {
console.log(emoji);
//=> '🦄'
});
ipc.send('get-emoji', 'unicorn');
As you can see below, this module makes it much simpler to handle the communication. You no longer need multiple IPC subscriptions and you can just await the response in the same call.
const {ipcMain: ipc} = require('electron-better-ipc');
ipc.answerRenderer('get-emoji', async emojiName => {
const emoji = await getEmoji(emojiName);
return emoji;
});
const {ipcRenderer: ipc} = require('electron-better-ipc');
(async () => {
const emoji = await ipc.callMain('get-emoji', 'unicorn');
console.log(emoji);
//=> '🦄'
})();
Here we do the inverse of the above, we get an emoji by name in the main process from the renderer process:
const {ipcRenderer: ipc} = require('electron-better-ipc');
ipc.answerMain('get-emoji', async emojiName => {
const emoji = await getEmoji(emojiName);
return emoji;
});
const {ipcMain: ipc} = require('electron-better-ipc');
(async () => {
const emoji = await ipc.callFocusedRenderer('get-emoji', 'unicorn');
console.log(emoji);
//=> '🦄'
})();
The module exports ipcMain and ipcRenderer objects which enhance the built-in ipc module with some added methods, so you can use them as a replacement for electron.ipcMain/electron.ipcRenderer.
Send a message to the given window.
In the renderer process, use ipcRenderer.answerMain to reply to this message.
Returns a Promise<unknown> with the reply from the renderer process.
Type: BrowserWindow
The window to send the message to.
Type: string
The channel to send the message on.
Type: unknown
The data to send to the receiver.
Send a message to the focused window, as determined by electron.BrowserWindow.getFocusedWindow.
In the renderer process, use ipcRenderer.answerMain to reply to this message.
Returns a Promise<unknown> with the reply from the renderer process.
Type: string
The channel to send the message on.
Type: unknown
The data to send to the receiver.
This method listens for a message from ipcRenderer.callMain defined in a renderer process and replies back.
Returns a function, that when called, removes the listener.
Type: string
The channel to send the message on.
Type: Function | AsyncFunction
The return value is sent back to the ipcRenderer.callMain in the renderer process.
This method listens for a message from ipcRenderer.callMain defined in the given BrowserWindow's renderer process and replies back.
Returns a function, that when called, removes the listener.
Type: BrowserWindow
The window for which to expect the message.
Type: string
The channel to send the message on.
Type: Function | AsyncFunction
The return value is sent back to the ipcRenderer.callMain in the renderer process.
Send a message to all renderer processes (windows).
Type: string
The channel to send the message on.
Type: unknown
The data to send to the receiver.
Send a message to the main process.
In the main process, use ipcMain.answerRenderer to reply to this message.
Returns a Promise<unknown> with the reply from the main process.
Type: string
The channel to send the message on.
Type: unknown
The data to send to the receiver.
This method listens for a message from ipcMain.callRenderer defined in the main process and replies back.
Returns a function, that when called, removes the listener.
Type: string
The channel to send the message on.
Type: Function | AsyncFunction
The return value is sent back to the ipcMain.callRenderer in the main process.
FAQs
Simplified IPC communication for Electron apps
The npm package @freik/electron-better-ipc receives a total of 2 weekly downloads. As such, @freik/electron-better-ipc popularity was classified as not popular.
We found that @freik/electron-better-ipc demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.