-
Notifications
You must be signed in to change notification settings - Fork 56
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
Should browser.storage.local.set({"": ""})
and browser.storage.local.get("")
be valid?
#278
Comments
browser.storage.local.set("")
and browser.storage.local.get("")
be valid?browser.storage.local.set({"": ""})
and browser.storage.local.get("")
be valid?
For reference, Firefox also supports this (matches Chrome).
This is interesting, is this extension public/in the store? Does it appear accidental or intentional? |
In any case, as we talked about in TPAC, for developers it would be very good to know about this behaviour in Safari even if it will be changed in the future. Mentioning it on this mdn page would be great: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/storage/StorageArea/set Generally speaking an empty key is just valid in JSON, as can be seen in the standard: That plus the fact Google Chrome and Firefox already support this, it seems best to change the behaviour in Safari as well. |
I decided to add this info to BCD and found the following curious detail: browser.storage.local.set({"":"example"})
browser.storage.local.get("", (a) => console.log(a[""])) logs out However, browser.storage.local.set({"":"example"})
browser.storage.local.get(null, (a) => console.log(a[""])) logs out And browser.storage.local.set({"":"example"})
browser.storage.local.get([""], (a) => console.log(a[""])) throws And browser.storage.local.remove("")
browser.storage.local.remove([""]) both throw In other words, this is just a difference in querying code. I'll add a note to MDN BCD. Edit: I updated the examples a bit. Edit 2: added |
@bershanskiy This was tested in Mozilla Firefox? I have tested these cases in Google Chrome, and in Google Chrome they just return in all three cases like you would expect. |
I tested those in Firefox (and, just for more confidence, on Chrome after replacing I believe that Safari just has a bug in |
Yes, |
Adding |
Since we all agreed on the preferred behaviour, there seems to be no work left for this issue within the group. Should we close the issue in this case? Or do we want to keep it open until it has been implemented by Safari? In any case, @xeenon can we add a note somewhere to update https://github.com/bershanskiy/browser-compat-data/blob/main/webextensions/api/storage.json under "empty_key", and change the "version_added" once this has been fixed by Safari? |
IMO it's fine to close since we've completed the discussion on interoperability. But I'll leave it up to @xeenon to close this, in case having it open is helpful.
FYI the canonical repo is mdn/content, i.e. https://github.com/mdn/browser-compat-data/blob/main/webextensions/api/storage.json I'm not sure if we need to list this in the BCD. This is an implementation bug for an uncommon scenario. I'm not opposed to documenting it, but I do wonder where we draw the line between an eventually obsolete historical note and an incompatibility that's worth calling out. Technically, |
I just stumbled upon this issue, and I suspect that it's referring to my own extension, considering that I filed a Feedback with Apple on the issue 6 weeks ago. The behavior is intentional. The keys represent site-specific options, and an empty key is used for the defaults. I have a workaround for Safari that I don't need for Chrome or Firefox:
|
I see in the meeting notes that some people didn't like this behavior, but it's no different from standard JavaScript objects:
|
I actually created a PR for MDN to include this workaround. Not sure if it will be merged since this level of detail might be excessive for MDN. |
Currently Chrome supports doing
browser.storage.local.set({ "": "foo" })
andbrowser.storage.local.get("")
. We always return an empty result object in Safari in if the key is empty. We have found an extension in the wild doing this, and will likely change Safari to match Chrome.The text was updated successfully, but these errors were encountered: