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

333
Vistas
Could not create listener with electron.ipcRenderer.on

After creating an electron application with

npm install create-electron-app -g
create-electron-app "Electron App"

an event listener was added to index.html by placing this script tag at the end of the body.

<script>
      const electron = require("electron");
      const ipcRenderer = electron.ipcRenderer;
      ipcRenderer.on('cpu', (event,data) => {// This isn't picking up the sent data.
        console.log('data is: ' + data);
      });
</script>

With the following js to start the app

const { app, BrowserWindow } = require('electron');
const path = require('path');
const os = require('os-utils');

// irrelevant code left out 

const createWindow = () => {
  const mainWindow = new BrowserWindow({
    width: 1000,
    height: 600,
    webPreferences: {
      nodeIntegration: true,
      contextIsolation: false
    }
  });

  mainWindow.loadFile(path.join(__dirname, 'index.html'));

  mainWindow.webContents.openDevTools();
  
  os.cpuUsage(function(v){
    console.log(v*100);
    mainWindow.webContents.send('cpu', v*100);// this should send this information to the webpage's ipcRenderer. 
  });
};

app.on('ready', createWindow);

The Problem

Nothing happens after I start the app. The dev console opens up but no data is logged to the console from this line: console.log('data is: ' + data);

Things I've tried

I've tried wrapping the os.cpuUsage(…) a listener that waits for the entire page to load, as was suggested in this answer

mainWindow.webContents.on('did-finish-load', ()=>{
  os.cpuUsage(function(v){
    console.log(v*100);
    mainWindow.webContents.send('cpu', v*100);// this should send this information to the webpage's ipcRenderer. 
  })
});

I have also checked to see if .on is actually creating an event listener by adding

      console.log(ipcRenderer.listenerCount())

to the end of the script tag. It logged '0'

I have also tried changing ipcRenderer.on to ipcRenderer.once with no change in behavior.

Additionally, I added these console.log lines after the const declarations in the <script> tag:

console.log('test')
console.log(electron)
console.log(ipcRenderer)

These were successfully logged.

about 4 years ago · Santiago Gelvez
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