management.install()
Installe et active une extension de thème à partir de l'URL donnée.
Cette API nécessite la permission de l'API "management" et ne fonctionnera qu'avec des thèmes signés.
C'est une fonction asynchrone qui renvoie une Promise.
Syntaxe
let { id } = await browser.management.install({ url });
Paramètres
- options
-
Un objet qui inclut l'URL du fichier XPI du thème à addons.mozilla.org et un hachage facultatif du fichier XPI, en utilisant sha256 ou plus.
Valeur retournée
Une Promise qui sera remplie avec un objet, contenant l'ExtensionID
défini pour le thème dans manifest.json.
Compatibilité des navigateurs
Report problems with this compatibility data on GitHubdesktop | mobile | ||||||
---|---|---|---|---|---|---|---|
install |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- No support
- No support
- See implementation notes.
Exemples
Parcourez une liste de thèmes :
"use strict";
let themes = [
"https://addons.mozilla.org/firefox/downloads/file/1063216/insightscare-1.0-fx.xpi",
"https://addons.mozilla.org/firefox/downloads/file/1063419/orange_roses-1.0-fx.xpi",
"https://addons.mozilla.org/firefox/downloads/file/1062647/sticktoyourguns-2.0-fx.xpi",
"https://addons.mozilla.org/firefox/downloads/file/0/bad_url.xpi",
];
let current;
async function install(url) {
try {
current = url;
let { id } = await browser.management.install({ url });
console.log("Theme installed: " + id);
} catch (e) {
console.error("Installation failed: " + e);
}
}
browser.browserAction.onClicked.addListener(() => {
let id = themes.indexOf(current);
install(themes[(id + 1) % themes.length]);
});
for (let url of themes) {
browser.menus.create({
title: url,
onclick: () => install(url),
contexts: ["browser_action"],
});
}