Skip to content

Conversation

@hkmaly
Copy link

@hkmaly hkmaly commented Apr 1, 2023

Seems to solve #159.

Frankly, most likely the actual error is that it should be current[HISTORY_KEY] instead of current.history, but maybe it would be safer to get rid of those awaits as well.

const current = (await browser.storage.local.get(HISTORY_KEY)) || {};
await browser.storage.local.set({
[HISTORY_KEY]: [...(current.history || []), entry],
browser.storage.local.get(HISTORY_KEY, function(current) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll need to try this out, local.get is async and returns a promise as per https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/storage/StorageArea/get

MDN also doesn't seem to see to indicate a callback function as the second argument.

Copy link
Author

@hkmaly hkmaly Apr 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gyng If you look on bottom of that page, it's actually mentioned there as example: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/storage/StorageArea/get#chrome_examples (with different function syntax, but still).

Or I can rewrite it to promise using then. I'm just suspicious about the await. And there is no other await in your extension ...

... oh. I see. browser.storage.local is supposed to be something else than chrome.storage.local. Weird. It DOES work for me, though (in firefox) ...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Another pull request with then pushed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants