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

290
Vistas
Electron App Exit immediately after printing command

i'm trying to create a desktop app that can do printing after i clicked some button. so here is my code.

main.js

const {app,BrowserWindow} = require('electron');

function createWindow(){
    const win = new BrowserWindow({
        resizable:false
    })
    win.maximize()
    win.removeMenu()
    win.loadFile("./index.html")

    win.webContents.on('did-create-window',(window,detail)=>{
        window.removeMenu()
        window.resizable = false
        window.webContents.print({silent:false})
    })
}

app.whenReady().then(() => {
    createWindow()
  
    app.on('activate', () => {
      if (BrowserWindow.getAllWindows().length === 0) {
        createWindow()
      }
    })
  })
  
  app.on('window-all-closed', () => {
    if (process.platform !== 'darwin') {
      app.quit()
    }
  })

Index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    whatever
    <button onclick="newPrint()">BIGGIE</button>
</body>
<script>
    function newPrint(){
        var myWindow = window.open("", "MsgWindow", "width=200,height=100");
        myWindow.document.write("<p>This is 'MsgWindow'. I am 200px wide and 100px tall!</p>"); 
    }
</script>
</html>

package.json

{
  "name": "electron-print",
  "version": "1.0.0",
  "description": "",
  "main": "main.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "electron": "^19.0.2"
  }
}

enter image description here

So after i clicked the button, the electron app just suddenly close ! i just don't know why it happened.

and i tried re-creating this app on other computer (Mine was running Win 11 and i thought maybe that was the problem) and it worked just fine !

Could it be that Electron is not fully compatible with Win 11 yet ?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

This seems very much like this Electron bug, which is fixed in Electron 19.0.2 which you're apparently on.

Can you reinstall your node modules to confirm that you still see the issue in 19.0.2? This issue would have been present in Electron 19.0.1.

about 4 years ago · Juan Pablo Isaza 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