从Firefox扩展检测操作系统

问题描述:

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


    // 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; 
+0

仅供参考:https://developer.mozilla.org/en/nsIXULRuntime – Nickolay 2009-10-12 06:22:14

为了完整,让OS字符串新addon-sdk

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

火狐正在向web-extension API,你可以使用:

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

Possible os values是:MAC, win,android,cros,linux,openbsd

Documentation for getPlatformInfo is here.

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