management.install()
從給定的 URL 安裝並啟用主題擴充套件。
此 API 需要“management” API 許可權,並且只能與已簽名的主題一起使用。
這是一個非同步函式,它返回一個 Promise。
語法
js
browser.management.install(options)
引數
- options
-
一個物件,其中包含 addons.mozilla.org 上的主題 XPI 檔案的 URL,以及可選的 XPI 檔案雜湊(使用 sha256 或更強)。
返回值
一個 Promise,它將以一個包含 manifest.json 中為主題定義的 ExtensionID 的物件來 fulfilled。
示例
迴圈瀏覽主題列表
js
"use strict";
const themes = [
"https://addons.mozilla.org/en-US/firefox/downloads/file/1063216/insightscare-1.0-fx.xpi",
"https://addons.mozilla.org/en-US/firefox/downloads/file/1063419/orange_roses-1.0-fx.xpi",
"https://addons.mozilla.org/en-US/firefox/downloads/file/1062647/sticktoyourguns-2.0-fx.xpi",
"https://addons.mozilla.org/en-US/firefox/downloads/file/0/bad_url.xpi",
];
let current;
async function install(url) {
try {
current = url;
const { id } = await browser.management.install({ url });
console.log(`Theme installed: ${id}`);
} catch (e) {
console.error(`Installation failed: ${e}`);
}
}
browser.browserAction.onClicked.addListener(() => {
const id = themes.indexOf(current);
install(themes[(id + 1) % themes.length]);
});
for (const url of themes) {
browser.menus.create({
title: url,
onclick: () => install(url),
contexts: ["browser_action"],
});
}
瀏覽器相容性
載入中…