Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

264
Vistas
ipcRenderer not receiving the message from webContents.send (Electron)

In the main window of my program, I have a button that, if clicked, creates a new, additional window. When this new window finishes loading, I want to send a message to ipcRenderer; however, I have not been able so far to make ipcRenderer able to receive the message, even though the window is created successfully.

Here's a snippet of the code in main.js:

const { ipcMain } = require('electron');

ipcMain.handle('open-window', () => {
    const newWindow = createWindow();
    newWindow.on('did-finish-load', () => {
        newWindow.webContents.send('opened-window');
    });
});

Note that createWindow is a function that creates and returns a browser window.

And here's a snippet of the code in preload.js:

const { ipcRenderer } = require('electron');

window.addEventListener('DOMContentLoaded', () => {
  document.getElementById('openWindow').addEventListener('click', () => {
        ipcRenderer.invoke('open-window');
    });
});

ipcRenderer.on('opened-window', () => {
    console.log('received message!')
})

As you can see, I would expect to receive in the console the string received message! after the new window finishes loading; however, this is not happening. What am I doing wrong?

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You are sending "opened-window" to the new window you created, not the original one in which the button was pressed.

newWindow.webContents.send('opened-window')

instead of newWindow, you need to refer to the window with the button and the opened-window handler

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda