ElectronJS ReferenceError:导航器未定义 [英] ElectronJS ReferenceError: navigator is not defined

查看:70
本文介绍了ElectronJS ReferenceError:导航器未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在电子上创建自定义标题栏.但是,当我启动我的应用程序时,出现"ReferenceError:导航器未定义"问题.请帮忙.这是我的main.js的代码片段

I'm trying make a custom titlebar on electron. But when i started my app, i take "ReferenceError: navigator is not defined" issue. Please help. This is the code snippet from my 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')});

推荐答案

无法在渲染器过程.在Electron主流程中将没有任何导航器.并且导航器是浏览器的属性.

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.

渲染器负责将代码渲染到browserWindow.因此,您可以在渲染器而不是main处访问browserWindow的导航器.

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.

这将很好地工作.

这篇关于ElectronJS ReferenceError:导航器未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆