ipcMain event.reply not working

I am developing a simple electron program. It takes a user input from a website, processes it using a callback function, and either returns an error or null (for no error). The callback function calls event.reply to send the result back to the page, however the event.reply does not throw an error or run the code specified in the reply.

Node integration is set to true and context isolation has been set to false.

The actual function with a callback, as well as the page’s HTML code, have not been given. I have extensively tested both in a vacuum, and both are not the problem.

pageRenderer.js

submit = document.getElementById('submit');

ipcRenderer.on('returnInfo', (event, isSuccess) => {
    if (isSuccess) { 
        alert('Success!');
    } else { //Login failed
        alert('Failure!');
    }
});

submit.addEventListener('click', (event) => {
    const userInput = document.getElementById('input').value;
    ipcRenderer.send('Process', (userInput));
});

main.js

ipcMain.on('Process', (event, userInput) => {
        globalVariable = userInput
        processValue((err) => {
            if (err) {
                console.error(err);
                event.reply('returnInfo', false);
            } else {
                event.reply('returnInfo', true);
            }

        });
});       

When running the program, I tested that the if statement in the ipcMain function works correctly, depending on if processValue succeeds or not. However, the ipcRenderer function does not run and does not throw a runtime error.

The issue might be related to the way you are sending the data from the renderer process to the main process. Instead of passing the data as an argument to ipcRenderer.send, you should send it as a separate parameter. Modify your code in pageRenderer.js as follows:

submit.addEventListener('click', (event) => {
    const userInput = document.getElementById('input').value;
    ipcRenderer.send('Process', userInput);
});

By making this change, the userInput value will be correctly passed to the main process.

Additionally, make sure that you have imported the necessary modules in both pageRenderer.js and main.js. The ipcRenderer module should be imported in pageRenderer.js and the ipcMain module should be imported in main.js.

Once you have made these changes, the event.reply function should be executed correctly in the main process, and the result should be sent back to the renderer process.