-
-
Save mgalla10/1ab968669f64a7707306e876ab2ff5bc to your computer and use it in GitHub Desktop.
Electron 17 Print Crash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'"> | |
<link href="./styles.css" rel="stylesheet"> | |
<title>Hello World!</title> | |
</head> | |
<body> | |
<button id="btnPrint">Print</button> | |
<script src="./renderer.js"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const {app, BrowserWindow, ipcMain, dialog} = require('electron') | |
const path = require('path') | |
function createWindow () | |
{ | |
const mainWindow = new BrowserWindow( | |
{ | |
width: 800, | |
height: 600, | |
webPreferences: { | |
preload: path.join(__dirname, 'preload.js') | |
} | |
}) | |
mainWindow.loadFile('index.html') | |
ipcMain.on("printWindow", () => | |
{ | |
// works | |
// mainWindow.webContents.print() | |
// mainWindow.webContents.print({}) | |
// mainWindow.webContents.print({}, null) | |
// crashes | |
mainWindow.webContents.print({}, () => {}) | |
// mainWindow.webContents.print({}, function () {}) | |
}) | |
} | |
app.whenReady().then(() => createWindow()) | |
app.on('window-all-closed', () => app.quit()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "silly-legs-subtract-1dlyf", | |
"productName": "silly-legs-subtract-1dlyf", | |
"description": "My Electron application description", | |
"keywords": [], | |
"main": "./main.js", | |
"version": "1.0.0", | |
"author": "mgallagh", | |
"scripts": { | |
"start": "electron ." | |
}, | |
"dependencies": {}, | |
"devDependencies": { | |
"electron": "17.0.0" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const {contextBridge, ipcRenderer} = require('electron') | |
contextBridge.exposeInMainWorld("_print", () => ipcRenderer.send("printWindow")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.getElementById("btnPrint").addEventListener("click", () => window._print()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment