Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

292
Visualizações
os.platform returns browser instead of actual OS - React & Electron

I am trying to retrieve the appdata folder location for the application, and since each os has a separate path for the appdata or application support folder, I tried retrieving the os type to specify which path to use. The issue is os.platform() returns 'browser'. I have tried running it on windows and mac, but they all return browser. If i run process.platform in electron.js it gives me the correct os, but in react I get browser. How can I get the proper OS?

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

In a browser you can use a combination of navigator.platform, navigator.userAgent, and navigator.userAgentData.platform to get the information you want, but it might take some testing and parsing.

AFAIK, navigator.userAgentData.platform is available only on Chrome/Chromium-based browsers, but gives the most straight-forward result when available.

Checking which platform you're using, rather than checking for specific features, is generally consider not to be a good idea -- but I've found it hard to avoid sometimes myself, especially when working around platform-specific quirks and bugs.

about 4 years ago · Juan Pablo Isaza Relatório

0

This is because you are running process.platform in the renderer process.

In order to get the correct value you need to run platform.process either on main process (usually the background.js file) or via @electron/remote, like this:

window.require('@electron/remote').process.platform

@electron/remote's usage depends on your electron version, I recommend you to check @electron/remote readme.

about 4 years ago · Juan Pablo Isaza Relatório

0

Have you tried using Electron's app.getPath(name) method?

This method will return the users application data directory.

Only once the app is "ready" can you retrieve this path.

// Electron module(s).
const electronApp = require('electron').app;

// Application is now ready to start.
electronApp.on('ready', () => {

    // Get the users app data directory.
    let appData = electronApp.getPath('appData');

    // Get the users home directory.
    let home = electronApp.getPath('home');
})
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda