w3c / w3c/webextensions

undefined value in StorageArea.set()

Open
#263 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

inconsistency
Dominant language
Bikeshed
Stars
711
Forks
95
Avg merge
10d 11h
Merged PRs (30d)
2

Description

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" }

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the StorageArea.set() behavior described in the MDN link and compare the Firefox and Chromium results in the manifest.json/background.js testcase. Determine the agreed cross-browser behavior for undefined values, then document the decision in the relevant WebExtensions specification material; done means the behavior and expected result are unambiguous.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
api, documentation
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.