从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;
答
为了完整,让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
。
仅供参考:https://developer.mozilla.org/en/nsIXULRuntime – Nickolay 2009-10-12 06:22:14