在firefox插件中检测firefox android?

问题描述 投票:0回答:1

在Firefox Quantum之前,我可以使用下面的代码片段在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';

但现在,此代码段已存档。怎么检测到这个?

firefox-addon firefox-webextensions firefox-android
1个回答
2
投票

Cc,Ci和require-syntax是XUL / SDK技术,已被弃用以支持WebExtensions。

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

browser.runtime.getPlatformInfo().then((info) => {
    console.log(info.os); // will return android
});

这解析为PlatformInfo对象,其中包含“os”属性,其中将设置“android”。 https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/runtime/PlatformOs

有关更多详细信息,请参阅https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/runtime/getPlatformInfo

© www.soinside.com 2019 - 2024. All rights reserved.