I am trying to add close and minimize button on frameless window in Electron JS app. But its not working in anyhow. It's alwasy show "Cannot read property 'getCurrentWindow' of undefined" error. Here is my code:
const {remote} = require('electron');
document.getElementById('minimize').onclick = function() {
var window = remote.getCurrentWindow();
window.minimize();
}
document.getElementById('close').onclick = function() {
var window = remote.getCurrentWindow();
window.close();
}
I also add webPreferences: {nodeIntegration: true} in main.js.
win = new BrowserWindow({width: 990, height: 660, title: "Okkhor52 Tools", show: false, resizable: false, frame: false, webPreferences: {nodeIntegration: true}});
Please give me a sollution, I try to found this problem sollution in many place but i didn't get exact sollution.
Sollution is very easy. Just add webPreferences: {enableRemoteModule: true}
in your BrowserWindow in main.js.
win = new BrowserWindow({
width: 990,
height: 660,
title: "Okkhor52 Tools",
resizable: false,
frame: false,
webPreferences: {
nodeIntegration: true,
enableRemoteModule: true
}
});
Beside enableRemoteModule: true
you will need to add nodeIntegration: true
in webPreference, otherwise if you call electron from other's javascript (Like this const {remote} = require('electron');
) it will be not work.
If you already have enableRemoteModule
set to true and are still having this problem, it could very well be that you are requiring the remote module, or requiring a file that requires it inside the main process, at least this was the case for me. The remote module is not necessary inside the main process and is only for the renderer process.
If you require or require another javascript file that uses require("electron").remote.getCurrentWindow()
inside the main process then you will get this error.
Solve this simply by not including that code in any way inside the main process.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With