electron: Uncaught exception in main process after reloading
This code causes an uncaught exception when focusing the (detached) Developer Tools after reloading the page:
import classnames from 'classnames';
import { remote } from 'electron';
const mainWindow = remote.getCurrentWindow();
mainWindow.on('blur', () => document.body.className = classnames('unfocused'));
mainWindow.on('focus', () => document.body.className = classnames('focused'));
The stack trace:
Uncaught Exception:
Error: Attempting to call a function in a renderer window that has been closed or released. Function provided here: Object.<anonymous> (bootstrap.js:12:12.
at BrowserWindow.ret (PRIVATE_PATH\node_modules\electron-prebuilt\dist\resources\atom.asar\browser\lib\rpc-server.js:149:21)
at emitOne (events.js:82:20)
at BrowserWindow.emit (events.js:169:7)
at Object.module.exports.showErrorBox (PRIVATE_PATH\node_modules\electron-prebuilt\dist\resources\atom.asar\browser\api\lib\dialog.js:157:35)
at process.<anonymous> (PRIVATE_PATH\node_modules\electron-prebuilt\dist\resources\atom.asar\browser\lib\init.js:62:19)
at emitOne (events.js:77:13)
at process.emit (events.js:169:7)
at process._fatalException (node.js:224:26)
at Object.module.exports.showErrorBox (PRIVATE_PATH\node_modules\electron-prebuilt\dist\resources\atom.asar\browser\api\lib\dialog.js:157:35)
at process.<anonymous> (PRIVATE_PATH\node_modules\electron-prebuilt\dist\resources\atom.asar\browser\lib\init.js:62:19)
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 16 (10 by maintainers)
Method 1: Don’t use events with the remote module (use the ipc module for that) Method 2: Release the callbacks on app startup. Example:
Note, that this clears all callbacks, also these you have registred in the main-process! Also note, that you must not click the Developer Tools window while reloading. This would lead to the same crash / error as if not releasing the callbacks.
(for those who want to solve the problem) in renderer process code:
fix: (add)
Oh sorry. I’m dumb. I don’t release the callbacks before/after reloading.