Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Safari StorageArea.{get,remove} do not support empty keys #20931

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ If managed storage is not set, `undefined` will be returned.
>
> When this API is used as `chrome.storage.local.get()`, it correctly passes an Object to the callback function.

## Safari empty key bug

Safari has a bug which prevents this method from retreiving the data associated with the empty key `""` if it is explicitly specified. Specifically, Safari will throw an error `Error: Invalid empty key found in array passed to StorageArea.get()`. Instead, developers can pass `null` as the first argument to retreive all data in the storage area and then choose the desired data:

```js
const data = await StorageArea.get(null);
cosnole.log(data['']);
```

## Browser compatibility

{{Compat}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ let removingItem = browser.storage.<storageType>.remove(

A [`Promise`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that will be fulfilled with no arguments if the operation succeeded. If the operation failed, the promise will be rejected with an error message.

## Safari empty key bug

Safari has a bug which prevents this method from deleting the data associated with the empty key `""`. Specifically, `StorageArea.remove("")` and `StorageArea.remove([""])` will both throw `Error: Invalid empty key found in array passed to storage.StorageArea.remove()`. Instead, storage can be cleared via two other alternatives:

- call to {{WebExtAPIRef("storage.StorageArea.clear")}} which will remove all data from the storge area, including this recod, or
- call to {{WebExtAPIRef("storage.StorageArea.set")}} to overwrite this this data with some blank value like empty string `""` (record consumes 2 bytes from quota), or number `0` (record consmes 1 byte from quota).

## Browser compatibility

{{Compat}}
Expand Down