Wrong data getting when use browser.storage.local.get
Closed this issue ยท 4 comments
HI @clarkbw firstly, thanks for this awesome repo, it help me a lots ๐
However, I encounter a bug maybe, following is my source code:
browser.storage.local.get({ apiErrReport: [] }, (result) => {
console.log(result);
const { apiErrReport } = result;
// ...
});
I pass an object to get
function, this is work well as usual, but when I started to use jest-webextension-mock
and wrote the test, I found the callback argument reuslt
become as:
There's a hardcode id
always in the root object
{ id: { apiErrReport: [] } }
But I think it is suppose to be a plain object without id
{ apiErrReport: [] } }
Any idea? BTW, I saw the source code and it always call the callback with { id }
, but I think:
if object given, the argument should be
const args = { ...id }
cb(args);
if string given, the argument should be
const args = {};
args[id] = ...;
cb(args);
I'm not sure, please let me know your idea. thanks
Regards,
Allen
Hi @AllenFang thanks for such an awesome write up of your issue! I'll try to take a look today.
Ok, looks like you're right. StorageArea.get allows for a number of keys that I don't think I handle well. Did you want to give a PR a try?
It's likely we need a shared solution for both get
, getBytesInUse
, and remove