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

undefined value in StorageArea.set() #263

Open
regseb opened this issue Aug 24, 2022 · 3 comments
Open

undefined value in StorageArea.set() #263

regseb opened this issue Aug 24, 2022 · 3 comments
Labels
inconsistency Inconsistent behavior across browsers

Comments

@regseb
Copy link

regseb commented Aug 24, 2022

Hi,

I noticed a difference between Firefox and Chromium on the StorageArea.set() method.

  • In Firefox, StorageArea.set() removes item when value is undefined.
  • In Chromium, StorageArea.set() ignore item when value is undefined.

Expected

I propose a third solution where the value is saved in the storage.

This pseudo-code use assert.deepStrictEqual() from Node.js.

const data = { foo: undefined };
chrome.storage.local.set(data);
chrome.storage.local.get(Object.keys(data), (d) => assert.deepStrictEqual(d, data));

Testcase

  • manifest.json:
{
    "manifest_version": 2,
    "name": "Test case",
    "version": "1.0.0",
    "background": {
        "scripts": ["background.js"]
    },
    "permissions": ["storage"]
}
  • background.js:
chrome.storage.local.clear(() => {
    chrome.storage.local.set({ foo: "bar" });
    chrome.storage.local.get("foo", (v) => console.log(v));
    chrome.storage.local.set({ foo: undefined });
    chrome.storage.local.get("foo", (v) => console.log(v));
    chrome.storage.local.set({ foo: "baz" });
    chrome.storage.local.get("foo", (v) => console.log(v));
});

Results

Firefox

{ foo: "bar" }
{ }
{ foo: "baz" }

Chromium

{ foo: "bar" }
{ foo: "bar" }
{ foo: "baz" }

@dotproto dotproto added the inconsistency Inconsistent behavior across browsers label Aug 31, 2022
@Rob--W
Copy link
Member

Rob--W commented Sep 1, 2022

Relevant bug reports:

@xeenon
Copy link
Collaborator

xeenon commented Sep 1, 2022

Safari matches Chrome here (the key is ignored and will not be set or changed). A null value can be used in Safari for doing this.

@Rob--W
Copy link
Member

Rob--W commented Sep 1, 2022

I have re-opened the closed bug in Firefox with some implementation details: https://bugzilla.mozilla.org/show_bug.cgi?id=1499842#c5

I don't expect any of us to work on it anytime soon, but patches are welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
inconsistency Inconsistent behavior across browsers
Projects
None yet
Development

No branches or pull requests

4 participants