-
Notifications
You must be signed in to change notification settings - Fork 8.1k
/
index.md
72 lines (53 loc) · 1.98 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
---
title: sessions.removeWindowValue()
slug: Mozilla/Add-ons/WebExtensions/API/sessions/removeWindowValue
---
{{AddonSidebar}}
Supprime une valeur précédemment stockée par un appel à {{WebExtAPIRef("sessions.setWindowValue")}}.
C'est une fonction asynchrone qui renvoie une [`Promise`](/fr/docs/Web/JavaScript/Reference/Objets_globaux/Promise).
## Syntaxe
```js
var removing = browser.sessions.removeWindowValue(
windowId, // integer
key, // string
);
```
### Paramètres
- `windowId`
- : `integer`. ID de la fenêtre dont vous essayez de supprimer les données.
- `key`
- : `string`. lé identifiant la valeur particulière à supprimer. Cela doit correspondre à la clé précédemment donnée dans {{WebExtAPIRef("sessions.setWindowValue")}}.
### Valeur retournée
Une [`Promise`](/fr/docs/Web/JavaScript/Reference/Objets_globaux/Promise) qui ne sera résolue aucun argument si l'élément a été supprimé avec succès. Si l'appel a échoué (par exemple, parce que l'ID de la fenêtre n'a pas pu être trouvé), la promesse sera rejetée avec un message d'erreur.
## Compatibilité des navigateurs
{{Compat}}
## Exemples
Ce code ajoute deux éléments de menu contextuel: l'un stocke une valeur associée à la fenêtre courante, l'autre la supprime :
```js
async function setOnActiveWindow() {
let currentWindow = await browser.windows.getLastFocused();
await browser.sessions.setWindowValue(currentWindow.id, "my-key", "my-value");
}
async function removeFromActiveWindow() {
let currentWindow = await browser.windows.getLastFocused();
await browser.sessions.removeWindowValue(currentWindow.id, "my-key");
}
browser.menus.create({
id: "add-my-item",
title: "add item",
contexts: ["all"],
});
browser.menus.create({
id: "remove-my-item",
title: "remove item",
contexts: ["all"],
});
browser.menus.onClicked.addListener((info) => {
if (info.menuItemId === "add-my-item") {
setOnActiveWindow();
} else {
removeFromActiveWindow();
}
});
```
{{WebExtExamples}}