Firefox addon 在firefox插件中检测firefox android?

Firefox addon 在firefox插件中检测firefox android?,firefox-addon,firefox-addon-webextensions,firefox-android,Firefox Addon,Firefox Addon Webextensions,Firefox Android,在FirefoxQuantum之前,我可以通过下面的代码片段在Firefox插件中检测Firefox android const { Cc, Ci } = require('chrome'); /** * Is firefox android? * * @returns {boolean} true if there is firefox android in firefox addon * @see https://developer.mozilla.org/en-US/Add

在FirefoxQuantum之前,我可以通过下面的代码片段在Firefox插件中检测Firefox android

const { Cc, Ci } = require('chrome');
/**
  * Is firefox android?
  *
  * @returns {boolean} true if there is firefox android in firefox addon
  * @see https://developer.mozilla.org/en-US/Add-ons/Firefox_for_Android/Code_snippets#Supporting_both_desktop_and_mobile
  */
module.exports = () =>
Cc['@mozilla.org/xre/app-info;1']
  .getService(Ci.nsIXULRuntime)
  .widgetToolkit.toLowerCase() === 'android';

但是现在,这个片段被存档了。如何检测这种情况?

Cc、Ci和require语法是XUL/SDK技术,该技术已被弃用,取而代之的是WebExtensions

在WebExtension中,您可以使用browser.runtime.getPlatformInfo检索平台信息:

browser.runtime.getPlatformInfo().then((info) => {
    console.log(info.os); // will return android
});
这将解析为一个PlatformInfo对象,该对象包含将在其中设置“android”的“os”属性

有关详细信息,请参阅

Cc、Ci和require语法是XUL/SDK技术,该技术已被弃用以支持WebExtensions

在WebExtension中,您可以使用browser.runtime.getPlatformInfo检索平台信息:

browser.runtime.getPlatformInfo().then((info) => {
    console.log(info.os); // will return android
});
这将解析为一个PlatformInfo对象,该对象包含将在其中设置“android”的“os”属性

有关详细信息,请参阅