[英]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.我正在尝试检索应用程序的 appdata 文件夹位置,并且由于每个操作系统都有单独的 appdata 或应用程序支持文件夹路径,因此我尝试检索 os 类型以指定要使用的路径。 The issue is os.platform() returns 'browser'.
问题是 os.platform() 返回“浏览器”。 I have tried running it on windows and mac, but they all return browser.
我试过在 windows 和 mac 上运行它,但它们都返回浏览器。 If i run process.platform in electron.js it gives me the correct os, but in react I get browser.
如果我在 electron.js 中运行 process.platform 它会给我正确的操作系统,但在反应我得到浏览器。 How can I get the proper OS?
如何获得正确的操作系统?
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.在浏览器中,您可以使用
navigator.platform
、 navigator.userAgent
和navigator.userAgentData.platform
的组合来获取您想要的信息,但这可能需要一些测试和解析。
AFAIK, navigator.userAgentData.platform
is available only on Chrome/Chromium-based browsers, but gives the most straight-forward result when available. AFAIK,
navigator.userAgentData.platform
仅在基于 Chrome/Chromium 的浏览器上可用,但在可用时提供最直接的结果。
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.检查您正在使用的平台,而不是检查特定功能,通常被认为不是一个好主意——但我发现有时我自己很难避免,尤其是在解决特定于平台的怪癖和错误时。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.