management.install() 编辑
Installs and enables a theme extension from the given URL.
This API requires the "management" API permission and will only work with signed themes.
This is an asynchronous function that returns a Promise.
Syntax
let {id} = await browser.management.install({url});
Parameters
- options
- An object that includes the URL of the XPI file of the theme at addons.mozilla.org and an optional a hash of the XPI file, using sha256 or stronger.
Return value
A Promise that will be fulfilled with an object, containing the ExtensionID
defined for the theme in manifest.json.
Browser compatibility
BCD tables only load in the browser
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Examples
Cycle through a list of themes:
"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"],
});
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论