最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论