Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

288
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!