Skip to content

Commit 89d9418

Browse files
rebloordotprotogithub-actions[bot]
authored
Bug-1910669 add StorageArea.getKeys() doc and release note (mdn#40560)
* Bug-1910669 add StorageArea.getKeys() doc and rn * Remove superfluous lines * Apply suggestions from review Co-authored-by: Simeon Vincent <svincent@gmail.com> * linter suggestion Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --------- Co-authored-by: Simeon Vincent <svincent@gmail.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent d8ecbd3 commit 89d9418

File tree

7 files changed

+72
-1
lines changed

7 files changed

+72
-1
lines changed

files/en-us/mozilla/add-ons/webextensions/api/storage/local/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ The `local` object implements the methods defined on the {{WebExtAPIRef("storage
2727
- : Retrieves one or more items from the storage area.
2828
- {{WebExtAPIRef("storage.StorageArea.getBytesInUse()", "storage.local.getBytesInUse()")}}
2929
- : Gets the amount of storage space (in bytes) used for one or more items in the storage area.
30+
- {{WebExtAPIRef("storage.StorageArea.getKeys()", "storage.local.getKeys()")}}
31+
- : Retrieves the keys of all items in the storage area.
3032
- {{WebExtAPIRef("storage.StorageArea.set()", "storage.local.set()")}}
3133
- : Stores one or more items in the storage area. If the item exists, its value is updated.
3234
- {{WebExtAPIRef("storage.StorageArea.remove()", "storage.local.remove()")}}

files/en-us/mozilla/add-ons/webextensions/api/storage/managed/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ The `managed` object implements the methods defined on the {{WebExtAPIRef("stora
4747
- : Retrieves one or more items from the storage area.
4848
- {{WebExtAPIRef("storage.StorageArea.getBytesInUse()", "storage.managed.getBytesInUse()")}}
4949
- : Gets the amount of storage space (in bytes) used for one or more items in the storage area.
50+
- {{WebExtAPIRef("storage.StorageArea.getKeys()", "storage.managed.getKeys()")}}
51+
- : Retrieves the keys of all items in the storage area.
5052

5153
## Events
5254

files/en-us/mozilla/add-ons/webextensions/api/storage/session/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ The `session` object implements the methods defined on the {{WebExtAPIRef("stora
2626
- : Retrieves one or more items from the storage area.
2727
- {{WebExtAPIRef("storage.StorageArea.getBytesInUse()", "storage.session.getBytesInUse()")}}
2828
- : Gets the amount of storage space (in bytes) used for one or more items in the storage area.
29+
- {{WebExtAPIRef("storage.StorageArea.getKeys()", "storage.session.getKeys()")}}
30+
- : Retrieves the keys of all items in the storage area.
2931
- {{WebExtAPIRef("storage.StorageArea.set()", "storage.session.set()")}}
3032
- : Stores one or more items in the storage area. If the item exists, its value is updated.
3133
- {{WebExtAPIRef("storage.StorageArea.setAccessLevel", "storage.session.setAccessLevel()")}}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
title: StorageArea.getKeys()
3+
slug: Mozilla/Add-ons/WebExtensions/API/storage/StorageArea/getKeys
4+
page-type: webextension-api-function
5+
browser-compat: webextensions.api.storage.StorageArea.getKeys
6+
sidebar: addonsidebar
7+
---
8+
9+
Retrieves the keys of all items in a storage area.
10+
11+
## Syntax
12+
13+
```js-nolint
14+
let results = browser.storage.<storageType>.getKeys();
15+
```
16+
17+
Where `<storageType>` is one of the storage types — {{WebExtAPIRef("storage.sync", "sync")}}, {{WebExtAPIRef("storage.local", "local")}}, {{WebExtAPIRef("storage.session", "session")}}, or {{WebExtAPIRef("storage.managed", "managed")}}.
18+
19+
### Parameters
20+
21+
This method takes no parameters.
22+
23+
### Return value
24+
25+
A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that resolves to an array containing storage item keys.
26+
27+
If the operation fails, the promise is rejected with an error message.
28+
29+
If managed storage is not set, `undefined` is returned.
30+
31+
> [!WARNING]
32+
> In Firefox, if an extension's managed storage has not been configured with a [native manifest](/en-US/docs/Mozilla/Add-ons/WebExtensions/Native_manifests#managed_storage_manifests) or using the [`3rdparty` enterprise policy](https://mozilla.github.io/policy-templates/#3rdparty), an exception is thrown when using this function to access managed storage (see [Firefox bug 1868153](https://bugzil.la/1868153)). This issue can be avoided by catching the error. This issue is related to the lack of support for the [`storage.managed_schema`](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/storage) manifest key (see [Firefox bug 1771731](https://bugzil.la/1771731)).
33+
34+
## Examples
35+
36+
Suppose storage contains two items:
37+
38+
```js
39+
// storage contains two items, "kitten" and "monster"
40+
browser.storage.local.set({
41+
kitten: { name: "Mog", eats: "mice" },
42+
monster: { name: "Kraken", eats: "people" },
43+
});
44+
```
45+
46+
Retrieve keys of all items in storage.local and log the result.
47+
48+
```js
49+
browser.storage.local
50+
.getKeys()
51+
.then((keys) => console.log(keys)) // [ "kitten", "monster" ]
52+
.catch((err) => console.error(`Error: ${error}`));
53+
```
54+
55+
{{WebExtExamples}}
56+
57+
## Browser compatibility
58+
59+
{{Compat}}

files/en-us/mozilla/add-ons/webextensions/api/storage/storagearea/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Values of this type are objects.
1818
- : Retrieves one or more items from the storage area.
1919
- {{WebExtAPIRef("storage.StorageArea.getBytesInUse()")}}
2020
- : Gets the amount of storage space (in bytes) used one or more items being stored in the storage area.
21+
- {{WebExtAPIRef("storage.StorageArea.getKeys()")}}
22+
- : Retrieves the keys of all items in the storage area.
2123
- {{WebExtAPIRef("storage.StorageArea.set()")}}
2224
- : Stores one or more items in the storage area. If an item already exists, its value will be updated.
2325
- {{WebExtAPIRef("storage.StorageArea.setAccessLevel()")}}

files/en-us/mozilla/add-ons/webextensions/api/storage/sync/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ The `sync` object implements the methods defined on the {{WebExtAPIRef("storage.
7979
- : Retrieves one or more items from the storage area.
8080
- {{WebExtAPIRef("storage.StorageArea.getBytesInUse()", "storage.sync.getBytesInUse()")}}
8181
- : Gets the amount of storage space (in bytes) used for one or more items in the storage area.
82+
- {{WebExtAPIRef("storage.StorageArea.getKeys()", "storage.sync.getKeys()")}}
83+
- : Retrieves the keys of all items in the storage area.
8284
- {{WebExtAPIRef("storage.StorageArea.set()", "storage.sync.set()")}}
8385
- : Stores one or more items in the storage area. If the item exists, its value is updated.
8486
- {{WebExtAPIRef("storage.StorageArea.remove()", "storage.sync.remove()")}}

files/en-us/mozilla/firefox/releases/143/index.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ Firefox 143 is the current [Nightly version of Firefox](https://www.firefox.com/
6868

6969
<!-- #### Marionette -->
7070

71-
<!-- ## Changes for add-on developers -->
71+
## Changes for add-on developers
72+
73+
- Addition of {{WebExtAPIRef("storage.StorageArea.getKeys()")}}. This method returns an array containing all of the keys in a storage area. It's available for all storage areas, that is {{WebExtAPIRef("storage.sync", "sync")}}, {{WebExtAPIRef("storage.local", "local")}}, {{WebExtAPIRef("storage.session", "session")}}, and {{WebExtAPIRef("storage.managed", "managed")}}. ([Firefox bug 1910669](https://bugzil.la/1910669))
7274

7375
<!-- ### Removals -->
7476

0 commit comments

Comments
 (0)