Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

263
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda