DEV Community

KoichiArai
KoichiArai

Posted on

Day19 of 100DaysOfCode

It's hard to keep coding consistently, especially since I've been working overtime until 10p.m. lately.
(I know it's not great to make excuses, but I'm determined to push through.)
By the way, I added a **contextBridge** (by including a **preload.js** file) to the previous program.
However, it doesn't work and I have been trying to solve this issue.

What I did

  • Added a secure process
// index.js
const button = document.getElementById("button");
const receive = document.getElementById("receive");
const send = document.getElementById("send");

button.addEventListener('click', async () => {
    receive.textContent = await window.myAPI.buttonEvent(send.value);// Changed
});
Enter fullscreen mode Exit fullscreen mode
// preload.js
const {ipcRenderer, contextBridge} = require('electron');

contextBridge.exposeInMainWorld('myAPI',{
    buttonEvent: (text) => ipcRenderer.invoke('two-way-com', text),
});
Enter fullscreen mode Exit fullscreen mode

I'll continue working on solving this problem.

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay