-
Notifications
You must be signed in to change notification settings - Fork 22.5k
/
index.md
75 lines (54 loc) · 2.01 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
---
title: management.install()
slug: Mozilla/Add-ons/WebExtensions/API/management/install
page-type: webextension-api-function
browser-compat: webextensions.api.management.install
---
{{AddonSidebar}}
Installs and enables a theme extension from the given URL.
This API requires the "management" [API permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions) and will only work with signed themes.
This is an asynchronous function that returns a [Promise](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
## Syntax
```js-nolint
browser.management.install(options)
```
### Parameters
- options
- : An object that includes the URL of the XPI file of the theme at [addons.mozilla.org](https://addons.mozilla.org) and an optional a hash of the XPI file, using sha256 or stronger.
### Return value
A [Promise](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that will be fulfilled with an object, containing the `ExtensionID` defined for the theme in manifest.json.
## Browser compatibility
{{Compat}}
## Examples
Cycle through a list of themes:
```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"],
});
}
```
{{WebExtExamples}}