I'm trying to use custom-electron-titlebar : https://github.com/AlexTorresSk/custom-electron-titlebar#readme . When I put in the renderer process :
import customTitlebar from 'custom-electron-titlebar';
_getTitleBar() {
return new customTitlebar.Titlebar({
backgroundColor: customTitlebar.Color.fromHex('#333'),
});
}
I get the error require is not defined
When I move everything in the main process main.ts
:
import customTitlebar from 'custom-electron-titlebar'
ipcMain.on("customTitlebar-from-A", (event, args) => {
let titlebar = new customTitlebar.Titlebar({
backgroundColor: customTitlebar.Color.fromHex('#333'),
});
WindowTypeA.webContents.send("customTitlebar-to-A", { titlebar });
});
I get the error: navigator is not defined
.
Searching I found this answer: ElectronJS ReferenceError: navigator is not defined : "This can't be executed in main process. The main process is for managing the renderer process. There won't be any navigator at Electron main process. And navigator is property of browser. The renderer is responsible to render the code to browserWindow. So you can access the navigator of browserWindow at renderer not main. So please move this to your renderer where you'd like to customize the title bar. "
But how to keep customTitlebar within the renderer process, if I get the error require is not defined
?
WindowTypeA = new BrowserWindow({
width: 800,
height: 600,
titleBarStyle: "hidden",
webPreferences: {
nodeIntegration: false,
enableRemoteModule: false,
contextIsolation: true,
nodeIntegrationInWorker: false,
nodeIntegrationInSubFrames: false,
webSecurity: true,
webviewTag: false,
preload: path.join(__dirname, "./preload/preload.js"), /* eng-disable PRELOAD_JS_CHECK */
}
For security reasons, I MUST keep nodeIntegration:false
and contextIsolation: true
- Electron: v 12.0.0
- node: v 14.5.0
- O.S: Ubuntu 18.04 Desktop
How to solve the problem?