gpt4 book ai didi

javascript - ElectronJS 引用错误 : navigator is not defined

转载 作者:行者123 更新时间:2023-12-03 12:21:51 29 4
gpt4 key购买 nike

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

My Codes

// 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')});

最佳答案

这不能在 main process 中执行.
主要流程是管理renderer process . Electron 主进程不会有任何导航器。和 navigator是浏览器的属性。

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

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

这将非常有效。

关于javascript - ElectronJS 引用错误 : navigator is not defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59789539/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com