0

I hope you are having a good morning. I was wondering if there was a way to call a regular function in contextBridge in preload.js from main.js that will not be read by renderer.js. For example when wanting to call a regular function in contextBridge, not having to use ipcRenderer, you simply do window.preloader.functionName() in renderer.js.

I want to do the exact same thing except in main.js. I have tried doing win.webContents.functionName(); in main.js, however, I receive the error of TypeError: Cannot read properties of undefined (reading ‘functionName’)

Please let me know if you have a solution! Thanks.

  • I think you'll want to post some actual code to give us a sense of what you're trying to do. It's not clear from the snippets. The error indicates that `win` isn't defined, so where is `win` coming from? – pushkin Jul 06 '22 at 19:22
  • You can't just send a message to the renderer via `yourWin.webContents.send("callFunction");` and then have your preload script intercept that message via `ipcRenderer.on("callFunction", () => functionName());`? – pushkin Jul 06 '22 at 19:23
  • That was the way I did it! Thanks for the response! – Ryan Johnson Aug 06 '22 at 08:32

0 Answers0