问题 从Firefox扩展检测操作系统


我正在开发一个firefox扩展,我需要检测哪个操作系统firefox正在运行,但我似乎无法找到和如何做到这一点的信息?


9786
2017-09-13 21:35


起源



答案:



    // Returns "WINNT" on Windows Vista, XP, 2000, and NT systems;  
    // "Linux" on GNU/Linux; and "Darwin" on Mac OS X.  
    var osString = Components.classes["@mozilla.org/xre/app-info;1"]  
                   .getService(Components.interfaces.nsIXULRuntime).OS;  

15
2017-09-13 21:54



供参考: developer.mozilla.org/en/nsIXULRuntime - Nickolay


答案:



    // Returns "WINNT" on Windows Vista, XP, 2000, and NT systems;  
    // "Linux" on GNU/Linux; and "Darwin" on Mac OS X.  
    var osString = Components.classes["@mozilla.org/xre/app-info;1"]  
                   .getService(Components.interfaces.nsIXULRuntime).OS;  

15
2017-09-13 21:54



供参考: developer.mozilla.org/en/nsIXULRuntime - Nickolay


为了完整性,获取新的os字符串 插件-SDK

const {Cc, Ci} = require("chrome");
const osString = Cc['@mozilla.org/xre/app-info;1'].getService(Ci.nsIXULRuntime).OS;
console.log(osString);

0
2017-11-27 21:41





Firefox正在向 web-extension 您可以使用的API:

chrome.runtime.getPlatformInfo(info => console.log(info.os))

可能 os 值 是:mac,win,android,cros,linux,openbsd

文档 getPlatformInfo 在这儿。

警告: 这不起作用 content-script,你将不得不打电话给你 background-script


0
2017-07-02 06:52