Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

291
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!