javascript - ElectronJS ReferenceError: navigator is not defined - Stack Overflow

I'm trying make a custom titlebar on electron. But when i started my app, i take "ReferenceEr

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

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

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

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')});
Share Improve this question edited Jan 20, 2020 at 12:56 tpikachu 4,8442 gold badges21 silver badges45 bronze badges asked Jan 17, 2020 at 14:39 ValorValor 431 silver badge5 bronze badges 4
  • lmk where you import this custom-electron-titlebar – tpikachu Commented Jan 17, 2020 at 17:50
  • in main.js m8 :. – Valor Commented Jan 18, 2020 at 21:26
  • please use this at your renderer – tpikachu Commented Jan 20, 2020 at 10:47
  • your main process is just for managing the renderer process. there is no navigator at main – tpikachu Commented Jan 20, 2020 at 10:47
Add a ment  | 

1 Answer 1

Reset to default 4

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.

This will be working very well.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745379767a4625169.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信