So, I’m trying to send data from my main.js, to be used in the renderer to draw divs to my html, after not being able to use the content from my JSON I decided to try and send a simple string, and the problem persists, a useless object.(Tried stringify, tried “toString()” and it only becomes an “Object”.
Funnily enough, sending data from render to main works perfectly, I’m receiving it and storing it into a file that works just fine.
Main.js
const createMainWindow = () => {
const win = new BrowserWindow({
width: 600,
height: 400,
webPreferences: {
nodeIntegration: true,
preload: path.join(__dirname, "preload.js")
}
})
win.loadFile('index.html')
win.webContents.openDevTools();
win.webContents.on('did-finish-load', () =>{
win.webContents.send('loadJSON', "hello");
})
};
preload.js
contextBridge.exposeInMainWorld('electronAPI', {
storeJSON: (data) => ipcRenderer.send('storeJSON', data),
loadJSON: (data) => ipcRenderer.on('loadJSON', data)
})
vsticker.js (renderer)
window.electronAPI.loadJSON((data) =>{
console.log(data);
});
I’m starting to get exhausted from reading electron’s docs to try and figure out why this is happening, I tried to wait until the page loads, tried this method of using a string instead of the contents fro my JSON, nothing seems to work, I just want to finish this.
Also, yes, I’ve read the post from the person that had a very similar problem, his solution was to wait until the page was fully loaded, I’ve tried this and it didn’t work.