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

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

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 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