2

我正在尝试在电子上制作自定义标题栏。但是当我启动我的应用程序时,我遇到了“ReferenceError: navigator is not defined”的问题。请帮忙。这是我的 main.js 中的代码片段

我的代码

// 1. Require the installed module
const customTitlebar = require('custom-electron-titlebar');
// 2. Create the custom titlebar with your own settings
//    To make it work, we just need to provide the backgroundColor property
//    Other properties are optional.
let MyTitleBar = new customTitlebar.Titlebar({ backgroundColor: customTitlebar.Color.fromHex('#03a9f4')});
4

1 回答 1

2

这不能在主进程中执行。主要进程用于管理渲染器进程。在 Electron 主进程中不会有任何导航器。导航器是浏览器的属性。

渲染器负责将代码渲染到 browserWindow。因此,您可以在非主渲染器上访问 browserWindow 的导航器。

因此,请将其移至您想要自定义标题栏的渲染器。

这将非常有效。

于 2020-01-21T02:10:31.067 回答