AlexTorresDev / custom-electron-titlebar

Custom electon title bar inpire on VS Code title bar
MIT License
868 stars 149 forks source link

navigator is not defined #105

Closed maxime-mp4 closed 2 years ago

maxime-mp4 commented 4 years ago

When I start my electron app (npx electron main.js), on this line, i have this error. Electronjs version: v10.1.4 Code:

const { app, BrowserWindow } = require("electron");
const customTitlebar = require("custom-electron-titlebar");

function createWindow(){

  const window = new BrowserWindow({
    width: 1280,
    height: 720,
    resizable: false,
    titleBarStyle: "hidden",
    frame: false,
    webPreferences: {
      nodeIntegration: true,
    },
  });

  new customTitlebar.Titlebar({
    backgroundColor: customTitlebar.Color.fromHex("#444"),
  });

  window.loadFile("../public/index.html");
}
leoata commented 4 years ago

I'm using this with react and a workaround that I found was placing the Titlebar code inside of the react code instead of the electron. I'm not sure how this translates to your specific environment, but I would look to find a way to declare the Titlebar later in the initialization stages.

ilikestohack commented 4 years ago

I also have this issue and I am not using react and would not like to is there any other fix?

Silventino commented 4 years ago

Same issue here. @leoata, can you share how you did the workaround?

ghost commented 4 years ago

I'm also experiencing the same issue

ghost commented 4 years ago

I was able to fix this by including it after the react app render statement. Just put it at the end of your index.html

0xdeafcafe commented 3 years ago

It looks like you're instantiating TitleBar in the electron main process, rather than the renderer process (where it actually has access to the DOM). That is why it works when you added it into the index.html file.