1// In main process.
2const { ipcMain } = require('electron')
3ipcMain.on('asynchronous-message', (event, arg) => {
4 console.log(arg) // prints "ping"
5 event.reply('asynchronous-reply', 'pong')
6})
7
8ipcMain.on('synchronous-message', (event, arg) => {
9 console.log(arg) // prints "ping"
10 event.returnValue = 'pong'
11})
12Copy
1// In renderer process (web page).
2const { ipcRenderer } = require('electron')
3console.log(ipcRenderer.sendSync('synchronous-message', 'ping')) // prints "pong"
4
5ipcRenderer.on('asynchronous-reply', (event, arg) => {
6 console.log(arg) // prints "pong"
7})
8ipcRenderer.send('asynchronous-message', 'ping')
9Copy