In the main process, I have a simple Uint8Array and I want to send it to the renderer process.
sender.send is converting everything to JSON, so it cannot be used for binary data.
Is there a simple solution for this?
The ipcMain module is used to communicate asynchronously from the main process to renderer processes. When used in the main process, the module handles asynchronous and synchronous messages sent from a renderer process (web page). The messages sent from a renderer will be emitted to this module.
IPC channels In Electron, processes communicate by passing messages through developer-defined "channels" with the ipcMain and ipcRenderer modules. These channels are arbitrary (you can name them anything you want) and bidirectional (you can use the same channel name for both modules).
The ipcRenderer module is an EventEmitter. It provides a few methods so you can send synchronous and asynchronous messages from the render process (web page) to the main process. You can also receive replies from the main process.
in main.js
global.Uint8Array.root = YOUR_JSON;
in render js
const {remote} = require('electron');
...
console.log(remote.getGobal('Uint8Array').root);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With